[3.13] gh-128302: Fix bugs in xml.dom.xmlbuilder (GH-128284) (#128582)

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 6ea04da270)

Co-authored-by: Stephen Morton <git@tungol.org>
This commit is contained in:
Miss Islington (bot) 2025-01-11 12:31:04 +01:00 committed by GitHub
parent 65da5db28a
commit 3714fd07c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 100 additions and 5 deletions

View file

@ -189,7 +189,7 @@ class DOMBuilder:
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)
@ -247,10 +247,12 @@ class DOMEntityResolver(object):
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):