comparison cmd2.py @ 328:7b2bca3951a7

locals_in_py
author cat@eee
date Fri, 12 Feb 2010 15:35:48 -0500
parents e9eea93c777c
children c69ad8418d39
comparison
equal deleted inserted replaced
327:e9eea93c777c 328:7b2bca3951a7
400 current_script_dir = None 400 current_script_dir = None
401 reserved_words = [] 401 reserved_words = []
402 feedback_to_output = False # Do include nonessentials in >, | output 402 feedback_to_output = False # Do include nonessentials in >, | output
403 quiet = False # Do not suppress nonessential output 403 quiet = False # Do not suppress nonessential output
404 debug = False 404 debug = False
405 locals_in_py = False
405 settable = stubbornDict(''' 406 settable = stubbornDict('''
406 prompt 407 prompt
407 colors Colorized output (*nix only) 408 colors Colorized output (*nix only)
408 continuation_prompt 409 continuation_prompt
409 debug 410 debug
1028 arg = arg.parsed.raw[2:].strip() 1029 arg = arg.parsed.raw[2:].strip()
1029 if arg.strip(): 1030 if arg.strip():
1030 interp = InteractiveInterpreter(locals=self.pystate) 1031 interp = InteractiveInterpreter(locals=self.pystate)
1031 interp.runcode(arg) 1032 interp.runcode(arg)
1032 else: 1033 else:
1033 interp = MyInteractiveConsole(locals=self.pystate) 1034 localvars = (self.locals_in_py and self.pystate) or {}
1035 interp = MyInteractiveConsole(locals=localvars)
1034 def quit(): 1036 def quit():
1037 'blah'
1035 raise EmbeddedConsoleExit 1038 raise EmbeddedConsoleExit
1036 def onecmd(arg): 1039 def onecmd(arg):
1037 return self.onecmd(arg + '\n') 1040 return self.onecmd(arg + '\n')
1038 self.pystate['quit'] = quit 1041 self.pystate['quit'] = quit
1039 self.pystate['exit'] = quit 1042 self.pystate['exit'] = quit
1043 self.pystate['cmd'] = onecmd
1040 try: 1044 try:
1041 cprt = 'Type "help", "copyright", "credits" or "license" for more information.' 1045 cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
1042 keepstate = Statekeeper(sys, ('stdin','stdout')) 1046 keepstate = Statekeeper(sys, ('stdin','stdout'))
1043 sys.stdout = self.stdout 1047 sys.stdout = self.stdout
1044 sys.stdin = self.stdin 1048 sys.stdin = self.stdin