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 jcsalterego
Recipients Neil Muller, effbot, hodgestar, jcsalterego, pitrou
Date 2009-06-24.23:56:03
SpamBayes Score 2.2285724e-09
Marked as misclassified No
Message-id <>
Thanks for the explanation -- looks like I was way off base on that one.

I took a look at the code you provided but it doesn't work as a drop-in
replacement for _escape_cdata, since that function returns a string
rather than bytes.

However taking your code, calling it _encode_cdata and then refactoring
all calls _encode(_escape_cdata(x), encoding) to _encode_cdata(x,
encoding) seems to do the trick and passes the tests.

Specific example:

- file.write(_encode(_escape_cdata(node.text), encoding))
+ file.write(_encode_cdata(node.text, encoding))

One minor modification is to return the string as is if encoding=None,
just like _encode:

def _encode_cdata(text, encoding):
    # escape character data
        text = text.replace("&", "&amp;")
        text = text.replace("<", "&lt;")
        text = text.replace(">", "&gt;")
        if encoding:
            return text.encode(encoding, "xmlcharrefreplace")
            return text
    except (TypeError, AttributeError):
Date User Action Args
2009-06-24 23:56:06jcsalteregosetrecipients: + jcsalterego, effbot, pitrou, hodgestar, Neil Muller
2009-06-24 23:56:05jcsalteregosetmessageid: <>
2009-06-24 23:56:04jcsalteregolinkissue6233 messages
2009-06-24 23:56:04jcsalteregocreate