mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-27 16:10:38 +08:00
fixed: bytes iteration generate int literal instead of bytes literal
This commit is contained in:
@@ -10,7 +10,7 @@ import re, operator, sys
|
||||
import wordmatcher
|
||||
import pyreadline.clipboard as clipboard
|
||||
from pyreadline.logger import log
|
||||
from pyreadline.unicode_helper import ensure_unicode
|
||||
from pyreadline.unicode_helper import ensure_unicode, biter
|
||||
|
||||
kill_ring_to_clipboard = False #set to true to copy every addition to kill ring to clipboard
|
||||
|
||||
@@ -272,12 +272,12 @@ class TextLine(object):
|
||||
def _insert_text(self, text, argument=1):
|
||||
text = text * argument
|
||||
if self.overwrite:
|
||||
for c in text:
|
||||
for c in biter(text):
|
||||
#if self.point:
|
||||
self.line_buffer[self.point] = c
|
||||
self.point += 1
|
||||
else:
|
||||
for c in text:
|
||||
for c in biter(text):
|
||||
self.line_buffer.insert(self.point, c)
|
||||
self.point += 1
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ if pyreadline_codepage is None:
|
||||
if sys.version_info < (2, 6):
|
||||
bytes = str
|
||||
|
||||
PY3 = (sys.version_info >= (3, 0))
|
||||
|
||||
def ensure_unicode(text):
|
||||
u"""helper to ensure that text passed to WriteConsoleW is unicode"""
|
||||
if isinstance(text, bytes):
|
||||
@@ -37,3 +39,9 @@ def ensure_str(text):
|
||||
except (LookupError, TypeError):
|
||||
return text.encode(u"ascii", u"replace")
|
||||
return text
|
||||
|
||||
def biter(text):
|
||||
if PY3 and isinstance(text, bytes):
|
||||
return (s.to_bytes(1, 'big') for s in text)
|
||||
else:
|
||||
return iter(text)
|
||||
|
||||
Reference in New Issue
Block a user