Skip to content

Commit f90ee80

Browse files
committed
remove six
1 parent 29d3072 commit f90ee80

24 files changed

+47
-100
lines changed

debug-info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"maxsize": sys.maxsize
1212
}
1313

14-
search_modules = ["chardet", "genshi", "html5lib", "lxml", "six"]
14+
search_modules = ["chardet", "genshi", "html5lib", "lxml"]
1515
found_modules = []
1616

1717
for m in search_modules:

html5lib/_inputstream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
from six import text_type
3-
from six.moves import http_client, urllib
2+
import http.client
3+
import urllib.response
44

55
import codecs
66
import re
@@ -124,10 +124,10 @@ def _readFromBuffer(self, bytes):
124124
def HTMLInputStream(source, **kwargs):
125125
# Work around Python bug #20007: read(0) closes the connection.
126126
# http://bugs.python.org/issue20007
127-
if (isinstance(source, http_client.HTTPResponse) or
127+
if (isinstance(source, http.client.HTTPResponse) or
128128
# Also check for addinfourl wrapping HTTPResponse
129129
(isinstance(source, urllib.response.addbase) and
130-
isinstance(source.fp, http_client.HTTPResponse))):
130+
isinstance(source.fp, http.client.HTTPResponse))):
131131
isUnicode = False
132132
elif hasattr(source, "read"):
133133
isUnicode = isinstance(source.read(0), text_type)

html5lib/_tokenizer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11

2-
from six import unichr as chr
3-
42
from collections import deque, OrderedDict
53
from sys import version_info
64

html5lib/_trie/py.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
from six import text_type
2-
31
from bisect import bisect_left
42

53
from ._base import Trie as ABCTrie
64

75

86
class Trie(ABCTrie):
97
def __init__(self, data):
10-
if not all(isinstance(x, text_type) for x in data.keys()):
8+
if not all(isinstance(x, str) for x in data.keys()):
119
raise TypeError("All keys must be strings")
1210

1311
self._data = data

html5lib/_utils.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33

44
from collections.abc import Mapping
55

6-
from six import text_type, PY3
7-
8-
if PY3:
9-
import xml.etree.ElementTree as default_etree
10-
else:
11-
try:
12-
import xml.etree.ElementTree as default_etree
13-
except ImportError:
14-
import xml.etree.ElementTree as default_etree
6+
import xml.etree.ElementTree as default_etree
157

168

179
__all__ = ["default_etree", "MethodDispatcher", "isSurrogatePair",
@@ -27,10 +19,10 @@
2719
# escapes.
2820
try:
2921
_x = eval('"\\uD800"') # pylint:disable=eval-used
30-
if not isinstance(_x, text_type):
22+
if not isinstance(_x, str):
3123
# We need this with u"" because of http://bugs.jython.org/issue2039
3224
_x = eval('u"\\uD800"') # pylint:disable=eval-used
33-
assert isinstance(_x, text_type)
25+
assert isinstance(_x, str)
3426
except Exception:
3527
supports_lone_surrogates = False
3628
else:

html5lib/filters/lint.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11

2-
from six import text_type
3-
42
from . import base
53
from ..constants import namespaces, voidElements
64

@@ -32,9 +30,9 @@ def __iter__(self):
3230
if type in ("StartTag", "EmptyTag"):
3331
namespace = token["namespace"]
3432
name = token["name"]
35-
assert namespace is None or isinstance(namespace, text_type)
33+
assert namespace is None or isinstance(namespace, str)
3634
assert namespace != ""
37-
assert isinstance(name, text_type)
35+
assert isinstance(name, str)
3836
assert name != ""
3937
assert isinstance(token["data"], dict)
4038
if (not namespace or namespace == namespaces["html"]) and name in voidElements:
@@ -44,18 +42,18 @@ def __iter__(self):
4442
if type == "StartTag" and self.require_matching_tags:
4543
open_elements.append((namespace, name))
4644
for (namespace, name), value in token["data"].items():
47-
assert namespace is None or isinstance(namespace, text_type)
45+
assert namespace is None or isinstance(namespace, str)
4846
assert namespace != ""
49-
assert isinstance(name, text_type)
47+
assert isinstance(name, str)
5048
assert name != ""
51-
assert isinstance(value, text_type)
49+
assert isinstance(value, str)
5250

5351
elif type == "EndTag":
5452
namespace = token["namespace"]
5553
name = token["name"]
56-
assert namespace is None or isinstance(namespace, text_type)
54+
assert namespace is None or isinstance(namespace, str)
5755
assert namespace != ""
58-
assert isinstance(name, text_type)
56+
assert isinstance(name, str)
5957
assert name != ""
6058
if (not namespace or namespace == namespaces["html"]) and name in voidElements:
6159
assert False, "Void element reported as EndTag token: %(tag)s" % {"tag": name}
@@ -65,26 +63,26 @@ def __iter__(self):
6563

6664
elif type == "Comment":
6765
data = token["data"]
68-
assert isinstance(data, text_type)
66+
assert isinstance(data, str)
6967

7068
elif type in ("Characters", "SpaceCharacters"):
7169
data = token["data"]
72-
assert isinstance(data, text_type)
70+
assert isinstance(data, str)
7371
assert data != ""
7472
if type == "SpaceCharacters":
7573
assert data.strip(spaceCharacters) == ""
7674

7775
elif type == "Doctype":
7876
name = token["name"]
79-
assert name is None or isinstance(name, text_type)
80-
assert token["publicId"] is None or isinstance(name, text_type)
81-
assert token["systemId"] is None or isinstance(name, text_type)
77+
assert name is None or isinstance(name, str)
78+
assert token["publicId"] is None or isinstance(name, str)
79+
assert token["systemId"] is None or isinstance(name, str)
8280

8381
elif type == "Entity":
84-
assert isinstance(token["name"], text_type)
82+
assert isinstance(token["name"], str)
8583

8684
elif type == "SerializerError":
87-
assert isinstance(token["data"], text_type)
85+
assert isinstance(token["data"], str)
8886

8987
else:
9088
assert False, "Unknown token type: %(type)s" % {"type": type}

html5lib/filters/sanitizer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
import re
1111
import warnings
12+
from urllib.parse import urlparse
1213
from xml.sax.saxutils import escape, unescape
1314

14-
from six.moves import urllib_parse as urlparse
15-
1615
from . import base
1716
from ..constants import namespaces, prefixes
1817

@@ -845,7 +844,7 @@ def allowed_token(self, token):
845844
# remove replacement characters from unescaped characters
846845
val_unescaped = val_unescaped.replace("\ufffd", "")
847846
try:
848-
uri = urlparse.urlparse(val_unescaped)
847+
uri = urlparse(val_unescaped)
849848
except ValueError:
850849
uri = None
851850
del attrs[attr]

html5lib/html5parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from six import viewkeys
2-
31
from . import _inputstream
42
from . import _tokenizer
53

@@ -2773,7 +2771,7 @@ def processEndTag(self, token):
27732771

27742772

27752773
def adjust_attributes(token, replacements):
2776-
needs_adjustment = viewkeys(token['data']) & viewkeys(replacements)
2774+
needs_adjustment = token['data'].keys() & replacements.keys()
27772775
if needs_adjustment:
27782776
token['data'] = type(token['data'])((replacements.get(k, k), v)
27792777
for k, v in token['data'].items())

html5lib/serializer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from six import text_type
2-
31
import re
42

53
from codecs import register_error, xmlcharrefreplace_errors
@@ -221,14 +219,14 @@ def __init__(self, **kwargs):
221219
self.strict = False
222220

223221
def encode(self, string):
224-
assert isinstance(string, text_type)
222+
assert isinstance(string, str)
225223
if self.encoding:
226224
return string.encode(self.encoding, "htmlentityreplace")
227225
else:
228226
return string
229227

230228
def encodeStrict(self, string):
231-
assert isinstance(string, text_type)
229+
assert isinstance(string, str)
232230
if self.encoding:
233231
return string.encode(self.encoding, "strict")
234232
else:

html5lib/tests/test_meta.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
import six
31
from unittest.mock import Mock
42

53
from . import support
@@ -26,11 +24,7 @@ def test_errorMessage():
2624
r = support.errorMessage(input, expected, actual)
2725

2826
# Assertions!
29-
if six.PY2:
30-
assert b"Input:\n1\nExpected:\n2\nReceived\n3\n" == r
31-
else:
32-
assert six.PY3
33-
assert "Input:\n1\nExpected:\n2\nReceived\n3\n" == r
27+
assert "Input:\n1\nExpected:\n2\nReceived\n3\n" == r
3428

3529
assert input.__repr__.call_count == 1
3630
assert expected.__repr__.call_count == 1

0 commit comments

Comments
 (0)