Skip to content

Commit 04e4dba

Browse files
committed
Remove support for end-of-life Python 2.7
Python 2.7 has been EOL since 2020-01-01. It is no longer receiving security updates. By removing Python 2 support, can reduce testing resources and simplify the code by removing compatibility shims. Removes dependency on six. Removes test dependency on mock.
1 parent af19281 commit 04e4dba

Some content is hidden

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

64 files changed

+119
-327
lines changed

.appveyor.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ environment:
44
PATH: "C:\\Python27\\Scripts\\;%PATH%"
55
PYTEST_COMMAND: "coverage run -m pytest"
66
matrix:
7-
- TOXENV: py27-base
8-
- TOXENV: py27-optional
97
- TOXENV: py35-base
108
- TOXENV: py35-optional
119
- TOXENV: py36-base
@@ -21,7 +19,7 @@ test_script:
2119
- tox
2220

2321
after_test:
24-
- python debug-info.py
22+
- C:\\Python35\\python.exe debug-info.py
2523

2624
on_success:
2725
- codecov

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
language: python
22
python:
33
- "pypy3"
4-
- "pypy"
54
- "3.6"
65
- "3.5"
7-
- "2.7"
86

97
cache: pip
108

@@ -14,7 +12,6 @@ env:
1412
matrix:
1513
- TOXENV=optional
1614
- TOXENV=base
17-
- TOXENV=six19-optional
1815

1916
matrix:
2017
include:
@@ -24,9 +21,6 @@ matrix:
2421
- python: "3.7"
2522
dist: xenial # required for Python >= 3.7
2623
env: TOXENV=base
27-
- python: "3.7"
28-
dist: xenial # required for Python >= 3.7
29-
env: TOXENV=six19-optional
3024

3125
install:
3226
- pip install tox codecov

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
----------
33

4+
UNRELEASED
5+
----------
6+
7+
* Remove support for end-of-life Python 2.7.
8+
49
1.0.1
510
~~~~~
611

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ More documentation is available at https://html5lib.readthedocs.io/.
9191
Installation
9292
------------
9393

94-
html5lib works on CPython 2.7+, CPython 3.4+ and PyPy. To install it,
95-
use:
94+
html5lib works on CPython 3.5+ and PyPy. To install it, use:
9695

9796
.. code-block:: bash
9897
@@ -128,8 +127,8 @@ Please report any bugs on the `issue tracker
128127
Tests
129128
-----
130129

131-
Unit tests require the ``pytest`` and ``mock`` libraries and can be
132-
run using the ``py.test`` command in the root directory.
130+
Unit tests require the ``pytest`` library and can be run using the ``py.test``
131+
command in the root directory.
133132

134133
Test data are contained in a separate `html5lib-tests
135134
<https://github.com/html5lib/html5lib-tests>`_ repository and included

debug-info.py

Lines changed: 1 addition & 3 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

@@ -12,7 +10,7 @@
1210
"maxsize": sys.maxsize
1311
}
1412

15-
search_modules = ["chardet", "datrie", "genshi", "html5lib", "lxml", "six"]
13+
search_modules = ["chardet", "datrie", "genshi", "html5lib", "lxml"]
1614
found_modules = []
1715

1816
for m in search_modules:

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.
@@ -250,7 +249,7 @@
250249
# If true, do not generate a @detailmenu in the "Top" node's menu.
251250
#texinfo_no_detailmenu = False
252251

253-
class CExtMock(object):
252+
class CExtMock:
254253
"""Required for autodoc on readthedocs.org where you cannot build C extensions."""
255254
def __init__(self, *args, **kwargs):
256255
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

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

185183

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

189187
def __init__(self,

html5lib/_inputstream.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
3-
from six import text_type
4-
from six.moves import http_client, urllib
5-
1+
import urllib.response
62
import codecs
73
import re
84
from io import BytesIO, StringIO
5+
import http.client
96

107
import webencodings
118

@@ -48,7 +45,7 @@
4845
charsUntilRegEx = {}
4946

5047

51-
class BufferedStream(object):
48+
class BufferedStream:
5249
"""Buffering for streams that do not have buffering of their own
5350
5451
The buffer is implemented as a list of chunks on the assumption that
@@ -125,15 +122,15 @@ def _readFromBuffer(self, bytes):
125122
def HTMLInputStream(source, **kwargs):
126123
# Work around Python bug #20007: read(0) closes the connection.
127124
# http://bugs.python.org/issue20007
128-
if (isinstance(source, http_client.HTTPResponse) or
125+
if (isinstance(source, http.client.HTTPResponse) or
129126
# Also check for addinfourl wrapping HTTPResponse
130127
(isinstance(source, urllib.response.addbase) and
131-
isinstance(source.fp, http_client.HTTPResponse))):
128+
isinstance(source.fp, http.client.HTTPResponse))):
132129
isUnicode = False
133130
elif hasattr(source, "read"):
134-
isUnicode = isinstance(source.read(0), text_type)
131+
isUnicode = isinstance(source.read(0), str)
135132
else:
136-
isUnicode = isinstance(source, text_type)
133+
isUnicode = isinstance(source, str)
137134

138135
if isUnicode:
139136
encodings = [x for x in kwargs if x.endswith("_encoding")]
@@ -145,7 +142,7 @@ def HTMLInputStream(source, **kwargs):
145142
return HTMLBinaryInputStream(source, **kwargs)
146143

147144

148-
class HTMLUnicodeInputStream(object):
145+
class HTMLUnicodeInputStream:
149146
"""Provides a unicode stream of characters to the HTMLTokenizer.
150147
151148
This class takes care of character encoding and removing or replacing
@@ -598,10 +595,6 @@ def __next__(self):
598595
raise TypeError
599596
return self[p:p + 1]
600597

601-
def next(self):
602-
# Py2 compat
603-
return self.__next__()
604-
605598
def previous(self):
606599
p = self._position
607600
if p >= len(self):
@@ -679,7 +672,7 @@ def jumpTo(self, bytes):
679672
raise StopIteration
680673

681674

682-
class EncodingParser(object):
675+
class EncodingParser:
683676
"""Mini parser for detecting character encoding from meta elements"""
684677

685678
def __init__(self, data):
@@ -860,7 +853,7 @@ def getAttribute(self):
860853
attrValue.append(c)
861854

862855

863-
class ContentAttrParser(object):
856+
class ContentAttrParser:
864857
def __init__(self, data):
865858
assert isinstance(data, bytes)
866859
self.data = data

html5lib/_tokenizer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
3-
from six import unichr as chr
4-
51
from collections import deque
62

73
from .constants import spaceCharacters
@@ -18,7 +14,7 @@
1814
entitiesTrie = Trie(entities)
1915

2016

21-
class HTMLTokenizer(object):
17+
class HTMLTokenizer:
2218
""" This class takes care of tokenizing HTML.
2319
2420
* self.currentToken
@@ -44,7 +40,7 @@ def __init__(self, stream, parser=None, **kwargs):
4440

4541
# The current token being created
4642
self.currentToken = None
47-
super(HTMLTokenizer, self).__init__()
43+
super().__init__()
4844

4945
def __iter__(self):
5046
""" 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 as PyTrie
42

53
Trie = PyTrie

html5lib/_trie/_base.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
3-
try:
4-
from collections.abc import Mapping
5-
except ImportError: # Python 2.7
6-
from collections import Mapping
1+
from collections.abc import Mapping
72

83

94
class Trie(Mapping):
105
"""Abstract base class for tries"""
116

127
def keys(self, prefix=None):
138
# pylint:disable=arguments-differ
14-
keys = super(Trie, self).keys()
9+
keys = super().keys()
1510

1611
if prefix is None:
1712
return set(keys)

html5lib/_trie/datrie.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-
31
from datrie import Trie as DATrie
4-
from six import text_type
52

63
from ._base import Trie as ABCTrie
74

@@ -10,7 +7,7 @@ class Trie(ABCTrie):
107
def __init__(self, data):
118
chars = set()
129
for key in data.keys():
13-
if not isinstance(key, text_type):
10+
if not isinstance(key, str):
1411
raise TypeError("All keys must be strings")
1512
for char in key:
1613
chars.add(char)

html5lib/_trie/py.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
from six import text_type
3-
41
from bisect import bisect_left
52

63
from ._base import Trie as ABCTrie
74

85

96
class Trie(ABCTrie):
107
def __init__(self, data):
11-
if not all(isinstance(x, text_type) for x in data.keys()):
8+
if not all(isinstance(x, str) for x in data.keys()):
129
raise TypeError("All keys must be strings")
1310

1411
self._data = data

html5lib/_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
from __future__ import absolute_import, division, unicode_literals
2-
31
from types import ModuleType
42

5-
from six import text_type
6-
73
try:
84
import xml.etree.cElementTree as default_etree
95
except ImportError:
@@ -23,10 +19,10 @@
2319
# escapes.
2420
try:
2521
_x = eval('"\\uD800"') # pylint:disable=eval-used
26-
if not isinstance(_x, text_type):
22+
if not isinstance(_x, str):
2723
# We need this with u"" because of http://bugs.jython.org/issue2039
2824
_x = eval('u"\\uD800"') # pylint:disable=eval-used
29-
assert isinstance(_x, text_type)
25+
assert isinstance(_x, str)
3026
except: # pylint:disable=bare-except
3127
supports_lone_surrogates = False
3228
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

0 commit comments

Comments
 (0)