Skip to content

Commit

Permalink
Merge pull request #8278 from tiran/py3_celementtree
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored May 30, 2020
2 parents 7ed5e12 + a731989 commit d01bfcf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/8278.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vendored htmlib5 no longer imports deprecated xml.etree.cElementTree on Python 3.
5 changes: 3 additions & 2 deletions src/pip/_vendor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ Modifications
* ``setuptools`` is completely stripped to only keep ``pkg_resources``
* ``pkg_resources`` has been modified to import its dependencies from ``pip._vendor``
* ``packaging`` has been modified to import its dependencies from ``pip._vendor``
* ``html5lib`` has been modified to import six from ``pip._vendor`` and
to prefer importing from ``collections.abc`` instead of ``collections``.
* ``html5lib`` has been modified to import six from ``pip._vendor``, to prefer
importing from ``collections.abc`` instead of ``collections`` and does not import
``xml.etree.cElementTree`` on Python 3.
* ``CacheControl`` has been modified to import its dependencies from ``pip._vendor``
* ``requests`` has been modified to import its other dependencies from ``pip._vendor``
and to *not* load ``simplejson`` (all platforms) and ``pyopenssl`` (Windows).
Expand Down
11 changes: 7 additions & 4 deletions src/pip/_vendor/html5lib/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

from types import ModuleType

from pip._vendor.six import text_type
from pip._vendor.six import text_type, PY3

try:
import xml.etree.cElementTree as default_etree
except ImportError:
if PY3:
import xml.etree.ElementTree as default_etree
else:
try:
import xml.etree.cElementTree as default_etree
except ImportError:
import xml.etree.ElementTree as default_etree


__all__ = ["default_etree", "MethodDispatcher", "isSurrogatePair",
Expand Down
24 changes: 24 additions & 0 deletions tools/automation/vendoring/patches/html5lib.patch
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,28 @@ index dcfac220..d8b53004 100644
+ from collections import MutableMapping
from xml.dom import minidom, Node
import weakref

diff --git a/src/pip/_vendor/html5lib/_utils.py b/src/pip/_vendor/html5lib/_utils.py
index 0703afb3..96eb17b2 100644
--- a/src/pip/_vendor/html5lib/_utils.py
+++ b/src/pip/_vendor/html5lib/_utils.py
@@ -2,12 +2,15 @@ from __future__ import absolute_import, division, unicode_literals

from types import ModuleType

-from pip._vendor.six import text_type
+from pip._vendor.six import text_type, PY3

-try:
- import xml.etree.cElementTree as default_etree
-except ImportError:
+if PY3:
import xml.etree.ElementTree as default_etree
+else:
+ try:
+ import xml.etree.cElementTree as default_etree
+ except ImportError:
+ import xml.etree.ElementTree as default_etree


__all__ = ["default_etree", "MethodDispatcher", "isSurrogatePair",

0 comments on commit d01bfcf

Please sign in to comment.