summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-10-10 16:12:23 +0200
committeremkael <emkael@tlen.pl>2016-10-10 16:12:23 +0200
commit1278ce8686853ec67b1359435d9d2ae1981b5d54 (patch)
tree17d40f89b974bc7793d64a98b483a5da344342a0
parentac6d5ebbed923ec7e3ded5c97d55ad2c0ac14f99 (diff)
encoding readline completer options in case Python2 unicode strings are involved
-rw-r--r--ql/completer.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/ql/completer.py b/ql/completer.py
index a9b7d8d..89920d4 100644
--- a/ql/completer.py
+++ b/ql/completer.py
@@ -1,4 +1,5 @@
import readline
+import sys
class Completer(object):
@@ -10,8 +11,15 @@ class Completer(object):
readline.set_completer_delims('') # allow options with whitespace
readline.parse_and_bind('tab: complete')
+ def __encode_completion_string(self, s):
+ try:
+ return s.encode(sys.stdin.encoding) if isinstance(s, unicode) else s
+ except NameError: # Python 3.x does not have a 'unicode' type
+ pass
+ return s
+
def __init__(self, options):
- self.options = options
+ self.options = [self.__encode_completion_string(s) for s in options]
def complete(self, text, state):
text = text.lower()