diff options
author | Jean-Philippe Caruana <jp@barreverte.fr> | 2013-07-31 11:01:34 +0200 |
---|---|---|
committer | Jean-Philippe Caruana <jp@barreverte.fr> | 2013-07-31 11:02:10 +0200 |
commit | b6e53c7b1be3691514cbf25e3de09d6742a4a587 (patch) | |
tree | 3942eaec7d76df8aad0091947995732c9e9dc3bd /sleekxmpp/xmlstream/tostring.py | |
parent | 1c3bfd949bc7903ee945694a8c807250d0e893ab (diff) | |
download | slixmpp-b6e53c7b1be3691514cbf25e3de09d6742a4a587.tar.gz slixmpp-b6e53c7b1be3691514cbf25e3de09d6742a4a587.tar.bz2 slixmpp-b6e53c7b1be3691514cbf25e3de09d6742a4a587.tar.xz slixmpp-b6e53c7b1be3691514cbf25e3de09d6742a4a587.zip |
escape: use xml.etree.ElementTree._escape_attrib to avoid duplication
Diffstat (limited to 'sleekxmpp/xmlstream/tostring.py')
-rw-r--r-- | sleekxmpp/xmlstream/tostring.py | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py index addd6989..4d7976b1 100644 --- a/sleekxmpp/xmlstream/tostring.py +++ b/sleekxmpp/xmlstream/tostring.py @@ -16,7 +16,7 @@ from __future__ import unicode_literals import sys -from xml.etree.ElementTree import _escape_cdata, _raise_serialization_error +from xml.etree.ElementTree import _escape_cdata, _escape_attrib if sys.version_info < (3, 0): import types @@ -146,20 +146,7 @@ def escape(text, use_cdata=False): if use_cdata: return _escape_cdata(text, encoding) - # copied from xml.etree.ElementTree._escape_attrib with "'" case - try: - if "&" in text: - text = text.replace("&", "&") - if "<" in text: - text = text.replace("<", "<") - if ">" in text: - text = text.replace(">", ">") - if "\"" in text: - text = text.replace("\"", """) - if "'" in text: - text = text.replace("'", "'") - if "\n" in text: - text = text.replace("\n", " ") - return text.encode(encoding, "xmlcharrefreplace") - except (TypeError, AttributeError): - _raise_serialization_error(text) + text = _escape_attrib(text, encoding) + if "'" in text: + text = text.replace("'", "'") + return text |