Jerry Chen <je...@3rdengine.com> added the comment: 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 try: text = text.replace("&", "&") text = text.replace("<", "<") text = text.replace(">", ">") if encoding: return text.encode(encoding, "xmlcharrefreplace") else: return text except (TypeError, AttributeError): _raise_serialization_error(text) ---------- Added file: http://bugs.python.org/file14361/issue6233-encode_cdata.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6233> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com