Skip to content

Commit 2f1d6e0

Browse files
committed
Upgrade Python syntax with pyupgrade --py3-plus
1 parent 637e90b commit 2f1d6e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+197
-308
lines changed

debug-info.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function, unicode_literals
2-
31
import platform
42
import sys
53

doc/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# html5lib documentation build configuration file, created by
54
# sphinx-quickstart on Wed May 8 00:04:49 2013.
@@ -92,7 +91,7 @@
9291
]
9392

9493

95-
class CExtMock(object):
94+
class CExtMock:
9695
"""Required for autodoc on readthedocs.org where you cannot build C extensions."""
9796
def __init__(self, *args, **kwargs):
9897
pass

html5lib/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* :func:`~.serializer.serialize`
2121
"""
2222

23-
from __future__ import absolute_import, division, unicode_literals
2423

2524
from .html5parser import HTMLParser, parse, parseFragment
2625
from .treebuilders import getTreeBuilder

html5lib/_ihatexml.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
import re
42
import warnings
53

@@ -184,7 +182,7 @@ def escapeRegexp(string):
184182
nonPubidCharRegexp = re.compile("[^\x20\x0D\x0Aa-zA-Z0-9\\-'()+,./:=?;!*#@$_%]")
185183

186184

187-
class InfosetFilter(object):
185+
class InfosetFilter:
188186
replacementRegexp = re.compile(r"U[\dA-F]{5,5}")
189187

190188
def __init__(self,

html5lib/_inputstream.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from six import text_type
42
from six.moves import http_client, urllib
53

@@ -14,9 +12,9 @@
1412
from . import _utils
1513

1614
# Non-unicode versions of constants for use in the pre-parser
17-
spaceCharactersBytes = frozenset([item.encode("ascii") for item in spaceCharacters])
18-
asciiLettersBytes = frozenset([item.encode("ascii") for item in asciiLetters])
19-
asciiUppercaseBytes = frozenset([item.encode("ascii") for item in asciiUppercase])
15+
spaceCharactersBytes = frozenset(item.encode("ascii") for item in spaceCharacters)
16+
asciiLettersBytes = frozenset(item.encode("ascii") for item in asciiLetters)
17+
asciiUppercaseBytes = frozenset(item.encode("ascii") for item in asciiUppercase)
2018
spacesAngleBrackets = spaceCharactersBytes | frozenset([b">", b"<"])
2119

2220

@@ -48,7 +46,7 @@
4846
charsUntilRegEx = {}
4947

5048

51-
class BufferedStream(object):
49+
class BufferedStream:
5250
"""Buffering for streams that do not have buffering of their own
5351
5452
The buffer is implemented as a list of chunks on the assumption that
@@ -86,7 +84,7 @@ def read(self, bytes):
8684
return self._readFromBuffer(bytes)
8785

8886
def _bufferedBytes(self):
89-
return sum([len(item) for item in self.buffer])
87+
return sum(len(item) for item in self.buffer)
9088

9189
def _readStream(self, bytes):
9290
data = self.stream.read(bytes)
@@ -131,9 +129,9 @@ def HTMLInputStream(source, **kwargs):
131129
isinstance(source.fp, http_client.HTTPResponse))):
132130
isUnicode = False
133131
elif hasattr(source, "read"):
134-
isUnicode = isinstance(source.read(0), text_type)
132+
isUnicode = isinstance(source.read(0), str)
135133
else:
136-
isUnicode = isinstance(source, text_type)
134+
isUnicode = isinstance(source, str)
137135

138136
if isUnicode:
139137
encodings = [x for x in kwargs if x.endswith("_encoding")]
@@ -145,7 +143,7 @@ def HTMLInputStream(source, **kwargs):
145143
return HTMLBinaryInputStream(source, **kwargs)
146144

147145

148-
class HTMLUnicodeInputStream(object):
146+
class HTMLUnicodeInputStream:
149147
"""Provides a unicode stream of characters to the HTMLTokenizer.
150148
151149
This class takes care of character encoding and removing or replacing
@@ -325,7 +323,7 @@ def charsUntil(self, characters, opposite=False):
325323
if __debug__:
326324
for c in characters:
327325
assert(ord(c) < 128)
328-
regex = "".join(["\\x%02x" % ord(c) for c in characters])
326+
regex = "".join("\\x%02x" % ord(c) for c in characters)
329327
if not opposite:
330328
regex = "^%s" % regex
331329
chars = charsUntilRegEx[(characters, opposite)] = re.compile("[%s]+" % regex)
@@ -524,7 +522,7 @@ def changeEncoding(self, newEncoding):
524522
self.rawStream.seek(0)
525523
self.charEncoding = (newEncoding, "certain")
526524
self.reset()
527-
raise _ReparseException("Encoding changed from %s to %s" % (self.charEncoding[0], newEncoding))
525+
raise _ReparseException("Encoding changed from {} to {}".format(self.charEncoding[0], newEncoding))
528526

529527
def detectBOM(self):
530528
"""Attempts to detect at BOM at the start of the stream. If
@@ -673,7 +671,7 @@ def jumpTo(self, bytes):
673671
return True
674672

675673

676-
class EncodingParser(object):
674+
class EncodingParser:
677675
"""Mini parser for detecting character encoding from meta elements"""
678676

679677
def __init__(self, data):
@@ -861,7 +859,7 @@ def getAttribute(self):
861859
attrValue.append(c)
862860

863861

864-
class ContentAttrParser(object):
862+
class ContentAttrParser:
865863
def __init__(self, data):
866864
assert isinstance(data, bytes)
867865
self.data = data

html5lib/_tokenizer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from six import unichr as chr
42

53
from collections import deque, OrderedDict
@@ -24,7 +22,7 @@
2422
attributeMap = OrderedDict
2523

2624

27-
class HTMLTokenizer(object):
25+
class HTMLTokenizer:
2826
""" This class takes care of tokenizing HTML.
2927
3028
* self.currentToken
@@ -50,7 +48,7 @@ def __init__(self, stream, parser=None, **kwargs):
5048

5149
# The current token being created
5250
self.currentToken = None
53-
super(HTMLTokenizer, self).__init__()
51+
super().__init__()
5452

5553
def __iter__(self):
5654
""" This is where the magic happens.

html5lib/_trie/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from .py import Trie
42

53
__all__ = ["Trie"]

html5lib/_trie/_base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from collections.abc import Mapping
42

53

@@ -8,7 +6,7 @@ class Trie(Mapping):
86

97
def keys(self, prefix=None):
108
# pylint:disable=arguments-differ
11-
keys = super(Trie, self).keys()
9+
keys = super().keys()
1210

1311
if prefix is None:
1412
return set(keys)

html5lib/_trie/py.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21
from six import text_type
32

43
from bisect import bisect_left
@@ -8,7 +7,7 @@
87

98
class Trie(ABCTrie):
109
def __init__(self, data):
11-
if not all(isinstance(x, text_type) for x in data.keys()):
10+
if not all(isinstance(x, str) for x in data.keys()):
1211
raise TypeError("All keys must be strings")
1312

1413
self._data = data

html5lib/_utils.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from types import ModuleType
42

53
from collections.abc import Mapping
64

75
from six import text_type, PY3
86

9-
if PY3:
10-
import xml.etree.ElementTree as default_etree
11-
else:
12-
try:
13-
import xml.etree.cElementTree as default_etree
14-
except ImportError:
15-
import xml.etree.ElementTree as default_etree
7+
import xml.etree.ElementTree as default_etree
168

179

1810
__all__ = ["default_etree", "MethodDispatcher", "isSurrogatePair",
@@ -28,10 +20,10 @@
2820
# escapes.
2921
try:
3022
_x = eval('"\\uD800"') # pylint:disable=eval-used
31-
if not isinstance(_x, text_type):
23+
if not isinstance(_x, str):
3224
# We need this with u"" because of http://bugs.jython.org/issue2039
3325
_x = eval('u"\\uD800"') # pylint:disable=eval-used
34-
assert isinstance(_x, text_type)
26+
assert isinstance(_x, str)
3527
except Exception:
3628
supports_lone_surrogates = False
3729
else:

html5lib/constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
import string
42

53
EOF = None

html5lib/filters/alphabeticalattributes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from . import base
42

53
from collections import OrderedDict

html5lib/filters/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
3-
4-
class Filter(object):
1+
class Filter:
52
def __init__(self, source):
63
self.source = source
74

html5lib/filters/inject_meta_charset.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from . import base
42

53

html5lib/filters/lint.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from six import text_type
42

53
from . import base
@@ -23,7 +21,7 @@ def __init__(self, source, require_matching_tags=True):
2321
:arg require_matching_tags: whether or not to require matching tags
2422
2523
"""
26-
super(Filter, self).__init__(source)
24+
super().__init__(source)
2725
self.require_matching_tags = require_matching_tags
2826

2927
def __iter__(self):
@@ -33,9 +31,9 @@ def __iter__(self):
3331
if type in ("StartTag", "EmptyTag"):
3432
namespace = token["namespace"]
3533
name = token["name"]
36-
assert namespace is None or isinstance(namespace, text_type)
34+
assert namespace is None or isinstance(namespace, str)
3735
assert namespace != ""
38-
assert isinstance(name, text_type)
36+
assert isinstance(name, str)
3937
assert name != ""
4038
assert isinstance(token["data"], dict)
4139
if (not namespace or namespace == namespaces["html"]) and name in voidElements:
@@ -45,49 +43,49 @@ def __iter__(self):
4543
if type == "StartTag" and self.require_matching_tags:
4644
open_elements.append((namespace, name))
4745
for (namespace, name), value in token["data"].items():
48-
assert namespace is None or isinstance(namespace, text_type)
46+
assert namespace is None or isinstance(namespace, str)
4947
assert namespace != ""
50-
assert isinstance(name, text_type)
48+
assert isinstance(name, str)
5149
assert name != ""
52-
assert isinstance(value, text_type)
50+
assert isinstance(value, str)
5351

5452
elif type == "EndTag":
5553
namespace = token["namespace"]
5654
name = token["name"]
57-
assert namespace is None or isinstance(namespace, text_type)
55+
assert namespace is None or isinstance(namespace, str)
5856
assert namespace != ""
59-
assert isinstance(name, text_type)
57+
assert isinstance(name, str)
6058
assert name != ""
6159
if (not namespace or namespace == namespaces["html"]) and name in voidElements:
62-
assert False, "Void element reported as EndTag token: %(tag)s" % {"tag": name}
60+
assert False, "Void element reported as EndTag token: {tag}".format(tag=name)
6361
elif self.require_matching_tags:
6462
start = open_elements.pop()
6563
assert start == (namespace, name)
6664

6765
elif type == "Comment":
6866
data = token["data"]
69-
assert isinstance(data, text_type)
67+
assert isinstance(data, str)
7068

7169
elif type in ("Characters", "SpaceCharacters"):
7270
data = token["data"]
73-
assert isinstance(data, text_type)
71+
assert isinstance(data, str)
7472
assert data != ""
7573
if type == "SpaceCharacters":
7674
assert data.strip(spaceCharacters) == ""
7775

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

8482
elif type == "Entity":
85-
assert isinstance(token["name"], text_type)
83+
assert isinstance(token["name"], str)
8684

8785
elif type == "SerializerError":
88-
assert isinstance(token["data"], text_type)
86+
assert isinstance(token["data"], str)
8987

9088
else:
91-
assert False, "Unknown token type: %(type)s" % {"type": type}
89+
assert False, "Unknown token type: {type}".format(type=type)
9290

9391
yield token

html5lib/filters/optionaltags.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from . import base
42

53

html5lib/filters/sanitizer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
if Bleach is unsuitable for your needs.
77
88
"""
9-
from __future__ import absolute_import, division, unicode_literals
109

1110
import re
1211
import warnings
@@ -766,7 +765,7 @@ def __init__(self,
766765
hrefs--these are removed
767766
768767
"""
769-
super(Filter, self).__init__(source)
768+
super().__init__(source)
770769

771770
warnings.warn(_deprecation_msg, DeprecationWarning)
772771

@@ -874,8 +873,8 @@ def disallowed_token(self, token):
874873
assert token_type in ("StartTag", "EmptyTag")
875874
attrs = []
876875
for (ns, name), v in token["data"].items():
877-
attrs.append(' %s="%s"' % (name if ns is None else "%s:%s" % (prefixes[ns], name), escape(v)))
878-
token["data"] = "<%s%s>" % (token["name"], ''.join(attrs))
876+
attrs.append(' {}="{}"'.format(name if ns is None else "{}:{}".format(prefixes[ns], name), escape(v)))
877+
token["data"] = "<{}{}>".format(token["name"], ''.join(attrs))
879878
else:
880879
token["data"] = "<%s>" % token["name"]
881880
if token.get("selfClosing"):

html5lib/filters/whitespace.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
import re
42

53
from . import base

0 commit comments

Comments
 (0)