From 3ae839b01842f08ce5ff7ae88db94498cd2609e9 Mon Sep 17 00:00:00 2001 From: jstenar <> Date: Thu, 21 Feb 2008 17:43:36 +0000 Subject: [PATCH] pyreadline_trunk: quickfix for #228. Now defaults to ascii encoding if non-valid encoding is used. --- doc/ChangeLog | 5 +++++ pyreadline/unicode_helper.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/ChangeLog b/doc/ChangeLog index 95bbae0..02be9a4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2008-02-21 Jörgen Stenarson + * 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 * Reintroduced code to make pyreadline work with emacs. Not tested. Requested by Frank Wang. diff --git a/pyreadline/unicode_helper.py b/pyreadline/unicode_helper.py index f33fa09..ebfa581 100644 --- a/pyreadline/unicode_helper.py +++ b/pyreadline/unicode_helper.py @@ -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