Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use cElementTree on Python 3 #8278

Merged
merged 5 commits into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",