|
101 | 101 | from . import ElementPath |
102 | 102 |
|
103 | 103 |
|
| 104 | +# The white space characters of the XML specification (see XML 1.0, 2.3). |
| 105 | +_XML_WHITESPACE = " \t\r\n" |
| 106 | + |
104 | 107 | class ParseError(SyntaxError): |
105 | 108 | """An error when parsing an XML document. |
106 | 109 |
|
@@ -1209,17 +1212,17 @@ def _indent_children(elem, level): |
1209 | 1212 | child_indentation = indentations[level] + space |
1210 | 1213 | indentations.append(child_indentation) |
1211 | 1214 |
|
1212 | | - if not elem.text or not elem.text.strip(): |
| 1215 | + if not elem.text or not elem.text.strip(_XML_WHITESPACE): |
1213 | 1216 | elem.text = child_indentation |
1214 | 1217 |
|
1215 | 1218 | for child in elem: |
1216 | 1219 | if len(child): |
1217 | 1220 | _indent_children(child, child_level) |
1218 | | - if not child.tail or not child.tail.strip(): |
| 1221 | + if not child.tail or not child.tail.strip(_XML_WHITESPACE): |
1219 | 1222 | child.tail = child_indentation |
1220 | 1223 |
|
1221 | 1224 | # Dedent after the last child by overwriting the previous indentation. |
1222 | | - if not child.tail.strip(): |
| 1225 | + if not child.tail.strip(_XML_WHITESPACE): |
1223 | 1226 | child.tail = indentations[level] |
1224 | 1227 |
|
1225 | 1228 | _indent_children(tree, 0) |
@@ -1724,7 +1727,7 @@ def _default(self, text): |
1724 | 1727 | if prefix == ">": |
1725 | 1728 | self._doctype = None |
1726 | 1729 | return |
1727 | | - text = text.strip() |
| 1730 | + text = text.strip(_XML_WHITESPACE) |
1728 | 1731 | if not text: |
1729 | 1732 | return |
1730 | 1733 | self._doctype.append(text) |
@@ -1940,7 +1943,7 @@ def _flush(self, _join_text=''.join): |
1940 | 1943 | data = _join_text(self._data) |
1941 | 1944 | del self._data[:] |
1942 | 1945 | if self._strip_text and not self._preserve_space[-1]: |
1943 | | - data = data.strip() |
| 1946 | + data = data.strip(_XML_WHITESPACE) |
1944 | 1947 | if self._pending_start is not None: |
1945 | 1948 | args, self._pending_start = self._pending_start, None |
1946 | 1949 | qname_text = data if data and _looks_like_prefix_name(data) else None |
|
0 commit comments