[3.13] gh-128302: Fix bugs in xml.dom.xmlbuilder (GH-128284) by miss-islington · Pull Request #128582 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Lib/test/test_xml_dom_xmlbuilder.py
12 changes: 7 additions & 5 deletions Lib/xml/dom/xmlbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def parse(self, input):
options.filter = self.filter
options.errorHandler = self.errorHandler
fp = input.byteStream
if fp is None and options.systemId:
if fp is None and input.systemId:
import urllib.request
fp = urllib.request.urlopen(input.systemId)
return self._parse_bytestream(fp, options)
Expand Down Expand Up @@ -247,10 +247,12 @@ def _create_opener(self):

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


class DOMInputSource(object):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Allow :meth:`!xml.dom.xmlbuilder.DOMParser.parse` to correctly handle
:class:`!xml.dom.xmlbuilder.DOMInputSource` instances that only have a
:attr:`!systemId` attribute set.