Skip to content

Commit 1e14175

Browse files
committed
ruff: pyupgrade to 3.8
ruff check --target-version py38 --select UP --fix .
1 parent fd4f032 commit 1e14175

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

+39
-97
lines changed

debug-info.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function, unicode_literals
21

32
import platform
43
import sys

doc/conf.py

+1-2
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.
@@ -100,7 +99,7 @@
10099
}
101100

102101

103-
class CExtMock(object):
102+
class CExtMock:
104103
"""Required for autodoc on readthedocs.org where you cannot build C extensions."""
105104
def __init__(self, *args, **kwargs):
106105
pass

html5lib/__init__.py

-1
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import re
43
import warnings
@@ -181,7 +180,7 @@ def escapeRegexp(string):
181180
nonPubidCharRegexp = re.compile("[^\x20\x0D\x0Aa-zA-Z0-9\\-'()+,./:=?;!*#@$_%]")
182181

183182

184-
class InfosetFilter(object):
183+
class InfosetFilter:
185184
replacementRegexp = re.compile(r"U[\dA-F]{5,5}")
186185

187186
def __init__(self,

html5lib/_inputstream.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from six import text_type
43
from six.moves import http_client, urllib
@@ -48,7 +47,7 @@
4847
charsUntilRegEx = {}
4948

5049

51-
class BufferedStream(object):
50+
class BufferedStream:
5251
"""Buffering for streams that do not have buffering of their own
5352
5453
The buffer is implemented as a list of chunks on the assumption that
@@ -145,7 +144,7 @@ def HTMLInputStream(source, **kwargs):
145144
return HTMLBinaryInputStream(source, **kwargs)
146145

147146

148-
class HTMLUnicodeInputStream(object):
147+
class HTMLUnicodeInputStream:
149148
"""Provides a unicode stream of characters to the HTMLTokenizer.
150149
151150
This class takes care of character encoding and removing or replacing
@@ -673,7 +672,7 @@ def jumpTo(self, bytes):
673672
return True
674673

675674

676-
class EncodingParser(object):
675+
class EncodingParser:
677676
"""Mini parser for detecting character encoding from meta elements"""
678677

679678
def __init__(self, data):
@@ -861,7 +860,7 @@ def getAttribute(self):
861860
attrValue.append(c)
862861

863862

864-
class ContentAttrParser(object):
863+
class ContentAttrParser:
865864
def __init__(self, data):
866865
assert isinstance(data, bytes)
867866
self.data = data

html5lib/_tokenizer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from six import unichr as chr
43

@@ -24,7 +23,7 @@
2423
attributeMap = OrderedDict
2524

2625

27-
class HTMLTokenizer(object):
26+
class HTMLTokenizer:
2827
""" This class takes care of tokenizing HTML.
2928
3029
* self.currentToken

html5lib/_trie/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from .py import Trie
43

html5lib/_trie/_base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
try:
43
from collections.abc import Mapping
54
except ImportError: # Python 2.7
6-
from collections import Mapping
5+
from collections.abc import Mapping
76

87

98
class Trie(Mapping):

html5lib/_trie/py.py

-1
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

html5lib/_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from types import ModuleType
43

54
try:
65
from collections.abc import Mapping
76
except ImportError:
8-
from collections import Mapping
7+
from collections.abc import Mapping
98

109
from six import text_type, PY3
1110

1211
if PY3:
1312
import xml.etree.ElementTree as default_etree
1413
else:
1514
try:
16-
import xml.etree.cElementTree as default_etree
15+
import xml.etree.ElementTree as default_etree
1716
except ImportError:
1817
import xml.etree.ElementTree as default_etree
1918

@@ -122,7 +121,7 @@ def moduleFactoryFactory(factory):
122121
moduleCache = {}
123122

124123
def moduleFactory(baseModule, *args, **kwargs):
125-
if isinstance(ModuleType.__name__, type("")):
124+
if isinstance(ModuleType.__name__, str):
126125
name = "_%s_factory" % baseModule.__name__
127126
else:
128127
name = b"_%s_factory" % baseModule.__name__

html5lib/constants.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import string
43

html5lib/filters/alphabeticalattributes.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from . import base
43

html5lib/filters/base.py

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

32

4-
class Filter(object):
3+
class Filter:
54
def __init__(self, source):
65
self.source = source
76

html5lib/filters/inject_meta_charset.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from . import base
43

html5lib/filters/lint.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from six import text_type
43

html5lib/filters/optionaltags.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from . import base
43

html5lib/filters/sanitizer.py

-1
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

html5lib/filters/whitespace.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import re
43

html5lib/html5parser.py

+2-3
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 viewkeys
32

43
from . import _inputstream
@@ -69,7 +68,7 @@ def parseFragment(doc, container="div", treebuilder="etree", namespaceHTMLElemen
6968
return p.parseFragment(doc, container=container, **kwargs)
7069

7170

72-
class HTMLParser(object):
71+
class HTMLParser:
7372
"""HTML parser
7473
7574
Generates a tree structure from a stream of (possibly malformed) HTML.
@@ -397,7 +396,7 @@ def parseRCDataRawtext(self, token, contentType):
397396
self.phase = self.phases["text"]
398397

399398

400-
class Phase(object):
399+
class Phase:
401400
"""Base class for helper object that implements each phase of processing
402401
"""
403402
__slots__ = ("parser", "tree", "__startTagCache", "__endTagCache")

html5lib/serializer.py

+1-2
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
import re
@@ -101,7 +100,7 @@ def serialize(input, tree="etree", encoding=None, **serializer_opts):
101100
return s.render(walker(input), encoding)
102101

103102

104-
class HTMLSerializer(object):
103+
class HTMLSerializer:
105104

106105
# attribute quoting options
107106
quote_attr_values = "legacy" # be secure by default

html5lib/tests/__init__.py

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

html5lib/tests/conftest.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import os.path
32
import sys
43

@@ -54,7 +53,7 @@ def pytest_configure(config):
5453
# Check for optional requirements
5554
req_file = os.path.join(_root, "requirements-optional.txt")
5655
if os.path.exists(req_file):
57-
with open(req_file, "r") as fp:
56+
with open(req_file) as fp:
5857
for line in fp:
5958
if (line.strip() and
6059
not (line.startswith("-r") or
@@ -79,7 +78,7 @@ def pytest_configure(config):
7978
import xml.etree.ElementTree as ElementTree
8079

8180
try:
82-
import xml.etree.cElementTree as cElementTree
81+
import xml.etree.ElementTree as cElementTree
8382
except ImportError:
8483
msgs.append("cElementTree unable to be imported")
8584
else:

html5lib/tests/sanitizer.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import codecs
43
import json

html5lib/tests/support.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
# pylint:disable=wrong-import-position
43

@@ -86,7 +85,7 @@ def __getitem__(self, key):
8685
return dict.get(self, key, self.default)
8786

8887

89-
class TestData(object):
88+
class TestData:
9089
def __init__(self, filename, newTestHeading="data", encoding="utf8"):
9190
if encoding is None:
9291
self.f = open(filename, mode="rb")

html5lib/tests/test_alphabeticalattributes.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from collections import OrderedDict
43

html5lib/tests/test_encoding.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import os
43

@@ -9,7 +8,7 @@
98

109

1110
def test_basic_prescan_length():
12-
data = "<title>Caf\u00E9</title><!--a--><meta charset='utf-8'>".encode('utf-8')
11+
data = "<title>Caf\u00E9</title><!--a--><meta charset='utf-8'>".encode()
1312
pad = 1024 - len(data) + 1
1413
data = data.replace(b"-a-", b"-" + (b"a" * pad) + b"-")
1514
assert len(data) == 1024 # Sanity
@@ -18,7 +17,7 @@ def test_basic_prescan_length():
1817

1918

2019
def test_parser_reparse():
21-
data = "<title>Caf\u00E9</title><!--a--><meta charset='utf-8'>".encode('utf-8')
20+
data = "<title>Caf\u00E9</title><!--a--><meta charset='utf-8'>".encode()
2221
pad = 10240 - len(data) + 1
2322
data = data.replace(b"-a-", b"-" + (b"a" * pad) + b"-")
2423
assert len(data) == 10240 # Sanity

html5lib/tests/test_meta.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import six
43
try:
54
from unittest.mock import Mock
65
except ImportError:
7-
from mock import Mock
6+
from unittest.mock import Mock
87

98
from . import support
109

html5lib/tests/test_optionaltags_filter.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from html5lib.filters.optionaltags import Filter
43

html5lib/tests/test_parser2.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from six import PY2, text_type
43

html5lib/tests/test_sanitizer.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import warnings
43

html5lib/tests/test_serializer.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import os
43
import json

html5lib/tests/test_stream.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from . import support # noqa
43

@@ -105,7 +104,7 @@ def test_char_ascii():
105104

106105

107106
def test_char_utf8():
108-
stream = HTMLInputStream('\u2018'.encode('utf-8'), override_encoding='utf-8')
107+
stream = HTMLInputStream('\u2018'.encode(), override_encoding='utf-8')
109108
assert stream.charEncoding[0].name == 'utf-8'
110109
assert stream.char() == '\u2018'
111110

@@ -186,7 +185,7 @@ def test_python_issue_20007():
186185
Make sure we have a work-around for Python bug #20007
187186
http://bugs.python.org/issue20007
188187
"""
189-
class FakeSocket(object):
188+
class FakeSocket:
190189
def makefile(self, _mode, _bufsize=None):
191190
# pylint:disable=unused-argument
192191
return BytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")
@@ -205,7 +204,7 @@ def test_python_issue_20007_b():
205204
if six.PY2:
206205
return
207206

208-
class FakeSocket(object):
207+
class FakeSocket:
209208
def makefile(self, _mode, _bufsize=None):
210209
# pylint:disable=unused-argument
211210
return BytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")

html5lib/tests/test_tokenizer2.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import io
43

html5lib/tests/test_treeadapters.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
from . import support # noqa
43

html5lib/tests/test_treewalkers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
21

32
import itertools
43
import sys
@@ -74,11 +73,11 @@ def param_treewalker_six_mix():
7473
# fragment but not using the u'' syntax nor importing unicode_literals
7574
sm_tests = [
7675
('<a href="http://example.com">Example</a>',
77-
[(str('class'), str('test123'))],
76+
[('class', 'test123')],
7877
'<a>\n class="test123"\n href="http://example.com"\n "Example"'),
7978

8079
('<link href="http://example.com/cow">',
81-
[(str('rel'), str('alternate'))],
80+
[('rel', 'alternate')],
8281
'<link>\n href="http://example.com/cow"\n rel="alternate"\n "Example"')
8382
]
8483

0 commit comments

Comments
 (0)