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.

作者 effbot
收信人 Neil Muller, effbot, hodgestar, pitrou
日期 2009-06-21.21:42:02
SpamBayes Score 4.318773e-11
Marked as misclassified
Message-id <1245620524.03.0.89226197284.issue6233@psf.upfronthosting.co.za>
In-reply-to
内容
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)
历史
日期 用户 动作 参数
2009-06-21 21:42:04effbot修改recipients: + effbot, pitrou, hodgestar, Neil Muller
2009-06-21 21:42:04effbot修改messageid: <1245620524.03.0.89226197284.issue6233@psf.upfronthosting.co.za>
2009-06-21 21:42:03effbot链接issue6233 messages
2009-06-21 21:42:02effbot创建