diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index e2d9a1f..4f03415 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -286,7 +286,7 @@ class Console(object): # This pattern should match all characters that change the cursor position differently # than a normal character. - motion_char_re = re.compile('([\n\r\t\010\007])') + motion_char_re = re.compile(b'([\n\r\t\010\007])') def write_scrolling(self, text, attr=None): '''write text at current cursor position while watching for scrolling. @@ -306,7 +306,7 @@ class Console(object): w, h = self.size() scroll = 0 # the result # split the string into ordinary characters and funny characters - chunks = self.motion_char_re.split(text) + chunks = self.motion_char_re.split(ensure_str(text)) for chunk in chunks: n = self.write_color(chunk, attr) if len(chunk) == 1: # the funny characters will be alone @@ -690,7 +690,7 @@ def hook_wrapper_23(stdin, stdout, prompt): # call the Python hook res = ensure_str(readline_hook(prompt)) # make sure it returned the right sort of thing - if res and not isinstance(res, str): + if res and not isinstance(res, bytes): raise TypeError('readline must return a string.') except KeyboardInterrupt: # GNU readline returns 0 on keyboard interrupt @@ -714,7 +714,7 @@ def hook_wrapper(prompt): # call the Python hook res = ensure_str(readline_hook(prompt)) # make sure it returned the right sort of thing - if res and not isinstance(res, str): + if res and not isinstance(res, bytes): raise TypeError('readline must return a string.') except KeyboardInterrupt: # GNU readline returns 0 on keyboard interrupt @@ -738,7 +738,7 @@ def install_readline(hook): readline_hook = hook # get the address of PyOS_ReadlineFunctionPointer so we can update it PyOS_RFP = c_int.from_address(Console.GetProcAddress(sys.dllhandle, - "PyOS_ReadlineFunctionPointer")) + b"PyOS_ReadlineFunctionPointer")) # save a reference to the generated C-callable so it doesn't go away if sys.version < '2.3': readline_ref = HOOKFUNC22(hook_wrapper) diff --git a/pyreadline/lineeditor/history.py b/pyreadline/lineeditor/history.py index d5fbe14..b561a9a 100644 --- a/pyreadline/lineeditor/history.py +++ b/pyreadline/lineeditor/history.py @@ -15,9 +15,7 @@ else: from . import lineobj -import exceptions - -class EscapeHistory(exceptions.Exception): +class EscapeHistory(Exception): pass from pyreadline.logger import log diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index cc8704f..35123e3 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -196,7 +196,7 @@ class BaseMode(object): i = 0 while 1: try: - r = ensure_unicode(self.completer(text, i)) + r = self.completer(ensure_unicode(text), i) except IndexError: break i += 1 @@ -216,7 +216,7 @@ class BaseMode(object): break text = ensure_str(''.join(buf[self.begidx:self.endidx])) log('file complete text="%s"' % ensure_unicode(text)) - completions = list(map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))) + completions = list(map(ensure_unicode, glob.glob(os.path.expanduser(text) + b'*'))) if self.mark_directories == 'on': mc = [] for f in completions: diff --git a/pyreadline/test/test_emacs.py b/pyreadline/test/test_emacs.py index f4dcf62..765691f 100644 --- a/pyreadline/test/test_emacs.py +++ b/pyreadline/test/test_emacs.py @@ -14,7 +14,7 @@ from pyreadline.modes.emacs import * from pyreadline import keysyms from pyreadline.lineeditor import lineobj -from .common import * +from common import * from pyreadline.logger import log import pyreadline.logger as logger logger.sock_silent=True diff --git a/pyreadline/test/test_vi.py b/pyreadline/test/test_vi.py index e0be991..32d14e6 100644 --- a/pyreadline/test/test_vi.py +++ b/pyreadline/test/test_vi.py @@ -13,9 +13,9 @@ from pyreadline import keysyms from pyreadline.lineeditor import lineobj from pyreadline.logger import log import pyreadline.logger as logger -from .common import * +from common import * -from .common import * +from common import * #---------------------------------------------------------------------- class ViModeTest (ViMode): diff --git a/pyreadline/unicode_helper.py b/pyreadline/unicode_helper.py index 71d7c29..dd9b164 100644 --- a/pyreadline/unicode_helper.py +++ b/pyreadline/unicode_helper.py @@ -19,7 +19,7 @@ if pyreadline_codepage is None: def ensure_unicode(text): """helper to ensure that text passed to WriteConsoleW is unicode""" - if isinstance(text, str): + if isinstance(text, bytes): try: return text.decode(pyreadline_codepage, "replace") except (LookupError, TypeError):