mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-04 17:20:43 +08:00
pyreadline: all conversion is now handled by the ensure_unicode, ensure_str pair of functions
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
2007-11-09 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* make all conversion is done by ensure_unicode or ensure_str to ensure uniform
|
||||
handling of unicode issues.
|
||||
|
||||
2007-11-09 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* More fixes to unicode handling.
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
from ctypes import *
|
||||
from pyreadline.keysyms.winconstants import CF_TEXT, GHND
|
||||
from pyreadline.unicode_helper import ensure_unicode,ensure_text
|
||||
from pyreadline.unicode_helper import ensure_unicode,ensure_str
|
||||
|
||||
OpenClipboard = windll.user32.OpenClipboard
|
||||
EmptyClipboard = windll.user32.EmptyClipboard
|
||||
@@ -85,7 +85,7 @@ def GetClipboardText():
|
||||
return ensure_unicode(text)
|
||||
|
||||
def SetClipboardText(text):
|
||||
buffer = c_buffer(ensure_text(text))
|
||||
buffer = c_buffer(ensure_str(text))
|
||||
bufferSize = sizeof(buffer)
|
||||
hGlobalMem = GlobalAlloc(c_int(GHND), c_int(bufferSize))
|
||||
GlobalLock.restype = c_void_p
|
||||
|
||||
@@ -17,7 +17,7 @@ import sys
|
||||
import traceback
|
||||
import re
|
||||
from pyreadline.logger import log,log_sock
|
||||
from pyreadline.unicode_helper import ensure_unicode
|
||||
from pyreadline.unicode_helper import ensure_unicode,ensure_str
|
||||
import pyreadline.unicode_helper as unicode_helper
|
||||
try:
|
||||
from ctypes import *
|
||||
@@ -348,7 +348,7 @@ class Console(object):
|
||||
if attr is None:
|
||||
attr = self.attr
|
||||
self.SetConsoleTextAttribute(self.hout, attr)
|
||||
#self.WriteConsoleW(self.hout, ensure_text(chunk), len(chunk), byref(junk), None)
|
||||
#self.WriteConsoleW(self.hout, ensure_str(chunk), len(chunk), byref(junk), None)
|
||||
return n
|
||||
|
||||
def write_color(self, text, attr=None):
|
||||
@@ -675,7 +675,7 @@ def hook_wrapper_23(stdin, stdout, prompt):
|
||||
'''Wrap a Python readline so it behaves like GNU readline.'''
|
||||
try:
|
||||
# call the Python hook
|
||||
res = readline_hook(prompt).encode(unicode_helper.pyreadline_codepage)
|
||||
res = ensure_str(readline_hook(prompt))
|
||||
# make sure it returned the right sort of thing
|
||||
if res and not isinstance(res, str):
|
||||
raise TypeError, 'readline must return a string.'
|
||||
@@ -699,7 +699,7 @@ def hook_wrapper(prompt):
|
||||
'''Wrap a Python readline so it behaves like GNU readline.'''
|
||||
try:
|
||||
# call the Python hook
|
||||
res = readline_hook(prompt).encode(unicode_helper.pyreadline_codepage)
|
||||
res = ensure_str(readline_hook(prompt))
|
||||
# make sure it returned the right sort of thing
|
||||
if res and not isinstance(res, str):
|
||||
raise TypeError, 'readline must return a string.'
|
||||
|
||||
@@ -9,6 +9,7 @@ import re,operator,string,sys,os
|
||||
|
||||
#import wordmatcher
|
||||
#import pyreadline.clipboard as clipboard
|
||||
from pyreadline.unicode_helper import ensure_unicode,ensure_str
|
||||
if "pyreadline" in sys.modules:
|
||||
pyreadline= sys.modules["pyreadline"]
|
||||
else:
|
||||
@@ -66,7 +67,7 @@ class LineHistory(object):
|
||||
filename=self.history_filename
|
||||
try:
|
||||
for line in open(filename, 'r'):
|
||||
self.add_history(lineobj.ReadLineTextBuffer(line.rstrip().decode("utf8")))
|
||||
self.add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip())))
|
||||
except IOError:
|
||||
self.history = []
|
||||
self.history_cursor = 0
|
||||
@@ -77,7 +78,7 @@ class LineHistory(object):
|
||||
filename=self.history_filename
|
||||
fp = open(filename, 'wb')
|
||||
for line in self.history[-self.history_length:]:
|
||||
fp.write(line.get_line_text().encode("utf8"))
|
||||
fp.write(ensure_str(line.get_line_text()))
|
||||
fp.write('\n')
|
||||
fp.close()
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#*****************************************************************************
|
||||
|
||||
import socket
|
||||
from pyreadline.unicode_helper import ensure_text
|
||||
from pyreadline.unicode_helper import ensure_str
|
||||
_logfile=False
|
||||
|
||||
def start_log(on,filename):
|
||||
@@ -37,9 +37,9 @@ def log_sock(s,event_type=None):
|
||||
pass
|
||||
else:
|
||||
if event_type is None:
|
||||
logsocket.sendto(ensure_text(s),(host,port))
|
||||
logsocket.sendto(ensure_str(s),(host,port))
|
||||
elif event_type in show_event:
|
||||
logsocket.sendto(ensure_text(s),(host,port))
|
||||
logsocket.sendto(ensure_str(s),(host,port))
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ def ensure_unicode(text):
|
||||
return text.decode(pyreadline_codepage, "replace")
|
||||
return text
|
||||
|
||||
def ensure_text(text):
|
||||
def ensure_str(text):
|
||||
"""Convert unicode to str using pyreadline_codepage"""
|
||||
if isinstance(text, unicode):
|
||||
return text.encode(pyreadline_codepage, "replace")
|
||||
|
||||
Reference in New Issue
Block a user