[Python-checkins] bpo-34791: xml package obeys ignore env flags (GH-9544) (GH-9547)
Victor Stinner
webhook-mailer at python.org
Fri Oct 19 19:09:38 EDT 2018
https://github.com/python/cpython/commit/2546ac8eeb56fc146adea9a03158440a9271714e
commit: 2546ac8eeb56fc146adea9a03158440a9271714e
branch: 2.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2018-10-20T01:09:35+02:00
summary:
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 <christian at python.org>
https://bugs.python.org/issue34791
(cherry picked from commit 223e501fb9c2b6ae21b96054e20c4c31d94a5d96)
Co-authored-by: Christian Heimes <christian at python.org>
files:
A Misc/NEWS.d/next/Security/2018-09-24-18-49-25.bpo-34791.78GmIG.rst
M Lib/xml/dom/domreg.py
M Lib/xml/sax/__init__.py
diff --git a/Lib/xml/dom/domreg.py b/Lib/xml/dom/domreg.py
index ec3acdf9c1dd..083528010663 100644
--- a/Lib/xml/dom/domreg.py
+++ b/Lib/xml/dom/domreg.py
@@ -8,6 +8,8 @@
# should be published by posting to xml-sig at python.org, and are
# subsequently recorded in this file.
+import sys
+
well_known_implementations = {
'minidom':'xml.dom.minidom',
'4DOM': 'xml.dom.DOMImplementation',
@@ -57,7 +59,7 @@ def getDOMImplementation(name = None, features = ()):
return mod.getDOMImplementation()
elif name:
return registered[name]()
- elif "PYTHON_DOM" in os.environ:
+ elif not sys.flags.ignore_environment and "PYTHON_DOM" in os.environ:
return getDOMImplementation(name = os.environ["PYTHON_DOM"])
# User did not specify a name, try implementations in arbitrary
diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py
index 005b66e38a8e..d2e33913c075 100644
--- a/Lib/xml/sax/__init__.py
+++ b/Lib/xml/sax/__init__.py
@@ -59,7 +59,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()):
import xml.sax.expatreader
import os, sys
-if "PY_SAX_PARSER" in os.environ:
+if not sys.flags.ignore_environment and "PY_SAX_PARSER" in os.environ:
default_parser_list = os.environ["PY_SAX_PARSER"].split(",")
del os
diff --git a/Misc/NEWS.d/next/Security/2018-09-24-18-49-25.bpo-34791.78GmIG.rst b/Misc/NEWS.d/next/Security/2018-09-24-18-49-25.bpo-34791.78GmIG.rst
new file mode 100644
index 000000000000..afb59f8cb0eb
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2018-09-24-18-49-25.bpo-34791.78GmIG.rst
@@ -0,0 +1,3 @@
+The xml.sax and xml.dom.domreg no longer use environment variables to
+override parser implementations when sys.flags.ignore_environment is set by
+-E or -I arguments.
More information about the Python-checkins
mailing list