This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author effbot
Recipients Neil Muller, effbot, hodgestar, pitrou
Date 2009-06-21.21:42:02
SpamBayes Score 4.318773e-11
Marked as misclassified No
Message-id <1245620524.03.0.89226197284.issue6233@psf.upfronthosting.co.za>
In-reply-to
Content
Did you look at the 1.3 alpha code base when you came up with this idea?  
Unfortunately, 1.3's _encode is used for a different purpose...

I don't have time to test it tonight, but I suspect that 1.3's 
escape_data/escape_attrib functions might work better under 3.X; they do 
the text.replace dance first, and then an explicit text.encode(encoding, 
"xmlcharrefreplace") at the end.  E.g.

def _escape_cdata(text, encoding):
    # escape character data
    try:
        # it's worth avoiding do-nothing calls for strings that are
        # shorter than 500 character, or so.  assume that's, by far,
        # the most common case in most applications.
        if "&" in text:
            text = text.replace("&", "&amp;")
        if "<" in text:
            text = text.replace("<", "&lt;")
        if ">" in text:
            text = text.replace(">", "&gt;")
        return text.encode(encoding, "xmlcharrefreplace")
    except (TypeError, AttributeError):
        _raise_serialization_error(text)
History
Date User Action Args
2009-06-21 21:42:04effbotsetrecipients: + effbot, pitrou, hodgestar, Neil Muller
2009-06-21 21:42:04effbotsetmessageid: <1245620524.03.0.89226197284.issue6233@psf.upfronthosting.co.za>
2009-06-21 21:42:03effbotlinkissue6233 messages
2009-06-21 21:42:02effbotcreate