diff options
author | catherine devlin <catherine.devlin@gmail.com> | 2011-02-01 18:27:48 -0500 |
---|---|---|
committer | catherine devlin <catherine.devlin@gmail.com> | 2011-02-01 18:27:48 -0500 |
commit | fe85f182b25d0e8a584abaea21249ee4ac32fc47 (patch) | |
tree | ae29f9eda90208e30451729f58fe022981ab92d4 /cmd2.py | |
parent | faebc062f45a729ca6b60244ff7ef959a5f33d73 (diff) | |
download | cmd2-hg-fe85f182b25d0e8a584abaea21249ee4ac32fc47.tar.gz |
nesting try/finally for 2.4 compatibility
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 41 |
1 files changed, 22 insertions, 19 deletions
@@ -748,28 +748,31 @@ class Cmd(cmd.Cmd): 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): |