# HG changeset patch # User catherine.devlin@gmail.com # Date 1296602868 18000 # Node ID a9f936346399f070d8e58c29c8ab18068ad09bfc # Parent d858a03fbdbbca9a1f3842d9388175095cb00c34 nesting try/finally for 2.4 compatibility diff -r d858a03fbdbb -r a9f936346399 cmd2.py --- a/cmd2.py Wed Nov 17 21:59:01 2010 -0500 +++ b/cmd2.py Tue Feb 01 18:27:48 2011 -0500 @@ -748,28 +748,31 @@ result = 'do_' + funcs[0] return result def onecmd_plus_hooks(self, line): + # The outermost level of try/finally nesting can be condensed once + # Python 2.4 support can be dropped. stop = 0 try: - statement = self.complete_statement(line) - (stop, statement) = self.postparsing_precmd(statement) - if stop: - return self.postparsing_postcmd(stop) - if statement.parsed.command not in self.excludeFromHistory: - self.history.append(statement.parsed.raw) try: - self.redirect_output(statement) - timestart = datetime.datetime.now() - statement = self.precmd(statement) - stop = self.onecmd(statement) - stop = self.postcmd(stop, statement) - if self.timing: - self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart)) - finally: - self.restore_output(statement) - except EmptyStatement: - return 0 - except Exception, e: - self.perror(str(e), statement) + statement = self.complete_statement(line) + (stop, statement) = self.postparsing_precmd(statement) + if stop: + return self.postparsing_postcmd(stop) + if statement.parsed.command not in self.excludeFromHistory: + self.history.append(statement.parsed.raw) + try: + self.redirect_output(statement) + timestart = datetime.datetime.now() + statement = self.precmd(statement) + stop = self.onecmd(statement) + stop = self.postcmd(stop, statement) + if self.timing: + self.pfeedback('Elapsed: %s' % str(datetime.datetime.now() - timestart)) + finally: + self.restore_output(statement) + except EmptyStatement: + return 0 + except Exception, e: + self.perror(str(e), statement) finally: return self.postparsing_postcmd(stop) def complete_statement(self, line):