mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-27 16:10:38 +08:00
fix for python3 bytes/str type mismatch.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -15,9 +15,7 @@ else:
|
||||
|
||||
from . import lineobj
|
||||
|
||||
import exceptions
|
||||
|
||||
class EscapeHistory(exceptions.Exception):
|
||||
class EscapeHistory(Exception):
|
||||
pass
|
||||
|
||||
from pyreadline.logger import log
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user