|
104 | 104 | from . import ElementPath |
105 | 105 |
|
106 | 106 |
|
| 107 | +# The white space characters of the XML specification (see XML 1.0, 2.3). |
| 108 | +_XML_WHITESPACE = " \t\r\n" |
| 109 | + |
107 | 110 | class ParseError(SyntaxError): |
108 | 111 | """An error when parsing an XML document. |
109 | 112 |
|
@@ -1194,17 +1197,17 @@ def _indent_children(elem, level): |
1194 | 1197 | child_indentation = indentations[level] + space |
1195 | 1198 | indentations.append(child_indentation) |
1196 | 1199 |
|
1197 | | - if not elem.text or not elem.text.strip(): |
| 1200 | + if not elem.text or not elem.text.strip(_XML_WHITESPACE): |
1198 | 1201 | elem.text = child_indentation |
1199 | 1202 |
|
1200 | 1203 | for child in elem: |
1201 | 1204 | if len(child): |
1202 | 1205 | _indent_children(child, child_level) |
1203 | | - if not child.tail or not child.tail.strip(): |
| 1206 | + if not child.tail or not child.tail.strip(_XML_WHITESPACE): |
1204 | 1207 | child.tail = child_indentation |
1205 | 1208 |
|
1206 | 1209 | # Dedent after the last child by overwriting the previous indentation. |
1207 | | - if not child.tail.strip(): |
| 1210 | + if not child.tail.strip(_XML_WHITESPACE): |
1208 | 1211 | child.tail = indentations[level] |
1209 | 1212 |
|
1210 | 1213 | _indent_children(tree, 0) |
@@ -1705,7 +1708,7 @@ def _default(self, text): |
1705 | 1708 | if prefix == ">": |
1706 | 1709 | self._doctype = None |
1707 | 1710 | return |
1708 | | - text = text.strip() |
| 1711 | + text = text.strip(_XML_WHITESPACE) |
1709 | 1712 | if not text: |
1710 | 1713 | return |
1711 | 1714 | self._doctype.append(text) |
@@ -1921,7 +1924,7 @@ def _flush(self, _join_text=''.join): |
1921 | 1924 | data = _join_text(self._data) |
1922 | 1925 | del self._data[:] |
1923 | 1926 | if self._strip_text and not self._preserve_space[-1]: |
1924 | | - data = data.strip() |
| 1927 | + data = data.strip(_XML_WHITESPACE) |
1925 | 1928 | if self._pending_start is not None: |
1926 | 1929 | args, self._pending_start = self._pending_start, None |
1927 | 1930 | qname_text = data if data and _looks_like_prefix_name(data) else None |
|
0 commit comments