escape: use xml.etree.ElementTree._escape_attrib to avoid duplication
This commit is contained in:
parent
1c3bfd949b
commit
b6e53c7b1b
1 changed files with 5 additions and 18 deletions
|
@ -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("\"", """)
|
||||
text = _escape_attrib(text, encoding)
|
||||
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)
|
||||
return text
|
||||
|
|
Loading…
Reference in a new issue