From 6e8a1d8adb2743a2649118e0f73a46ef697130f3 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 6 Oct 2015 20:04:56 -0700 Subject: [PATCH] codes.py: fix input-with-completion on py3 The input() function returns str(bytes) on py2, and str(unicode) on py3. We want unicode in both cases. --- src/wormhole/codes.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wormhole/codes.py b/src/wormhole/codes.py index 88a8d49..0a49890 100644 --- a/src/wormhole/codes.py +++ b/src/wormhole/codes.py @@ -82,7 +82,10 @@ def input_code_with_completion(prompt, get_channel_ids, code_length): readline.set_completer(c.wrap_completer) readline.set_completer_delims("") code = six.moves.input(prompt) - return code.decode("utf-8") + # Code is str(bytes) on py2, and str(unicode) on py3. We want unicode. + if isinstance(code, bytes): + code = code.decode("utf-8") + return code if __name__ == "__main__": code = input_code_with_completion("Enter wormhole code: ", lambda: [], 2)