def _cmdloop(self):
"""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.
This serves the same role as cmd.cmdloop().
:return: bool - True implies the entire application should exit.
"""
# An almost perfect copy from Cmd; however, the pseudo_raw_input portion
# has been split out so that it can be called separately
if self.use_rawinput and self.completekey:
try:
self.old_completer = readline.get_completer()
self.old_delims = readline.get_completer_delims()
readline.set_completer(self.complete)
# Don't treat "-" as a readline delimiter since it is commonly used in filesystem paths
readline.set_completer_delims(self.old_delims.replace('-', ''))
readline.parse_and_bind(self.completekey + ": complete")
except NameError:
pass
stop = None
try:
while not stop:
if self.cmdqueue:
# Run command out of cmdqueue if nonempty (populated by load command or commands at invocation)
line = self.cmdqueue.pop(0)
if self.echo and line != 'eos':
self.poutput('{}{}'.format(self.prompt, line))
else:
# Otherwise, read a command from stdin
line = self.pseudo_raw_input(self.prompt)
# Run the command along with all associated pre and post hooks
stop = self.onecmd_plus_hooks(line)
finally:
if self.use_rawinput and self.completekey:
try:
readline.set_completer(self.old_completer)
readline.set_completer_delims(self.old_delims)
except NameError:
pass
# Need to set empty list this way because Python 2 doesn't support the clear() method on lists
self.cmdqueue = []
self._script_dir = []
return stop
# noinspection PyUnusedLocal
评论列表
文章目录