59
59
# itertools.zip() for Python 2 or zip() for Python 3 - produces an iterator in both cases
60
60
from six .moves import zip
61
61
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
-
71
62
# Detect whether IPython is installed to determine if the built-in "ipy" command should be included
72
63
ipython_available = True
73
64
try :
@@ -927,13 +918,18 @@ def _cmdloop(self):
927
918
stop = None
928
919
try :
929
920
while not stop :
930
- # NOTE: cmdqueue appears completely unused, but it is defined in cmd.Cmd, so we are leaving it here
931
921
if self .cmdqueue :
922
+ # Run command out of cmdqueue if nonempty (populated by load command or commands at invocation)
932
923
line = self .cmdqueue .pop (0 )
933
924
else :
925
+ # Otherwise, read a command from stdin
934
926
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 :
936
930
self .stdout .write (line + '\n ' )
931
+
932
+ # Run the command along with all associated pre and post hooks
937
933
stop = self .onecmd_plus_hooks (line )
938
934
finally :
939
935
if self .use_rawinput and self .completekey :
@@ -942,6 +938,11 @@ def _cmdloop(self):
942
938
readline .set_completer_delims (self .old_delims )
943
939
except NameError :
944
940
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
+
945
946
return stop
946
947
947
948
# noinspection PyUnusedLocal
0 commit comments