Mercurial > python-cmd2
changeset 235:78ad20c2eed0
py working better now; still needs a iscomplete=True on onecmd
author | catherine@dellzilla |
---|---|
date | Tue, 24 Mar 2009 13:48:25 -0400 |
parents | ff99b39259d5 |
children | 035330ccfcf0 |
files | cmd2.py |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd2.py Tue Mar 24 13:29:54 2009 -0400 +++ b/cmd2.py Tue Mar 24 13:48:25 2009 -0400 @@ -26,7 +26,8 @@ flagReader.py options are still supported for backward compatibility """ import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest -import unittest, string, datetime, urllib, inspect, code +import unittest, string, datetime, urllib, inspect +from code import InteractiveConsole, InteractiveInterpreter, softspace from optparse import make_option __version__ = '0.4.8' @@ -225,7 +226,7 @@ class EmbeddedConsoleExit(Exception): pass -class InteractiveConsole(code.InteractiveConsole): +class MyInteractiveConsole(InteractiveConsole): def runcode(self, code): """Execute a code object. @@ -247,7 +248,7 @@ except: self.showtraceback() else: - if code.softspace(sys.stdout, 0): + if softspace(sys.stdout, 0): print class Cmd(cmd.Cmd): @@ -796,17 +797,20 @@ Non-python commands can be issued with cmd('your non-python command here'). ''' if arg.strip(): - interp = code.InteractiveInterpreter(locals=self.pystate) + interp = InteractiveInterpreter(locals=self.pystate) interp.runcode(arg) else: - interp = InteractiveConsole(locals=self.pystate) + interp = MyInteractiveConsole(locals=self.pystate) def quit(): raise EmbeddedConsoleExit self.pystate['quit'] = quit self.pystate['exit'] = quit + self.pystate[self.nonpythoncommand] = self.onecmd try: interp.interact() - except (EmbeddedConsoleExit, SystemExit): + except SystemExit: + quit() + except EmbeddedConsoleExit: return def do_history(self, arg):