comparison cmd2.py @ 221:9aa1f34455b4 0.4.8

autobind test failing
author catherine@Elli.myhome.westell.com
date Wed, 18 Mar 2009 22:02:15 -0400
parents 8c277a37e2bc
children 1702ce785a8d
comparison
equal deleted inserted replaced
220:8c277a37e2bc 221:9aa1f34455b4
742 os.system(arg) 742 os.system(arg)
743 743
744 def do_py(self, arg): 744 def do_py(self, arg):
745 ''' 745 '''
746 py <command>: Executes a Python command. 746 py <command>: Executes a Python command.
747 py: Enters interactive Python mode (end with `\py`). 747 py: Enters interactive Python mode (end with `end py`).
748 ''' 748 '''
749 if arg.strip(): 749 if arg.strip():
750 try: 750 try:
751 result = eval(arg, self.pystate) 751 result = eval(arg, self.pystate)
752 if result is None: 752 print repr(result)
753 except SyntaxError:
754 try:
753 exec(arg, self.pystate) 755 exec(arg, self.pystate)
754 else: 756 except Exception:
755 print result 757 raise
756 except Exception, e: 758 except Exception, e:
757 print e 759 print e
758 else: 760 else:
759 print 'Now accepting python commands; end with `\\py`' 761 print 'Now accepting python commands; end with `end py`'
760 buffer = [self.pseudo_raw_input('>>> ')] 762 buffer = [self.pseudo_raw_input('>>> ')]
761 while not buffer[-1].strip().startswith('\\py'): 763 while buffer[-1].lower().split()[:2] != ['end','py']:
762 try: 764 try:
763 buf = '\n'.join(buffer) 765 buf = '\n'.join(buffer)
764 try: 766 try:
765 result = eval(buf, self.pystate) 767 result = eval(buf, self.pystate)
766 print repr(result) 768 print repr(result)