[ python-Bugs-1674223 ] Unicode xmlcharrefreplace produces backslash not xml style.

SourceForge.net noreply at sourceforge.net
Mon Mar 5 18:54:51 CET 2007


Bugs item #1674223, was opened at 2007-03-05 18:11
Message generated for change (Comment added) made by doerwalter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1674223&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: Python 2.5
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Stanley Sokolow (odontomatix)
Assigned to: Nobody/Anonymous (nobody)
Summary: Unicode xmlcharrefreplace produces backslash not xml style.

Initial Comment:
In Python 2.4.2 and 2.5, and maybe other versions too, the unicode string encoder for producing xml style unicode output (example, © for copyright symbol) produces the wrong style -- it produces backslash encoding (\xa9 for same copyright unicode character).

Example at Python shell:
u'\u2122'.encode('unicode_escape','xmlcharrefreplace')
should produce: ™
but it produces \u2122

The same happens when it is used in a program.  The print output of the encoded unicode contains backslash encodings as though the method 'backslashreplace' had been used.



----------------------------------------------------------------------

>Comment By: Walter Dörwald (doerwalter)
Date: 2007-03-05 18:54

Message:
Logged In: YES 
user_id=89016
Originator: NO

u'\u2122'.encode('unicode_escape','xmlcharrefreplace') produces \u2122
because that's the way the unicode_escape codec outputs unicode codepoints.
For unicode_escape the xmlcharrefreplace error handler never kicks in. If
you want the error handler to kick in, you have to use an encoding that
doesn't support the character you want to encode. The best candidate is
probably ascii:

>>> u"\u2122".encode("ascii", "xmlcharrefreplace")
>>> '™'


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1674223&group_id=5470


More information about the Python-bugs-list mailing list