summaryrefslogtreecommitdiffstats
path: root/Lib/xml/dom
diff options
context:
space:
mode:
authorStephen Morton <git@tungol.org>2025-01-07 10:40:41 (GMT)
committerGitHub <noreply@github.com>2025-01-07 10:40:41 (GMT)
commit6ea04da27036eaa69d65150148bb8c537d9beacf (patch)
tree3ad7437e402c7129d79abf15f33e0abab3e56a21 /Lib/xml/dom
parent145276a072ae058bac42ee43a4235cd4eda2726b (diff)
downloadcpython-6ea04da27036eaa69d65150148bb8c537d9beacf.zip
cpython-6ea04da27036eaa69d65150148bb8c537d9beacf.tar.gz
cpython-6ea04da27036eaa69d65150148bb8c537d9beacf.tar.bz2
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.
Diffstat (limited to 'Lib/xml/dom')
-rw-r--r--Lib/xml/dom/xmlbuilder.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/xml/dom/xmlbuilder.py b/Lib/xml/dom/xmlbuilder.py
index 8a20026..a885262 100644
--- a/Lib/xml/dom/xmlbuilder.py
+++ b/Lib/xml/dom/xmlbuilder.py
@@ -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):