mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-19 11:27:06 +08:00
pyreadline_trunk: quickfix for #228. Now defaults to ascii encoding if non-valid encoding is used.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2008-02-21 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* unicodehelper functions now defaults to ascii if supplied pyreadline_encoding is
|
||||
not a valid encoding. This is a brute force solution to ticket #228 it fixes
|
||||
immediate symptom but may not be the correct solution to the underlying problem.
|
||||
|
||||
2008-01-07 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* Reintroduced code to make pyreadline work with emacs. Not tested.
|
||||
Requested by Frank Wang.
|
||||
|
||||
@@ -17,11 +17,17 @@ except AttributeError: #This error occurs when pdb imports readline and d
|
||||
def ensure_unicode(text):
|
||||
"""helper to ensure that text passed to WriteConsoleW is unicode"""
|
||||
if isinstance(text, str):
|
||||
return text.decode(pyreadline_codepage, "replace")
|
||||
try:
|
||||
return text.decode(pyreadline_codepage, "replace")
|
||||
except (LookupError, TypeError):
|
||||
return text.decode("ascii", "replace")
|
||||
return text
|
||||
|
||||
def ensure_str(text):
|
||||
"""Convert unicode to str using pyreadline_codepage"""
|
||||
if isinstance(text, unicode):
|
||||
return text.encode(pyreadline_codepage, "replace")
|
||||
try:
|
||||
return text.encode(pyreadline_codepage, "replace")
|
||||
except (LookupError, TypeError):
|
||||
return text.encode("ascii", "replace")
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user