Skip to content

Commit 765d333

Browse files
vstinnerlarryhastings
authored andcommitted
bpo-34791: xml package obeys ignore env flags (GH-9544) (#11872)
The xml.sax and xml.dom.domreg modules now obey sys.flags.ignore_environment. Signed-off-by: Christian Heimes <[email protected]> (cherry picked from commit 223e501)
1 parent 4b42d57 commit 765d333

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
@@ -6,6 +6,8 @@
66
# should be published by posting to [email protected], and are
77
# subsequently recorded in this file.
88

9+
import sys
10+
911
well_known_implementations = {
1012
'minidom':'xml.dom.minidom',
1113
'4DOM': 'xml.dom.DOMImplementation',
@@ -55,7 +57,7 @@ def getDOMImplementation(name=None, features=()):
5557
return mod.getDOMImplementation()
5658
elif name:
5759
return registered[name]()
58-
elif "PYTHON_DOM" in os.environ:
60+
elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ:
5961
return getDOMImplementation(name = os.environ["PYTHON_DOM"])
6062

6163
# 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
@@ -56,7 +56,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()):
5656
import xml.sax.expatreader
5757

5858
import os, sys
59-
if "PY_SAX_PARSER" in os.environ:
59+
if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ:
6060
default_parser_list = os.environ["PY_SAX_PARSER"].split(",")
6161
del os
6262

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)