From ef26c05181f2f203ad5990d157f7367341d221ee Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Sat, 6 Feb 2010 23:12:11 +0000 Subject: [PATCH] be more tolerant of errors when translating for gui, add encode exception handlers --- pyfpdb/Charset.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index ea19d32e..9c49f505 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -42,6 +42,9 @@ def to_utf8(s): except UnicodeDecodeError: sys.stderr.write('Could not convert: "%s"\n' % s) raise + except UnicodeEncodeError: + sys.stderr.write('Could not encode: "%s"\n' % s) + raise except TypeError: # TypeError is raised when we give unicode() an already encoded string return s @@ -54,13 +57,21 @@ def to_db_utf8(s): except UnicodeDecodeError: sys.stderr.write('Could not convert: "%s"\n' % s) raise + except UnicodeEncodeError: + sys.stderr.write('Could not encode: "%s"\n' % s) + raise def to_gui(s): if not_needed3: return s try: - (_out, _len) = encoder_to_sys.encode(s) + # we usually don't want to use 'replace' but this is only for displaying + # in the gui so it doesn't matter if names are missing an accent or two + (_out, _len) = encoder_to_sys.encode(s, 'replace') return _out except UnicodeDecodeError: sys.stderr.write('Could not convert: "%s"\n' % s) raise + except UnicodeEncodeError: + sys.stderr.write('Could not encode: "%s"\n' % s) + raise