Mercurial > cpython-lru_cache-weakref
annotate Lib/cmd.py @ 1590:ac2e5cc29949 legacy-trunk
Added tests for missing host to open_http and open_gopher
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 18 Apr 1994 09:39:56 +0000 |
| parents | 560ec7030817 |
| children | 1940892d2fe3 |
| rev | line source |
|---|---|
| 624 | 1 # A generic class to build line-oriented command interpreters |
| 2 | |
| 3 import string | |
| 4 import sys | |
| 5 import linecache | |
| 6 | |
| 7 PROMPT = '(Cmd) ' | |
| 8 IDENTCHARS = string.letters + string.digits + '_' | |
| 9 | |
| 10 class Cmd: | |
|
1315
acdc0b9a6c78
* aifc.py: don't die on invalid MARK chunk
Guido van Rossum <guido@python.org>
parents:
1086
diff
changeset
|
11 |
|
acdc0b9a6c78
* aifc.py: don't die on invalid MARK chunk
Guido van Rossum <guido@python.org>
parents:
1086
diff
changeset
|
12 def __init__(self): |
| 624 | 13 self.prompt = PROMPT |
| 14 self.identchars = IDENTCHARS | |
| 15 self.lastcmd = '' | |
| 16 | |
| 17 def cmdloop(self): | |
| 18 stop = None | |
| 19 while not stop: | |
| 20 try: | |
| 21 line = raw_input(self.prompt) | |
| 22 except EOFError: | |
| 23 line = 'EOF' | |
| 24 stop = self.onecmd(line) | |
| 25 | |
| 26 def onecmd(self, line): | |
| 27 line = string.strip(line) | |
| 28 if not line: | |
| 29 line = self.lastcmd | |
| 30 else: | |
| 31 self.lastcmd = line | |
| 32 i, n = 0, len(line) | |
| 33 while i < n and line[i] in self.identchars: i = i+1 | |
| 34 cmd, arg = line[:i], string.strip(line[i:]) | |
| 35 if cmd == '': | |
| 36 return self.default(line) | |
| 37 else: | |
| 38 try: | |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
979
diff
changeset
|
39 func = getattr(self, 'do_' + cmd) |
| 624 | 40 except AttributeError: |
| 41 return self.default(line) | |
| 42 return func(arg) | |
| 43 | |
| 44 def default(self, line): | |
| 45 print '*** Unknown syntax:', line | |
| 46 | |
| 47 def do_help(self, arg): | |
| 48 if arg: | |
| 49 # XXX check arg syntax | |
| 50 try: | |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
979
diff
changeset
|
51 func = getattr(self, 'help_' + arg) |
| 624 | 52 except: |
| 53 print '*** No help on', `arg` | |
| 54 return | |
| 55 func() | |
| 56 else: | |
|
979
3c55e612a6fc
Module getattr doesn't exist any more, it's now called newdir.
Guido van Rossum <guido@python.org>
parents:
650
diff
changeset
|
57 import newdir |
|
1315
acdc0b9a6c78
* aifc.py: don't die on invalid MARK chunk
Guido van Rossum <guido@python.org>
parents:
1086
diff
changeset
|
58 names = newdir.dir(self.__class__) |
| 624 | 59 cmds = [] |
| 60 for name in names: | |
| 61 if name[:3] == 'do_': | |
| 62 cmds.append(name[3:]) | |
| 63 print cmds |
