rest25/library/cmd.rst => rest262/library/cmd.rst
21   to inherit :class:`Cmd`'s methods and encapsulate action methods.
22
23   The optional argument *completekey* is the :mod:`readline` name of a completion
24   key; it defaults to :kbd:`Tab`. If *completekey* is not :const:`None` and
25   :mod:`readline` is available, command completion is done automatically.
26
27   The optional arguments *stdin* and *stdout* specify the  input and output file
28   objects that the Cmd instance or subclass  instance will use for input and
n29-   output. If not specified, they will default to *sys.stdin* and *sys.stdout*.
n29+   output. If not specified, they will default to :data:`sys.stdin` and
30+   :data:`sys.stdout`.
31+ 
32+   If you want a given *stdin* to be used, make sure to set the instance's
33+   :attr:`use_rawinput` attribute to ``False``, otherwise *stdin* will be
34+   ignored.
30
31   .. versionchanged:: 2.3
32      The *stdin* and *stdout* parameters were added.
33
34
35.. _cmd-objects:
36
37Cmd Objects
38-----------
39
40A :class:`Cmd` instance has the following methods:
41
42
n43-.. method:: XXX Class.cmdloop([intro])
n48+.. method:: Cmd.cmdloop([intro])
44
45   Repeatedly issue a prompt, accept input, parse an initial prefix off the
46   received input, and dispatch to action methods, passing them the remainder of
47   the line as argument.
48
49   The optional argument is a banner or intro string to be issued before the first
50   prompt (this overrides the :attr:`intro` class member).
51
77
78   All subclasses of :class:`Cmd` inherit a predefined :meth:`do_help`. This
79   method, called with an argument ``'bar'``, invokes the corresponding method
80   :meth:`help_bar`.  With no argument, :meth:`do_help` lists all available help
81   topics (that is, all commands with corresponding :meth:`help_\*` methods), and
82   also lists any undocumented commands.
83
84
n85-.. method:: XXX Class.onecmd(str)
n90+.. method:: Cmd.onecmd(str)
86
87   Interpret the argument as though it had been typed in response to the prompt.
88   This may be overridden, but should not normally need to be; see the
89   :meth:`precmd` and :meth:`postcmd` methods for useful execution hooks.  The
90   return value is a flag indicating whether interpretation of commands by the
91   interpreter should stop.  If there is a :meth:`do_\*` method for the command
92   *str*, the return value of that method is returned, otherwise the return value
93   from the :meth:`default` method is returned.
94
95
n96-.. method:: XXX Class.emptyline()
n101+.. method:: Cmd.emptyline()
97
98   Method called when an empty line is entered in response to the prompt. If this
99   method is not overridden, it repeats the last nonempty command entered.
100
101
n102-.. method:: XXX Class.default(line)
n107+.. method:: Cmd.default(line)
103
104   Method called on an input line when the command prefix is not recognized. If
105   this method is not overridden, it prints an error message and returns.
106
107
n108-.. method:: XXX Class.completedefault(text, line, begidx, endidx)
n113+.. method:: Cmd.completedefault(text, line, begidx, endidx)
109
110   Method called to complete an input line when no command-specific
111   :meth:`complete_\*` method is available.  By default, it returns an empty list.
112
113
n114-.. method:: XXX Class.precmd(line)
n119+.. method:: Cmd.precmd(line)
115
116   Hook method executed just before the command line *line* is interpreted, but
117   after the input prompt is generated and issued.  This method is a stub in
118   :class:`Cmd`; it exists to be overridden by subclasses.  The return value is
119   used as the command which will be executed by the :meth:`onecmd` method; the
120   :meth:`precmd` implementation may re-write the command or simply return *line*
121   unchanged.
122
123
n124-.. method:: XXX Class.postcmd(stop, line)
n129+.. method:: Cmd.postcmd(stop, line)
125
126   Hook method executed just after a command dispatch is finished.  This method is
127   a stub in :class:`Cmd`; it exists to be overridden by subclasses.  *line* is the
128   command line which was executed, and *stop* is a flag which indicates whether
129   execution will be terminated after the call to :meth:`postcmd`; this will be the
130   return value of the :meth:`onecmd` method.  The return value of this method will
131   be used as the new value for the internal flag which corresponds to *stop*;
132   returning false will cause interpretation to continue.
133
134
n135-.. method:: XXX Class.preloop()
n140+.. method:: Cmd.preloop()
136
137   Hook method executed once when :meth:`cmdloop` is called.  This method is a stub
138   in :class:`Cmd`; it exists to be overridden by subclasses.
139
140
n141-.. method:: XXX Class.postloop()
n146+.. method:: Cmd.postloop()
142
143   Hook method executed once when :meth:`cmdloop` is about to return. This method
144   is a stub in :class:`Cmd`; it exists to be overridden by subclasses.
145
146Instances of :class:`Cmd` subclasses have some public instance variables:
147
148
n149-.. attribute:: XXX Class.prompt
n154+.. attribute:: Cmd.prompt
150
151   The prompt issued to solicit input.
152
153
n154-.. attribute:: XXX Class.identchars
n159+.. attribute:: Cmd.identchars
155
156   The string of characters accepted for the command prefix.
157
158
n159-.. attribute:: XXX Class.lastcmd
n164+.. attribute:: Cmd.lastcmd
160
161   The last nonempty command prefix seen.
162
163
n164-.. attribute:: XXX Class.intro
n169+.. attribute:: Cmd.intro
165
166   A string to issue as an intro or banner.  May be overridden by giving the
167   :meth:`cmdloop` method an argument.
168
169
n170-.. attribute:: XXX Class.doc_header
n175+.. attribute:: Cmd.doc_header
171
172   The header to issue if the help output has a section for documented commands.
173
174
n175-.. attribute:: XXX Class.misc_header
n180+.. attribute:: Cmd.misc_header
176
177   The header to issue if the help output has a section for miscellaneous  help
178   topics (that is, there are :meth:`help_\*` methods without corresponding
179   :meth:`do_\*` methods).
180
181
n182-.. attribute:: XXX Class.undoc_header
n187+.. attribute:: Cmd.undoc_header
183
184   The header to issue if the help output has a section for undocumented  commands
185   (that is, there are :meth:`do_\*` methods without corresponding :meth:`help_\*`
186   methods).
187
188
n189-.. attribute:: XXX Class.ruler
n194+.. attribute:: Cmd.ruler
190
191   The character used to draw separator lines under the help-message headers.  If
192   empty, no ruler line is drawn.  It defaults to ``'='``.
193
194
t195-.. attribute:: XXX Class.use_rawinput
t200+.. attribute:: Cmd.use_rawinput
196
197   A flag, defaulting to true.  If true, :meth:`cmdloop` uses :func:`raw_input` to
198   display a prompt and read the next command; if false, :meth:`sys.stdout.write`
199   and :meth:`sys.stdin.readline` are used. (This means that by importing
200   :mod:`readline`, on systems that support it, the interpreter will automatically
201   support :program:`Emacs`\ -like line editing  and command-history keystrokes.)
202
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op