summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcatherine devlin <catherine.devlin@gmail.com>2011-02-01 18:27:48 -0500
committercatherine devlin <catherine.devlin@gmail.com>2011-02-01 18:27:48 -0500
commitfe85f182b25d0e8a584abaea21249ee4ac32fc47 (patch)
treeae29f9eda90208e30451729f58fe022981ab92d4
parentfaebc062f45a729ca6b60244ff7ef959a5f33d73 (diff)
downloadcmd2-hg-fe85f182b25d0e8a584abaea21249ee4ac32fc47.tar.gz
nesting try/finally for 2.4 compatibility
-rwxr-xr-xcmd2.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/cmd2.py b/cmd2.py
index 854b40a..5201873 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -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):