]> granicus.if.org Git - python/commitdiff
bpo-34791: xml package obeys ignore env flags (GH-9544) (#11871)
authorVictor Stinner <vstinner@redhat.com>
Tue, 26 Feb 2019 01:47:47 +0000 (02:47 +0100)
committerlarryhastings <larry@hastings.org>
Tue, 26 Feb 2019 01:47:47 +0000 (17:47 -0800)
The xml.sax and xml.dom.domreg modules now obey
sys.flags.ignore_environment.

Signed-off-by: Christian Heimes <christian@python.org>
(cherry picked from commit 223e501fb9c2b6ae21b96054e20c4c31d94a5d96)

Lib/xml/dom/domreg.py
Lib/xml/sax/__init__.py
Misc/NEWS.d/next/Security/2018-09-24-18-49-25.bpo-34791.78GmIG.rst [new file with mode: 0644]

index 8c3d901acb0bc4c3c06aa1f2b49655b08a19ada5..69c17eebb265daad3243e62018409d72942a93af 100644 (file)
@@ -6,6 +6,8 @@ registerDOMImplementation should be imported from xml.dom."""
 # should be published by posting to xml-sig@python.org, and are
 # subsequently recorded in this file.
 
+import sys
+
 well_known_implementations = {
     'minidom':'xml.dom.minidom',
     '4DOM': 'xml.dom.DOMImplementation',
@@ -55,7 +57,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
index ef67ae67a6bdd3167d8cf6de2664132122bffad9..13f6cf58d0d2f2b3198686370820d9eae3c5ddf5 100644 (file)
@@ -58,7 +58,7 @@ if _false:
     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 (file)
index 0000000..afb59f8
--- /dev/null
@@ -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.