58 """ |
58 """ |
59 Class implementing the command line completer object. |
59 Class implementing the command line completer object. |
60 """ |
60 """ |
61 def __init__(self, namespace=None): |
61 def __init__(self, namespace=None): |
62 """ |
62 """ |
63 Create a new completer for the command line. |
63 Constructor |
64 |
64 |
65 Completer([namespace]) -> completer instance. |
65 Completer([namespace]) -> completer instance. |
66 |
66 |
67 If unspecified, the default namespace where completions are performed |
67 If unspecified, the default namespace where completions are performed |
68 is __main__ (technically, __main__.__dict__). Namespaces should be |
68 is __main__ (technically, __main__.__dict__). Namespaces should be |
89 self.use_main_ns = False |
89 self.use_main_ns = False |
90 self.namespace = namespace |
90 self.namespace = namespace |
91 |
91 |
92 def complete(self, text, state): |
92 def complete(self, text, state): |
93 """ |
93 """ |
94 Return the next possible completion for 'text'. |
94 Public method to return the next possible completion for 'text'. |
95 |
95 |
96 This is called successively with state == 0, 1, 2, ... until it |
96 This is called successively with state == 0, 1, 2, ... until it |
97 returns None. The completion should begin with 'text'. |
97 returns None. The completion should begin with 'text'. |
98 |
98 |
99 @param text The text to be completed. (string) |
99 @param text The text to be completed. (string) |
125 word = word + "(" |
125 word = word + "(" |
126 return word |
126 return word |
127 |
127 |
128 def global_matches(self, text): |
128 def global_matches(self, text): |
129 """ |
129 """ |
130 Compute matches when text is a simple name. |
130 Public method to compute matches when text is a simple name. |
131 |
131 |
132 @param text The text to be completed. (string) |
132 @param text The text to be completed. (string) |
133 @return A list of all keywords, built-in functions and names currently |
133 @return A list of all keywords, built-in functions and names currently |
134 defined in self.namespace that match. |
134 defined in self.namespace that match. |
135 """ |
135 """ |
145 matches.append(self._callable_postfix(val, word)) |
145 matches.append(self._callable_postfix(val, word)) |
146 return matches |
146 return matches |
147 |
147 |
148 def attr_matches(self, text): |
148 def attr_matches(self, text): |
149 """ |
149 """ |
150 Compute matches when text contains a dot. |
150 Public method to compute matches when text contains a dot. |
151 |
151 |
152 Assuming the text is of the form NAME.NAME....[NAME], and is |
152 Assuming the text is of the form NAME.NAME....[NAME], and is |
153 evaluatable in self.namespace, it will be evaluated and its attributes |
153 evaluatable in self.namespace, it will be evaluated and its attributes |
154 (as revealed by dir()) are used as possible completions. (For class |
154 (as revealed by dir()) are used as possible completions. (For class |
155 instances, class members are are also considered.) |
155 instances, class members are are also considered.) |