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:
parent
33277ce68b
commit
85c9070ec8
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user