summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-07-08 12:34:24 -0400
committerGitHub <noreply@github.com>2017-07-08 12:34:24 -0400
commita140ad1cdb531d2bc60237502cf8601f46d60692 (patch)
tree0a81b43613d77548f792721773d707a52f4fb282 /cmd2.py
parent22c43d7226b93b8d01ebb07de3fd41fda63f9005 (diff)
parentaf248f98c8a6c35c0ea68d59057830de25cd3f9b (diff)
downloadcmd2-git-a140ad1cdb531d2bc60237502cf8601f46d60692.tar.gz
Merge pull request #178 from python-cmd2/remove_filehack
Remove ugly file hack code which is no longer necessary
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/cmd2.py b/cmd2.py
index c83a9bf0..dba8689c 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -59,15 +59,6 @@ import six.moves as sm
# itertools.zip() for Python 2 or zip() for Python 3 - produces an iterator in both cases
from six.moves import zip
-# Python 3 compatibility hack due to no built-in file keyword in Python 3
-# Due to one occurrence of isinstance(<foo>, file) checking to see if something is of file type
-try:
- # noinspection PyUnboundLocalVariable,PyUnresolvedReferences
- file
-except NameError:
- import io
- file = io.TextIOWrapper
-
# Detect whether IPython is installed to determine if the built-in "ipy" command should be included
ipython_available = True
try:
@@ -927,13 +918,18 @@ class Cmd(cmd.Cmd):
stop = None
try:
while not stop:
- # NOTE: cmdqueue appears completely unused, but it is defined in cmd.Cmd, so we are leaving it here
if self.cmdqueue:
+ # Run command out of cmdqueue if nonempty (populated by load command or commands at invocation)
line = self.cmdqueue.pop(0)
else:
+ # Otherwise, read a command from stdin
line = self.pseudo_raw_input(self.prompt)
- if self.echo and isinstance(self.stdin, file):
+
+ # If echo is on and in the middle of running a script, then echo the line to the output
+ if self.echo and self._current_script_dir is not None:
self.stdout.write(line + '\n')
+
+ # Run the command along with all associated pre and post hooks
stop = self.onecmd_plus_hooks(line)
finally:
if self.use_rawinput and self.completekey:
@@ -942,6 +938,11 @@ class Cmd(cmd.Cmd):
readline.set_completer_delims(self.old_delims)
except NameError:
pass
+
+ # Need to set empty list this way because Python 2 doesn't support the clear() method on lists
+ self.cmdqueue = []
+ self._script_dir = []
+
return stop
# noinspection PyUnusedLocal