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.
This commit is contained in:
Mika Bostrom 2010-01-24 22:17:03 +02:00 committed by Gerko de Roo
parent 2c7287c351
commit b58edb53ae

View File

@ -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