Message36773
This patch adds unicode error handling callbacks to the
encode functionality. With this patch it's possible to
not only pass 'strict', 'ignore' or 'replace' as the
errors argument to encode, but also a callable
function, that will be called with the encoding name,
the original unicode object and the position of the
unencodable character. The callback must return a
replacement unicode object that will be encoded instead
of the original character.
For example replacing unencodable characters with XML
character references can be done in the following way.
u"aäoöuüß".encode(
"ascii",
lambda enc, uni, pos: u"&#x%x;" % ord(uni[pos])
)
|
|
Date |
User |
Action |
Args |
2007-08-23 15:06:03 | admin | link | issue432401 messages |
2007-08-23 15:06:03 | admin | create | |
|