From 14dcfeed73673aef5e3815b6ce4d921d47f1a29e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 27 Feb 2016 14:16:58 -0800 Subject: [PATCH] tolerate lack of readline at runtime 'readline' is part of the python stdlib, so declaring a dependency on it doesn't help. It doesn't exist on windows, and the pypi 'readline' module doesn't work on windows. So instead, just attempt to import readline, and if that fails, fall back to a non-completion flavor. --- src/wormhole/codes.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wormhole/codes.py b/src/wormhole/codes.py index 3b1ff79..fd08694 100644 --- a/src/wormhole/codes.py +++ b/src/wormhole/codes.py @@ -17,9 +17,6 @@ def extract_channel_id(code): channel_id = int(code.split("-")[0]) return channel_id -import readline -#import sys - class CodeInputter: def __init__(self, initial_channelids, get_channel_ids, code_length): self._initial_channelids = initial_channelids @@ -86,10 +83,14 @@ class CodeInputter: def input_code_with_completion(prompt, initial_channelids, get_channel_ids, code_length): - c = CodeInputter(initial_channelids, get_channel_ids, code_length) - readline.parse_and_bind("tab: complete") - readline.set_completer(c.wrap_completer) - readline.set_completer_delims("") + try: + import readline + c = CodeInputter(initial_channelids, get_channel_ids, code_length) + readline.parse_and_bind("tab: complete") + readline.set_completer(c.wrap_completer) + readline.set_completer_delims("") + except ImportError: + pass code = six.moves.input(prompt) # Code is str(bytes) on py2, and str(unicode) on py3. We want unicode. if isinstance(code, bytes):