|
5 | 5 | 1. End of file on input is processed as the command 'EOF'. |
6 | 6 | 2. A command is parsed out of each line by collecting the prefix composed |
7 | 7 | of characters in the identchars member. |
8 | | -3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method |
| 8 | +3. A command 'foo' is dispatched to a method 'do_foo()'; the do_ method |
9 | 9 | is passed a single argument consisting of the remainder of the line. |
10 | 10 | 4. Typing an empty line repeats the last command. (Actually, it calls the |
11 | | - method `emptyline', which may be overridden in a subclass.) |
12 | | -5. There is a predefined `help' method. Given an argument `topic', it |
13 | | - calls the command `help_topic'. With no arguments, it lists all topics |
| 11 | + method 'emptyline', which may be overridden in a subclass.) |
| 12 | +5. There is a predefined 'help' method. Given an argument 'topic', it |
| 13 | + calls the command 'help_topic'. With no arguments, it lists all topics |
14 | 14 | with defined help_ functions, broken into up to three topics; documented |
15 | 15 | commands, miscellaneous help topics, and undocumented commands. |
16 | | -6. The command '?' is a synonym for `help'. The command '!' is a synonym |
17 | | - for `shell', if a do_shell method exists. |
| 16 | +6. The command '?' is a synonym for 'help'. The command '!' is a synonym |
| 17 | + for 'shell', if a do_shell method exists. |
18 | 18 | 7. If completion is enabled, completing commands will be done automatically, |
19 | 19 | and completing of commands args is done by calling complete_foo() with |
20 | 20 | arguments text, line, begidx, endidx. text is string we are matching |
|
23 | 23 | indexes of the text being matched, which could be used to provide |
24 | 24 | different completion depending upon which position the argument is in. |
25 | 25 |
|
26 | | -The `default' method may be overridden to intercept commands for which there |
| 26 | +The 'default' method may be overridden to intercept commands for which there |
27 | 27 | is no do_ method. |
28 | 28 |
|
29 | | -The `completedefault' method may be overridden to intercept completions for |
| 29 | +The 'completedefault' method may be overridden to intercept completions for |
30 | 30 | commands that have no complete_ method. |
31 | 31 |
|
32 | | -The data member `self.ruler' sets the character used to draw separator lines |
| 32 | +The data member 'self.ruler' sets the character used to draw separator lines |
33 | 33 | in the help messages. If empty, no ruler line is drawn. It defaults to "=". |
34 | 34 |
|
35 | | -If the value of `self.intro' is nonempty when the cmdloop method is called, |
| 35 | +If the value of 'self.intro' is nonempty when the cmdloop method is called, |
36 | 36 | it is printed out on interpreter startup. This value may be overridden |
37 | 37 | via an optional argument to the cmdloop() method. |
38 | 38 |
|
39 | | -The data members `self.doc_header', `self.misc_header', and |
40 | | -`self.undoc_header' set the headers used for the help function's |
| 39 | +The data members 'self.doc_header', 'self.misc_header', and |
| 40 | +'self.undoc_header' set the headers used for the help function's |
41 | 41 | listings of documented functions, miscellaneous topics, and undocumented |
42 | 42 | functions respectively. |
43 | 43 | """ |
44 | 44 |
|
45 | | -import inspect, string, sys |
| 45 | +import sys |
46 | 46 |
|
47 | 47 | __all__ = ["Cmd"] |
48 | 48 |
|
49 | 49 | PROMPT = '(Cmd) ' |
50 | | -IDENTCHARS = string.ascii_letters + string.digits + '_' |
| 50 | +IDENTCHARS = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 51 | + 'abcdefghijklmnopqrstuvwxyz' |
| 52 | + '0123456789' |
| 53 | + '_') |
51 | 54 |
|
52 | 55 | class Cmd: |
53 | 56 | """A simple framework for writing line-oriented command interpreters. |
@@ -270,7 +273,7 @@ def complete(self, text, state): |
270 | 273 | endidx = readline.get_endidx() - stripped |
271 | 274 | if begidx>0: |
272 | 275 | cmd, args, foo = self.parseline(line) |
273 | | - if cmd == '': |
| 276 | + if not cmd: |
274 | 277 | compfunc = self.completedefault |
275 | 278 | else: |
276 | 279 | try: |
@@ -303,9 +306,11 @@ def do_help(self, arg): |
303 | 306 | try: |
304 | 307 | func = getattr(self, 'help_' + arg) |
305 | 308 | except AttributeError: |
| 309 | + from inspect import cleandoc |
| 310 | + |
306 | 311 | try: |
307 | 312 | doc=getattr(self, 'do_' + arg).__doc__ |
308 | | - doc = inspect.cleandoc(doc) |
| 313 | + doc = cleandoc(doc) |
309 | 314 | if doc: |
310 | 315 | self.stdout.write("%s\n"%str(doc)) |
311 | 316 | return |
|
0 commit comments