1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric6.DebugClients.Python.FlexCompleter</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>eric6.DebugClients.Python.FlexCompleter</h1> |
|
23 <p> |
|
24 Word completion for the eric6 shell. |
|
25 </p><p> |
|
26 <h4>NOTE for eric6 variant</h4> |
|
27 </p><p> |
|
28 This version is a re-implementation of FlexCompleter |
|
29 as found in the PyQwt package. It is modified to work with the eric6 debug |
|
30 clients. |
|
31 </p><p> |
|
32 |
|
33 </p><p> |
|
34 <h4>NOTE for the PyQwt variant</h4> |
|
35 </p><p> |
|
36 This version is a re-implementation of FlexCompleter |
|
37 with readline support for PyQt&sip-3.6 and earlier. |
|
38 </p><p> |
|
39 Full readline support is present in PyQt&sip-snapshot-20030531 and later. |
|
40 </p><p> |
|
41 |
|
42 </p><p> |
|
43 <h4>NOTE for FlexCompleter</h4> |
|
44 </p><p> |
|
45 This version is a re-implementation of rlcompleter with |
|
46 selectable namespace. |
|
47 </p><p> |
|
48 The problem with rlcompleter is that it's hardwired to work with |
|
49 __main__.__dict__, and in some cases one may have 'sandboxed' namespaces. |
|
50 So this class is a ripoff of rlcompleter, with the namespace to work in as |
|
51 an optional parameter. |
|
52 </p><p> |
|
53 This class can be used just like rlcompleter, but the Completer class now |
|
54 has a constructor with the optional 'namespace' parameter. |
|
55 </p><p> |
|
56 A patch has been submitted to Python@sourceforge for these changes to go in |
|
57 the standard Python distribution. |
|
58 </p><p> |
|
59 |
|
60 </p><p> |
|
61 <h4>Original rlcompleter documentation</h4> |
|
62 </p><p> |
|
63 This requires the latest extension to the readline module (the |
|
64 completes keywords, built-ins and globals in __main__; when completing |
|
65 NAME.NAME..., it evaluates (!) the expression up to the last dot and |
|
66 completes its attributes. |
|
67 </p><p> |
|
68 It's very cool to do "import string" type "string.", hit the |
|
69 completion key (twice), and see the list of names defined by the |
|
70 string module! |
|
71 </p><p> |
|
72 Tip: to use the tab key as the completion key, call |
|
73 </p><p> |
|
74 'readline.parse_and_bind("tab: complete")' |
|
75 </p><p> |
|
76 <b>Notes</b>: |
|
77 <ul> |
|
78 <li> |
|
79 Exceptions raised by the completer function are *ignored* (and |
|
80 generally cause the completion to fail). This is a feature -- since |
|
81 readline sets the tty device in raw (or cbreak) mode, printing a |
|
82 traceback wouldn't work well without some complicated hoopla to save, |
|
83 reset and restore the tty state. |
|
84 </li> |
|
85 <li> |
|
86 The evaluation of the NAME.NAME... form may cause arbitrary |
|
87 application defined code to be executed if an object with a |
|
88 __getattr__ hook is found. Since it is the responsibility of the |
|
89 application (or the user) to enable this feature, I consider this an |
|
90 acceptable risk. More complicated expressions (e.g. function calls or |
|
91 indexing operations) are *not* evaluated. |
|
92 </li> |
|
93 <li> |
|
94 GNU readline is also used by the built-in functions input() and |
|
95 raw_input(), and thus these also benefit/suffer from the completer |
|
96 features. Clearly an interactive application can benefit by |
|
97 specifying its own completer function and using raw_input() for all |
|
98 its input. |
|
99 </li> |
|
100 <li> |
|
101 When the original stdin is not a tty device, GNU readline is never |
|
102 used, and this module (and the readline module) are silently inactive. |
|
103 </li> |
|
104 </ul> |
|
105 </p> |
|
106 <h3>Global Attributes</h3> |
|
107 <table> |
|
108 <tr><td>__all__</td></tr> |
|
109 </table> |
|
110 <h3>Classes</h3> |
|
111 <table> |
|
112 <tr> |
|
113 <td><a href="#Completer">Completer</a></td> |
|
114 <td>Class implementing the command line completer object.</td> |
|
115 </tr> |
|
116 </table> |
|
117 <h3>Functions</h3> |
|
118 <table> |
|
119 <tr> |
|
120 <td><a href="#get_class_members">get_class_members</a></td> |
|
121 <td>Module function to retrieve the class members.</td> |
|
122 </tr> |
|
123 </table> |
|
124 <hr /><hr /> |
|
125 <a NAME="Completer" ID="Completer"></a> |
|
126 <h2>Completer</h2> |
|
127 <p> |
|
128 Class implementing the command line completer object. |
|
129 </p> |
|
130 <h3>Derived from</h3> |
|
131 object |
|
132 <h3>Class Attributes</h3> |
|
133 <table> |
|
134 <tr><td>None</td></tr> |
|
135 </table> |
|
136 <h3>Class Methods</h3> |
|
137 <table> |
|
138 <tr><td>None</td></tr> |
|
139 </table> |
|
140 <h3>Methods</h3> |
|
141 <table> |
|
142 <tr> |
|
143 <td><a href="#Completer.__init__">Completer</a></td> |
|
144 <td>Constructor</td> |
|
145 </tr><tr> |
|
146 <td><a href="#Completer._callable_postfix">_callable_postfix</a></td> |
|
147 <td>Protected method to check for a callable.</td> |
|
148 </tr><tr> |
|
149 <td><a href="#Completer.attr_matches">attr_matches</a></td> |
|
150 <td>Public method to compute matches when text contains a dot.</td> |
|
151 </tr><tr> |
|
152 <td><a href="#Completer.complete">complete</a></td> |
|
153 <td>Public method to return the next possible completion for 'text'.</td> |
|
154 </tr><tr> |
|
155 <td><a href="#Completer.global_matches">global_matches</a></td> |
|
156 <td>Public method to compute matches when text is a simple name.</td> |
|
157 </tr> |
|
158 </table> |
|
159 <h3>Static Methods</h3> |
|
160 <table> |
|
161 <tr><td>None</td></tr> |
|
162 </table> |
|
163 <a NAME="Completer.__init__" ID="Completer.__init__"></a> |
|
164 <h4>Completer (Constructor)</h4> |
|
165 <b>Completer</b>(<i>namespace=None</i>) |
|
166 <p> |
|
167 Constructor |
|
168 </p><p> |
|
169 Completer([namespace]) -> completer instance. |
|
170 </p><p> |
|
171 If unspecified, the default namespace where completions are performed |
|
172 is __main__ (technically, __main__.__dict__). Namespaces should be |
|
173 given as dictionaries. |
|
174 </p><p> |
|
175 Completer instances should be used as the completion mechanism of |
|
176 readline via the set_completer() call: |
|
177 </p><p> |
|
178 readline.set_completer(Completer(my_namespace).complete) |
|
179 </p><dl> |
|
180 <dt><i>namespace</i></dt> |
|
181 <dd> |
|
182 namespace for the completer |
|
183 </dd> |
|
184 </dl><dl> |
|
185 <dt>Raises <b>TypeError</b>:</dt> |
|
186 <dd> |
|
187 raised to indicate a wrong namespace structure |
|
188 </dd> |
|
189 </dl><a NAME="Completer._callable_postfix" ID="Completer._callable_postfix"></a> |
|
190 <h4>Completer._callable_postfix</h4> |
|
191 <b>_callable_postfix</b>(<i>val, word</i>) |
|
192 <p> |
|
193 Protected method to check for a callable. |
|
194 </p><dl> |
|
195 <dt><i>val</i></dt> |
|
196 <dd> |
|
197 value to check (object) |
|
198 </dd><dt><i>word</i></dt> |
|
199 <dd> |
|
200 word to ammend (string) |
|
201 </dd> |
|
202 </dl><dl> |
|
203 <dt>Returns:</dt> |
|
204 <dd> |
|
205 ammended word (string) |
|
206 </dd> |
|
207 </dl><a NAME="Completer.attr_matches" ID="Completer.attr_matches"></a> |
|
208 <h4>Completer.attr_matches</h4> |
|
209 <b>attr_matches</b>(<i>text</i>) |
|
210 <p> |
|
211 Public method to compute matches when text contains a dot. |
|
212 </p><p> |
|
213 Assuming the text is of the form NAME.NAME....[NAME], and is |
|
214 evaluatable in self.namespace, it will be evaluated and its attributes |
|
215 (as revealed by dir()) are used as possible completions. (For class |
|
216 instances, class members are are also considered.) |
|
217 </p><p> |
|
218 <b>WARNING</b>: this can still invoke arbitrary C code, if an object |
|
219 with a __getattr__ hook is evaluated. |
|
220 </p><dl> |
|
221 <dt><i>text</i></dt> |
|
222 <dd> |
|
223 The text to be completed. (string) |
|
224 </dd> |
|
225 </dl><dl> |
|
226 <dt>Returns:</dt> |
|
227 <dd> |
|
228 A list of all matches. |
|
229 </dd> |
|
230 </dl><a NAME="Completer.complete" ID="Completer.complete"></a> |
|
231 <h4>Completer.complete</h4> |
|
232 <b>complete</b>(<i>text, state</i>) |
|
233 <p> |
|
234 Public method to return the next possible completion for 'text'. |
|
235 </p><p> |
|
236 This is called successively with state == 0, 1, 2, ... until it |
|
237 returns None. The completion should begin with 'text'. |
|
238 </p><dl> |
|
239 <dt><i>text</i></dt> |
|
240 <dd> |
|
241 The text to be completed. (string) |
|
242 </dd><dt><i>state</i></dt> |
|
243 <dd> |
|
244 The state of the completion. (integer) |
|
245 </dd> |
|
246 </dl><dl> |
|
247 <dt>Returns:</dt> |
|
248 <dd> |
|
249 The possible completions as a list of strings. |
|
250 </dd> |
|
251 </dl><a NAME="Completer.global_matches" ID="Completer.global_matches"></a> |
|
252 <h4>Completer.global_matches</h4> |
|
253 <b>global_matches</b>(<i>text</i>) |
|
254 <p> |
|
255 Public method to compute matches when text is a simple name. |
|
256 </p><dl> |
|
257 <dt><i>text</i></dt> |
|
258 <dd> |
|
259 The text to be completed. (string) |
|
260 </dd> |
|
261 </dl><dl> |
|
262 <dt>Returns:</dt> |
|
263 <dd> |
|
264 A list of all keywords, built-in functions and names currently |
|
265 defined in self.namespace that match. |
|
266 </dd> |
|
267 </dl> |
|
268 <div align="right"><a href="#top">Up</a></div> |
|
269 <hr /><hr /> |
|
270 <a NAME="get_class_members" ID="get_class_members"></a> |
|
271 <h2>get_class_members</h2> |
|
272 <b>get_class_members</b>(<i>klass</i>) |
|
273 <p> |
|
274 Module function to retrieve the class members. |
|
275 </p><dl> |
|
276 <dt><i>klass</i></dt> |
|
277 <dd> |
|
278 The class object to be analysed. |
|
279 </dd> |
|
280 </dl><dl> |
|
281 <dt>Returns:</dt> |
|
282 <dd> |
|
283 A list of all names defined in the class. |
|
284 </dd> |
|
285 </dl> |
|
286 <div align="right"><a href="#top">Up</a></div> |
|
287 <hr /> |
|
288 </body></html> |
|