codecs.register_error for "strict", unicode.encode() and str.decode()
I think I'm missing some piece here.
I'm trying to register a default error handler for handling exceptions
for preventing encoding/decoding errors (I know how this works and that
making this global is probably not a good practice, but I found this
strange behaviour while writing a proof of concept of how to let Python
work in a more forgiving way).
What I discovered is that register_error() for "strict" seems to work in
the way I expect for string decoding, not for unicode encoding.
That's what happens on Mac, Python 2.7.1 from Apple:
melquiades:tmp alan$ python minimal_test_encode.py
Traceback (most recent call last):
File "minimal_test_encode.py", line 10, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0' in
position 0: ordinal not in range(12
What piece am I missing? The doc at http://docs.python.org/library/codecs.html says " For
encoding /error_handler/ will be called with a UnicodeEncodeError
which contains information about the location of the error.", is there
any reason why the standard "strict" handler cannot be replaced?