Skip to content

Commit 136589d

Browse files
committed
Remove six dependency from html5lib (#618)
This way lies madness, but at least we don't have a six dependency anymore. The way this work is that we vendored html5lib 1.1, but then this applies a 01_html5lib_six.patch to that which changes imports from six to import from bleach.six_shim. This updates the vendor management code and vendorverify to install html5lib 1.1 and then apply the patch and then compare with what's in the tree. If we end up applying further patches in the future, we can use this model to do that.
1 parent cf53a47 commit 136589d

16 files changed

+195
-18
lines changed

bleach/_vendor/01_html5lib_six.patch

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
diff --git bleach/_vendor/html5lib/_inputstream.py bleach/_vendor/html5lib/_inputstream.py
2+
index 0207dd2..0976251 100644
3+
--- bleach/_vendor/html5lib/_inputstream.py
4+
+++ bleach/_vendor/html5lib/_inputstream.py
5+
@@ -1,7 +1,7 @@
6+
from __future__ import absolute_import, division, unicode_literals
7+
8+
-from six import text_type
9+
-from six.moves import http_client, urllib
10+
+from bleach.six_shim import text_type
11+
+from bleach.six_shim import http_client, urllib
12+
13+
import codecs
14+
import re
15+
diff --git bleach/_vendor/html5lib/_tokenizer.py bleach/_vendor/html5lib/_tokenizer.py
16+
index 4748a19..d884801 100644
17+
--- bleach/_vendor/html5lib/_tokenizer.py
18+
+++ bleach/_vendor/html5lib/_tokenizer.py
19+
@@ -1,6 +1,6 @@
20+
from __future__ import absolute_import, division, unicode_literals
21+
22+
-from six import unichr as chr
23+
+from bleach.six_shim import unichr as chr
24+
25+
from collections import deque, OrderedDict
26+
from sys import version_info
27+
diff --git bleach/_vendor/html5lib/_trie/py.py bleach/_vendor/html5lib/_trie/py.py
28+
index c2ba3da..56f66bd 100644
29+
--- bleach/_vendor/html5lib/_trie/py.py
30+
+++ bleach/_vendor/html5lib/_trie/py.py
31+
@@ -1,5 +1,5 @@
32+
from __future__ import absolute_import, division, unicode_literals
33+
-from six import text_type
34+
+from bleach.six_shim import text_type
35+
36+
from bisect import bisect_left
37+
38+
diff --git bleach/_vendor/html5lib/_utils.py bleach/_vendor/html5lib/_utils.py
39+
index 9ea5794..635bb02 100644
40+
--- bleach/_vendor/html5lib/_utils.py
41+
+++ bleach/_vendor/html5lib/_utils.py
42+
@@ -7,7 +7,7 @@ try:
43+
except ImportError:
44+
from collections import Mapping
45+
46+
-from six import text_type, PY3
47+
+from bleach.six_shim import text_type, PY3
48+
49+
if PY3:
50+
import xml.etree.ElementTree as default_etree
51+
diff --git bleach/_vendor/html5lib/filters/lint.py bleach/_vendor/html5lib/filters/lint.py
52+
index acd4d7a..1340d97 100644
53+
--- bleach/_vendor/html5lib/filters/lint.py
54+
+++ bleach/_vendor/html5lib/filters/lint.py
55+
@@ -1,6 +1,6 @@
56+
from __future__ import absolute_import, division, unicode_literals
57+
58+
-from six import text_type
59+
+from bleach.six_shim import text_type
60+
61+
from . import base
62+
from ..constants import namespaces, voidElements
63+
diff --git bleach/_vendor/html5lib/filters/sanitizer.py bleach/_vendor/html5lib/filters/sanitizer.py
64+
index 70ef906..5c31e97 100644
65+
--- bleach/_vendor/html5lib/filters/sanitizer.py
66+
+++ bleach/_vendor/html5lib/filters/sanitizer.py
67+
@@ -12,7 +12,7 @@ import re
68+
import warnings
69+
from xml.sax.saxutils import escape, unescape
70+
71+
-from six.moves import urllib_parse as urlparse
72+
+from bleach.six_shim import urllib_parse as urlparse
73+
74+
from . import base
75+
from ..constants import namespaces, prefixes
76+
diff --git bleach/_vendor/html5lib/html5parser.py bleach/_vendor/html5lib/html5parser.py
77+
index 74d829d..5427b7d 100644
78+
--- bleach/_vendor/html5lib/html5parser.py
79+
+++ bleach/_vendor/html5lib/html5parser.py
80+
@@ -1,5 +1,5 @@
81+
from __future__ import absolute_import, division, unicode_literals
82+
-from six import with_metaclass, viewkeys
83+
+from bleach.six_shim import viewkeys
84+
85+
import types
86+
87+
@@ -423,7 +423,7 @@ def getPhases(debug):
88+
return type
89+
90+
# pylint:disable=unused-argument
91+
- class Phase(with_metaclass(getMetaclass(debug, log))):
92+
+ class Phase(metaclass=getMetaclass(debug, log)):
93+
"""Base class for helper object that implements each phase of processing
94+
"""
95+
__slots__ = ("parser", "tree", "__startTagCache", "__endTagCache")
96+
diff --git bleach/_vendor/html5lib/serializer.py bleach/_vendor/html5lib/serializer.py
97+
index c66df68..5666f49 100644
98+
--- bleach/_vendor/html5lib/serializer.py
99+
+++ bleach/_vendor/html5lib/serializer.py
100+
@@ -1,5 +1,5 @@
101+
from __future__ import absolute_import, division, unicode_literals
102+
-from six import text_type
103+
+from bleach.six_shim import text_type
104+
105+
import re
106+
107+
diff --git bleach/_vendor/html5lib/treebuilders/base.py bleach/_vendor/html5lib/treebuilders/base.py
108+
index e4a3d71..2869da0 100644
109+
--- bleach/_vendor/html5lib/treebuilders/base.py
110+
+++ bleach/_vendor/html5lib/treebuilders/base.py
111+
@@ -1,5 +1,5 @@
112+
from __future__ import absolute_import, division, unicode_literals
113+
-from six import text_type
114+
+from bleach.six_shim import text_type
115+
116+
from ..constants import scopingElements, tableInsertModeElements, namespaces
117+
118+
diff --git bleach/_vendor/html5lib/treebuilders/etree.py bleach/_vendor/html5lib/treebuilders/etree.py
119+
index 086bed4..5ccfc4d 100644
120+
--- bleach/_vendor/html5lib/treebuilders/etree.py
121+
+++ bleach/_vendor/html5lib/treebuilders/etree.py
122+
@@ -1,7 +1,7 @@
123+
from __future__ import absolute_import, division, unicode_literals
124+
# pylint:disable=protected-access
125+
126+
-from six import text_type
127+
+from bleach.six_shim import text_type
128+
129+
import re
130+
131+
diff --git bleach/_vendor/html5lib/treebuilders/etree_lxml.py bleach/_vendor/html5lib/treebuilders/etree_lxml.py
132+
index e73de61..f462232 100644
133+
--- bleach/_vendor/html5lib/treebuilders/etree_lxml.py
134+
+++ bleach/_vendor/html5lib/treebuilders/etree_lxml.py
135+
@@ -28,7 +28,7 @@ from . import etree as etree_builders
136+
from .. import _ihatexml
137+
138+
import lxml.etree as etree
139+
-from six import PY3, binary_type
140+
+from bleach.six_shim import PY3, binary_type
141+
142+
143+
fullTree = True
144+
diff --git bleach/_vendor/html5lib/treewalkers/etree.py bleach/_vendor/html5lib/treewalkers/etree.py
145+
index 4465337..a9d9450 100644
146+
--- bleach/_vendor/html5lib/treewalkers/etree.py
147+
+++ bleach/_vendor/html5lib/treewalkers/etree.py
148+
@@ -3,7 +3,7 @@ from __future__ import absolute_import, division, unicode_literals
149+
from collections import OrderedDict
150+
import re
151+
152+
-from six import string_types
153+
+from bleach.six_shim import string_types
154+
155+
from . import base
156+
from .._utils import moduleFactoryFactory
157+
diff --git bleach/_vendor/html5lib/treewalkers/etree_lxml.py bleach/_vendor/html5lib/treewalkers/etree_lxml.py
158+
index a614ac5..ef42163 100644
159+
--- bleach/_vendor/html5lib/treewalkers/etree_lxml.py
160+
+++ bleach/_vendor/html5lib/treewalkers/etree_lxml.py
161+
@@ -1,5 +1,5 @@
162+
from __future__ import absolute_import, division, unicode_literals
163+
-from six import text_type
164+
+from bleach.six_shim import text_type
165+
166+
from collections import OrderedDict
167+

bleach/_vendor/html5lib/_inputstream.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3-
from six import text_type
4-
from six.moves import http_client, urllib
3+
from bleach.six_shim import text_type
4+
from bleach.six_shim import http_client, urllib
55

66
import codecs
77
import re

bleach/_vendor/html5lib/_tokenizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3-
from six import unichr as chr
3+
from bleach.six_shim import unichr as chr
44

55
from collections import deque, OrderedDict
66
from sys import version_info

bleach/_vendor/html5lib/_trie/py.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
2-
from six import text_type
2+
from bleach.six_shim import text_type
33

44
from bisect import bisect_left
55

bleach/_vendor/html5lib/_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
except ImportError:
88
from collections import Mapping
99

10-
from six import text_type, PY3
10+
from bleach.six_shim import text_type, PY3
1111

1212
if PY3:
1313
import xml.etree.ElementTree as default_etree

bleach/_vendor/html5lib/filters/lint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import absolute_import, division, unicode_literals
22

3-
from six import text_type
3+
from bleach.six_shim import text_type
44

55
from . import base
66
from ..constants import namespaces, voidElements

bleach/_vendor/html5lib/filters/sanitizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import warnings
1313
from xml.sax.saxutils import escape, unescape
1414

15-
from six.moves import urllib_parse as urlparse
15+
from bleach.six_shim import urllib_parse as urlparse
1616

1717
from . import base
1818
from ..constants import namespaces, prefixes

bleach/_vendor/html5lib/html5parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
2-
from six import with_metaclass, viewkeys
2+
from bleach.six_shim import viewkeys
33

44
import types
55

@@ -423,7 +423,7 @@ def getMetaclass(use_metaclass, metaclass_func):
423423
return type
424424

425425
# pylint:disable=unused-argument
426-
class Phase(with_metaclass(getMetaclass(debug, log))):
426+
class Phase(metaclass=getMetaclass(debug, log)):
427427
"""Base class for helper object that implements each phase of processing
428428
"""
429429
__slots__ = ("parser", "tree", "__startTagCache", "__endTagCache")

bleach/_vendor/html5lib/serializer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
2-
from six import text_type
2+
from bleach.six_shim import text_type
33

44
import re
55

bleach/_vendor/html5lib/treebuilders/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
2-
from six import text_type
2+
from bleach.six_shim import text_type
33

44
from ..constants import scopingElements, tableInsertModeElements, namespaces
55

bleach/_vendor/html5lib/treebuilders/etree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import absolute_import, division, unicode_literals
22
# pylint:disable=protected-access
33

4-
from six import text_type
4+
from bleach.six_shim import text_type
55

66
import re
77

bleach/_vendor/html5lib/treebuilders/etree_lxml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .. import _ihatexml
2929

3030
import lxml.etree as etree
31-
from six import PY3, binary_type
31+
from bleach.six_shim import PY3, binary_type
3232

3333

3434
fullTree = True

bleach/_vendor/html5lib/treewalkers/etree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections import OrderedDict
44
import re
55

6-
from six import string_types
6+
from bleach.six_shim import string_types
77

88
from . import base
99
from .._utils import moduleFactoryFactory

bleach/_vendor/html5lib/treewalkers/etree_lxml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import, division, unicode_literals
2-
from six import text_type
2+
from bleach.six_shim import text_type
33

44
from collections import OrderedDict
55

bleach/_vendor/vendor_install.sh

+4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ set -o pipefail
77
BLEACH_VENDOR_DIR=${BLEACH_VENDOR_DIR:-"."}
88
DEST=${DEST:-"."}
99

10+
# Install with no dependencies
1011
pip install --no-binary all --no-compile --no-deps -r "${BLEACH_VENDOR_DIR}/vendor.txt" --target "${DEST}"
1112

13+
# Apply patches
14+
(cd "${DEST}" && patch -p2 < 01_html5lib_six.patch)
15+
1216
# install Python 3.6.14 urllib.urlparse for #536
1317
curl --proto '=https' --tlsv1.2 -o "${DEST}/parse.py" https://raw.githubusercontent.com/python/cpython/v3.6.14/Lib/urllib/parse.py
1418
(cd "${DEST}" && sha256sum parse.py > parse.py.SHA256SUM)

scripts/vendor_verify.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ set -e
55
# Install vendored packages into /tmp and then compare with what's in
66
# bleach/_vendor/.
77

8-
DEST=/tmp/vendor-test
8+
export DEST=/tmp/vendor-test
9+
export BLEACH_VENDOR_DIR=bleach/_vendor
910

1011
if [[ -e "${DEST}" ]]; then
1112
echo "${DEST} exists. Please remove."
@@ -14,11 +15,16 @@ fi
1415

1516
mkdir "${DEST}"
1617

17-
# Get versions of pip and python
18+
# Get diagnostic information
1819
pip --version
20+
echo "DEST: ${DEST}"
21+
echo "BLEACH_VENDOR_DIR: ${BLEACH_VENDOR_DIR}"
22+
23+
# Copy patch files to dest directory
24+
cp bleach/_vendor/*.patch "${DEST}"
1925

2026
# Install vendored dependencies into temp directory
21-
BLEACH_VENDOR_DIR=bleach/_vendor DEST="${DEST}" bleach/_vendor/vendor_install.sh
27+
bleach/_vendor/vendor_install.sh
2228

2329
# Diff contents of temp directory and bleach/_vendor/ excluding vendoring
2430
# infrastructure

0 commit comments

Comments
 (0)