[Python-checkins] python/dist/src/Lib cmd.py,1.26.16.1,1.26.16.2
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
2002年5月29日 16:15:48 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv765
Modified Files:
Tag: release22-maint
cmd.py
Log Message:
Backport change to 1.29 adding docstrings
Index: cmd.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cmd.py,v
retrieving revision 1.26.16.1
retrieving revision 1.26.16.2
diff -C2 -d -r1.26.16.1 -r1.26.16.2
*** cmd.py 25 Mar 2002 12:34:15 -0000 1.26.16.1
--- cmd.py 29 May 2002 23:15:46 -0000 1.26.16.2
***************
*** 54,57 ****
--- 54,68 ----
class Cmd:
+ """A simple framework for writing line-oriented command interpreters.
+
+ These are often useful for test harnesses, administrative tools, and
+ prototypes that will later be wrapped in a more sophisticated interface.
+
+ A Cmd instance or subclass instance is a line-oriented interpreter
+ framework. There is no good reason to instantiate Cmd itself; rather,
+ it's useful as a superclass of an interpreter class you define yourself
+ in order to inherit Cmd's methods and encapsulate action methods.
+
+ """
prompt = PROMPT
identchars = IDENTCHARS
***************
*** 68,71 ****
--- 79,90 ----
def __init__(self, completekey='tab'):
+ """Instantiate a line-oriented interpreter framework.
+
+ The optional argument is the readline name of a completion key;
+ it defaults to the Tab key. If completekey is not None and the
+ readline module is available, command completion is done
+ automatically.
+
+ """
if completekey:
try:
***************
*** 77,80 ****
--- 96,105 ----
def cmdloop(self, intro=None):
+ """Repeatedly issue a prompt, accept input, parse an initial prefix
+ off the received input, and dispatch to action methods, passing them
+ the remainder of the line as argument.
+
+ """
+
self.preloop()
if intro is not None:
***************
*** 107,119 ****
--- 132,154 ----
def precmd(self, line):
+ """Hook method executed just before the command line is
+ interpreted, but after the input prompt is generated and issued.
+
+ """
return line
def postcmd(self, stop, line):
+ """Hook method executed just after a command dispatch is finished."""
return stop
def preloop(self):
+ """Hook method executed once when the cmdloop() method is called."""
pass
def postloop(self):
+ """Hook method executed once when the cmdloop() method is about to
+ return.
+
+ """
pass
***************
*** 135,138 ****
--- 170,182 ----
def onecmd(self, line):
+ """Interpret the argument as though it had been typed in response
+ to the prompt.
+
+ This may be overridden, but should not normally need to be;
+ see the precmd() and postcmd() methods for useful execution hooks.
+ The return value is a flag indicating whether interpretation of
+ commands by the interpreter should stop.
+
+ """
cmd, arg, line = self.parseline(line)
if not line:
***************
*** 151,161 ****
--- 195,223 ----
def emptyline(self):
+ """Called when an empty line is entered in response to the prompt.
+
+ If this method is not overridden, it repeats the last nonempty
+ command entered.
+
+ """
if self.lastcmd:
return self.onecmd(self.lastcmd)
def default(self, line):
+ """Called on an input line when the command prefix is not recognized.
+
+ If this method is not overridden, it prints an error message and
+ returns.
+
+ """
print '*** Unknown syntax:', line
def completedefault(self, *ignored):
+ """Method called to complete an input line when no command-specific
+ complete_*() method is available.
+
+ By default, it returns an empty list.
+
+ """
return []