aboutsummaryrefslogtreecommitdiff
path: root/Lib/xml
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-09-11 23:23:24 -0700
committerRaymond Hettinger <python@rcn.com>2016-09-11 23:23:24 -0700
commit11fa3ffcb11caf628435670b213f9bc2e3ba4f67 (patch)
treea147fd06c6803f5ea86d4c419a99183ea3bdd14c /Lib/xml
parentMerge 3.5 - Issue #15308: Add 'interrupt execution' (^C) to Shell menu. (diff)
parentIssue #17582: xml.etree.ElementTree nows preserves whitespaces in attributes (diff)
downloadcpython-11fa3ffcb11caf628435670b213f9bc2e3ba4f67.tar.gz
cpython-11fa3ffcb11caf628435670b213f9bc2e3ba4f67.tar.bz2
cpython-11fa3ffcb11caf628435670b213f9bc2e3ba4f67.zip
merge
Diffstat (limited to 'Lib/xml')
-rw-r--r--Lib/xml/etree/ElementTree.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 4b0c661e317..735405681ff 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1084,8 +1084,19 @@ def _escape_attrib(text):
text = text.replace(">", "&gt;")
if "\"" in text:
text = text.replace("\"", "&quot;")
+ # The following business with carriage returns is to satisfy
+ # Section 2.11 of the XML specification, stating that
+ # CR or CR LN should be replaced with just LN
+ # http://www.w3.org/TR/REC-xml/#sec-line-ends
+ if "\r\n" in text:
+ text = text.replace("\r\n", "\n")
+ if "\r" in text:
+ text = text.replace("\r", "\n")
+ #The following four lines are issue 17582
if "\n" in text:
text = text.replace("\n", "&#10;")
+ if "\t" in text:
+ text = text.replace("\t", "&#09;")
return text
except (TypeError, AttributeError):
_raise_serialization_error(text)