fixed: bytes iteration generate int literal instead of bytes literal

This commit is contained in:
shimizukawa
2011-04-23 17:25:23 +09:00
parent 10b2612e14
commit 2a03c0cab6
2 changed files with 11 additions and 3 deletions
+3 -3
View File
@@ -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
+8
View File
@@ -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)