[3.12] gh-128302: Fix bugs in xml.dom.xmlbuilder (GH-128284) (#128583) · python/cpython@07a65cd · GitHub
Skip to content

Commit 07a65cd

Browse files
[3.12] gh-128302: Fix bugs in xml.dom.xmlbuilder (GH-128284) (#128583)
gh-128302: Fix bugs in xml.dom.xmlbuilder (GH-128284) * Allow DOMParser.parse() to correctly handle DOMInputSource instances that only have a systemId attribute set. * Fix DOMEntityResolver.resolveEntity(), which was broken by the Python 3.0 transition. * Add Lib/test/test_xml_dom_xmlbuilder.py with few tests. (cherry picked from commit 6ea04da) Co-authored-by: Stephen Morton <git@tungol.org>
1 parent b55c404 commit 07a65cd

4 files changed

Lines changed: 100 additions & 5 deletions

File tree

Lines changed: 88 additions & 0 deletions

Lib/xml/dom/xmlbuilder.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def parse(self, input):
189189
options.filter = self.filter
190190
options.errorHandler = self.errorHandler
191191
fp = input.byteStream
192-
if fp is None and options.systemId:
192+
if fp is None and input.systemId:
193193
import urllib.request
194194
fp = urllib.request.urlopen(input.systemId)
195195
return self._parse_bytestream(fp, options)
@@ -247,10 +247,12 @@ def _create_opener(self):
247247

248248
def _guess_media_encoding(self, source):
249249
info = source.byteStream.info()
250-
if "Content-Type" in info:
251-
for param in info.getplist():
252-
if param.startswith("charset="):
253-
return param.split("=", 1)[1].lower()
250+
# import email.message
251+
# assert isinstance(info, email.message.Message)
252+
charset = info.get_param('charset')
253+
if charset is not None:
254+
return charset.lower()
255+
return None
254256

255257

256258
class DOMInputSource(object):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Allow :meth:`!xml.dom.xmlbuilder.DOMParser.parse` to correctly handle
2+
:class:`!xml.dom.xmlbuilder.DOMInputSource` instances that only have a
3+
:attr:`!systemId` attribute set.
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)