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 | 5b3a83ae2b4f2cd49d8635c18de6d7f28040ffeb (patch) | |
| tree | ae29f9eda90208e30451729f58fe022981ab92d4 /cmd2.py | |
| parent | 154fe8a56736a00735ab4d7837fbf3c569000ad6 (diff) | |
| download | cmd2-git-5b3a83ae2b4f2cd49d8635c18de6d7f28040ffeb.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): |
