comparison cmd2.py @ 416:a9f936346399

nesting try/finally for 2.4 compatibility
author catherine.devlin@gmail.com
date Tue, 01 Feb 2011 18:27:48 -0500
parents d858a03fbdbb
children db32ab37051b
comparison
equal deleted inserted replaced
415:d858a03fbdbb 416:a9f936346399
746 funcs = [fname for fname in self.keywords if fname.startswith(arg)] 746 funcs = [fname for fname in self.keywords if fname.startswith(arg)]
747 if len(funcs) == 1: 747 if len(funcs) == 1:
748 result = 'do_' + funcs[0] 748 result = 'do_' + funcs[0]
749 return result 749 return result
750 def onecmd_plus_hooks(self, line): 750 def onecmd_plus_hooks(self, line):
751 # The outermost level of try/finally nesting can be condensed once
752 # Python 2.4 support can be dropped.
751 stop = 0 753 stop = 0
752 try: 754 try:
753 statement = self.complete_statement(line)
754 (stop, statement) = self.postparsing_precmd(statement)
755 if stop:
756 return self.postparsing_postcmd(stop)
757 if statement.parsed.command not in self.excludeFromHistory:
758 self.history.append(statement.parsed.raw)
759 try: 755 try:
760 self.redirect_output(statement) 756 statement = self.complete_statement(line)
761 timestart = datetime.datetime.now() 757 (stop, statement) = self.postparsing_precmd(statement)
762 statement = self.precmd(statement) 758 if stop:
763 stop = self.onecmd(statement) 759 return self.postparsing_postcmd(stop)
764 stop = self.postcmd(stop, statement) 760 if statement.parsed.command not in self.excludeFromHistory:
765 if self.timing: 761 self.history.append(statement.parsed.raw)
766 self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart)) 762 try:
767 finally: 763 self.redirect_output(statement)
768 self.restore_output(statement) 764 timestart = datetime.datetime.now()
769 except EmptyStatement: 765 statement = self.precmd(statement)
770 return 0 766 stop = self.onecmd(statement)
771 except Exception, e: 767 stop = self.postcmd(stop, statement)
772 self.perror(str(e), statement) 768 if self.timing:
769 self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart))
770 finally:
771 self.restore_output(statement)
772 except EmptyStatement:
773 return 0
774 except Exception, e:
775 self.perror(str(e), statement)
773 finally: 776 finally:
774 return self.postparsing_postcmd(stop) 777 return self.postparsing_postcmd(stop)
775 def complete_statement(self, line): 778 def complete_statement(self, line):
776 """Keep accepting lines of input until the command is complete.""" 779 """Keep accepting lines of input until the command is complete."""
777 if (not line) or ( 780 if (not line) or (