Skip to content

Commit 2546ac8

Browse files
miss-islingtontiran
authored andcommitted
bpo-34791: xml package obeys ignore env flags (GH-9544) (GH-9547)
The xml.sax and xml.dom.domreg modules now obey sys.flags.ignore_environment. Signed-off-by: Christian Heimes <[email protected]> https://bugs.python.org/issue34791 (cherry picked from commit 223e501) Co-authored-by: Christian Heimes <[email protected]>
1 parent 5744a33 commit 2546ac8

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Lib/xml/dom/domreg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# should be published by posting to [email protected], and are
99
# subsequently recorded in this file.
1010

11+
import sys
12+
1113
well_known_implementations = {
1214
'minidom':'xml.dom.minidom',
1315
'4DOM': 'xml.dom.DOMImplementation',
@@ -57,7 +59,7 @@ def getDOMImplementation(name = None, features = ()):
5759
return mod.getDOMImplementation()
5860
elif name:
5961
return registered[name]()
60-
elif "PYTHON_DOM" in os.environ:
62+
elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ:
6163
return getDOMImplementation(name = os.environ["PYTHON_DOM"])
6264

6365
# User did not specify a name, try implementations in arbitrary

Lib/xml/sax/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()):
5959
import xml.sax.expatreader
6060

6161
import os, sys
62-
if "PY_SAX_PARSER" in os.environ:
62+
if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ:
6363
default_parser_list = os.environ["PY_SAX_PARSER"].split(",")
6464
del os
6565

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The xml.sax and xml.dom.domreg no longer use environment variables to
2+
override parser implementations when sys.flags.ignore_environment is set by
3+
-E or -I arguments.

0 commit comments

Comments
 (0)