changeset 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
files cmd2.py
diffstat 1 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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):