From 85c9070ec8bc418237af83eb9adad8194e7cbcaa Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Sun, 24 Jan 2010 22:17:03 +0200 Subject: [PATCH] Write charmap-related errors directly to stderr This change is needed to skip a nasty behaviour: if the string triggered a decoding error, it will trigger one *AGAIN* if the string is printed to console. By writing directly to sys.stderr we skip the locale/conversion issues and get the troublesome string directly in a file where it is stored as a raw sequence of octets. --- pyfpdb/Charset.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index 16c236b6..86d33418 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -15,6 +15,9 @@ #In the "official" distribution you can find the license in #agpl-3.0.txt in the docs folder of the package. +# Error logging +import sys + # String manipulation import codecs @@ -37,7 +40,7 @@ def to_utf8(s): _out = unicode(s, Configuration.LOCALE_ENCODING).encode('utf-8') return _out except UnicodeDecodeError: - print 'Could not convert: "%s"' % s + sys.stderr.write('Could not convert: "%s"\n' % s) raise def to_db_utf8(s): @@ -47,7 +50,7 @@ def to_db_utf8(s): (_out, _len) = encoder_to_utf.encode(unicode(s)) return _out except UnicodeDecodeError: - print 'Could not convert: "%s"' % s + sys.stderr.write('Could not convert: "%s"\n' % s) raise def to_gui(s): @@ -57,6 +60,6 @@ def to_gui(s): (_out, _len) = encoder_to_sys.encode(s) return _out except UnicodeDecodeError: - print 'Could not convert: "%s"' % s + sys.stderr.write('Could not convert: "%s"\n' % s) raise