pyreadline_trunk: quickfix for #228. Now defaults to ascii encoding if non-valid encoding is used.

This commit is contained in:
jstenar
2008-02-21 17:43:36 +00:00
parent 82e2824891
commit 3ae839b018
2 changed files with 13 additions and 2 deletions
+5
View File
@@ -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.
+8 -2
View File
@@ -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