5959# itertools.zip() for Python 2 or zip() for Python 3 - produces an iterator in both cases
6060from six .moves import zip
6161
62- # Python 3 compatibility hack due to no built-in file keyword in Python 3
63- # Due to one occurrence of isinstance(<foo>, file) checking to see if something is of file type
64- try :
65- # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
66- file
67- except NameError :
68- import io
69- file = io .TextIOWrapper
70-
7162# Detect whether IPython is installed to determine if the built-in "ipy" command should be included
7263ipython_available = True
7364try :
@@ -927,13 +918,18 @@ def _cmdloop(self):
927918 stop = None
928919 try :
929920 while not stop :
930- # NOTE: cmdqueue appears completely unused, but it is defined in cmd.Cmd, so we are leaving it here
931921 if self .cmdqueue :
922+ # Run command out of cmdqueue if nonempty (populated by load command or commands at invocation)
932923 line = self .cmdqueue .pop (0 )
933924 else :
925+ # Otherwise, read a command from stdin
934926 line = self .pseudo_raw_input (self .prompt )
935- if self .echo and isinstance (self .stdin , file ):
927+
928+ # If echo is on and in the middle of running a script, then echo the line to the output
929+ if self .echo and self ._current_script_dir is not None :
936930 self .stdout .write (line + '\n ' )
931+
932+ # Run the command along with all associated pre and post hooks
937933 stop = self .onecmd_plus_hooks (line )
938934 finally :
939935 if self .use_rawinput and self .completekey :
@@ -942,6 +938,11 @@ def _cmdloop(self):
942938 readline .set_completer_delims (self .old_delims )
943939 except NameError :
944940 pass
941+
942+ # Need to set empty list this way because Python 2 doesn't support the clear() method on lists
943+ self .cmdqueue = []
944+ self ._script_dir = []
945+
945946 return stop
946947
947948 # noinspection PyUnusedLocal
0 commit comments