diff options
author | Todd Leonhardt <tleonhardt@gmail.com> | 2017-05-03 18:43:58 -0400 |
---|---|---|
committer | Todd Leonhardt <tleonhardt@gmail.com> | 2017-05-03 18:43:58 -0400 |
commit | 660bd38a1ecc36a6c7aaa5c27841a3957978802b (patch) | |
tree | 5c9d21ce43ca9847cb28df66d7995a3b5feb71ce /cmd2.py | |
parent | 8d704b424d9e920a080a531c4adb2b37d269b302 (diff) | |
download | cmd2-git-660bd38a1ecc36a6c7aaa5c27841a3957978802b.tar.gz |
Added some checks to deal with unit testing on Windows systems with no readline
NOTE: For real use on Windows you should have pyreadline installed.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -64,9 +64,12 @@ from six.moves.urllib.request import urlopen # Prefer statically linked gnureadline if available (for Mac OS X compatibility due to issues with libedit) try: - import gnureadline + import gnureadline as readline except ImportError: - import readline + try: + import readline + except ImportError: + pass # 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 @@ -1132,9 +1135,12 @@ class Cmd(cmd.Cmd): # An almost perfect copy from Cmd; however, the pseudo_raw_input portion # has been split out so that it can be called separately if self.use_rawinput and self.completekey: - self.old_completer = readline.get_completer() - readline.set_completer(self.complete) - readline.parse_and_bind(self.completekey + ": complete") + try: + self.old_completer = readline.get_completer() + readline.set_completer(self.complete) + readline.parse_and_bind(self.completekey + ": complete") + except NameError: + pass stop = None try: while not stop: @@ -1148,7 +1154,10 @@ class Cmd(cmd.Cmd): stop = self.onecmd_plus_hooks(line) finally: if self.use_rawinput and self.completekey: - readline.set_completer(self.old_completer) + try: + readline.set_completer(self.old_completer) + except NameError: + pass return stop # noinspection PyUnusedLocal |