Skip to content

Remove support for end-of-life Python 2.7 #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ environment:
PATH: "C:\\Python27\\Scripts\\;%PATH%"
PYTEST_COMMAND: "coverage run -m pytest"
matrix:
- TOXENV: py27-base
- TOXENV: py27-optional
- TOXENV: py35-base
- TOXENV: py35-optional
- TOXENV: py36-base
Expand All @@ -21,7 +19,7 @@ test_script:
- tox

after_test:
- python debug-info.py
- C:\\Python35\\python.exe debug-info.py

on_success:
- codecov
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: python
python:
- "pypy3"
- "pypy"
- "3.6"
- "3.5"
- "2.7"

cache: pip

Expand All @@ -14,7 +12,6 @@ env:
matrix:
- TOXENV=optional
- TOXENV=base
- TOXENV=six19-optional

matrix:
include:
Expand All @@ -24,9 +21,6 @@ matrix:
- python: "3.7"
dist: xenial # required for Python >= 3.7
env: TOXENV=base
- python: "3.7"
dist: xenial # required for Python >= 3.7
env: TOXENV=six19-optional

install:
- pip install tox codecov
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
----------

UNRELEASED
----------

* Remove support for end-of-life Python 2.7.

1.0.1
~~~~~

Expand Down
7 changes: 3 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ More documentation is available at https://html5lib.readthedocs.io/.
Installation
------------

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

.. code-block:: bash

Expand Down Expand Up @@ -128,8 +127,8 @@ Please report any bugs on the `issue tracker
Tests
-----

Unit tests require the ``pytest`` and ``mock`` libraries and can be
run using the ``py.test`` command in the root directory.
Unit tests require the ``pytest`` library and can be run using the ``py.test``
command in the root directory.

Test data are contained in a separate `html5lib-tests
<https://github.com/html5lib/html5lib-tests>`_ repository and included
Expand Down
4 changes: 1 addition & 3 deletions debug-info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function, unicode_literals

import platform
import sys

Expand All @@ -12,7 +10,7 @@
"maxsize": sys.maxsize
}

search_modules = ["chardet", "datrie", "genshi", "html5lib", "lxml", "six"]
search_modules = ["chardet", "datrie", "genshi", "html5lib", "lxml"]
found_modules = []

for m in search_modules:
Expand Down
3 changes: 1 addition & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# html5lib documentation build configuration file, created by
# sphinx-quickstart on Wed May 8 00:04:49 2013.
Expand Down Expand Up @@ -250,7 +249,7 @@
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False

class CExtMock(object):
class CExtMock:
"""Required for autodoc on readthedocs.org where you cannot build C extensions."""
def __init__(self, *args, **kwargs):
pass
Expand Down
1 change: 0 additions & 1 deletion html5lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* :func:`~.serializer.serialize`
"""

from __future__ import absolute_import, division, unicode_literals

from .html5parser import HTMLParser, parse, parseFragment
from .treebuilders import getTreeBuilder
Expand Down
4 changes: 1 addition & 3 deletions html5lib/_ihatexml.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

import re
import warnings

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


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

def __init__(self,
Expand Down
27 changes: 10 additions & 17 deletions html5lib/_inputstream.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import absolute_import, division, unicode_literals

from six import text_type
from six.moves import http_client, urllib

import urllib.response
import codecs
import re
from io import BytesIO, StringIO
import http.client

import webencodings

Expand Down Expand Up @@ -48,7 +45,7 @@
charsUntilRegEx = {}


class BufferedStream(object):
class BufferedStream:
"""Buffering for streams that do not have buffering of their own

The buffer is implemented as a list of chunks on the assumption that
Expand Down Expand Up @@ -125,15 +122,15 @@ def _readFromBuffer(self, bytes):
def HTMLInputStream(source, **kwargs):
# Work around Python bug #20007: read(0) closes the connection.
# http://bugs.python.org/issue20007
if (isinstance(source, http_client.HTTPResponse) or
if (isinstance(source, http.client.HTTPResponse) or
# Also check for addinfourl wrapping HTTPResponse
(isinstance(source, urllib.response.addbase) and
isinstance(source.fp, http_client.HTTPResponse))):
isinstance(source.fp, http.client.HTTPResponse))):
isUnicode = False
elif hasattr(source, "read"):
isUnicode = isinstance(source.read(0), text_type)
isUnicode = isinstance(source.read(0), str)
else:
isUnicode = isinstance(source, text_type)
isUnicode = isinstance(source, str)

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


class HTMLUnicodeInputStream(object):
class HTMLUnicodeInputStream:
"""Provides a unicode stream of characters to the HTMLTokenizer.

This class takes care of character encoding and removing or replacing
Expand Down Expand Up @@ -598,10 +595,6 @@ def __next__(self):
raise TypeError
return self[p:p + 1]

def next(self):
# Py2 compat
return self.__next__()

def previous(self):
p = self._position
if p >= len(self):
Expand Down Expand Up @@ -679,7 +672,7 @@ def jumpTo(self, bytes):
raise StopIteration


class EncodingParser(object):
class EncodingParser:
"""Mini parser for detecting character encoding from meta elements"""

def __init__(self, data):
Expand Down Expand Up @@ -860,7 +853,7 @@ def getAttribute(self):
attrValue.append(c)


class ContentAttrParser(object):
class ContentAttrParser:
def __init__(self, data):
assert isinstance(data, bytes)
self.data = data
Expand Down
8 changes: 2 additions & 6 deletions html5lib/_tokenizer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

from six import unichr as chr

from collections import deque

from .constants import spaceCharacters
Expand All @@ -18,7 +14,7 @@
entitiesTrie = Trie(entities)


class HTMLTokenizer(object):
class HTMLTokenizer:
""" This class takes care of tokenizing HTML.

* self.currentToken
Expand All @@ -44,7 +40,7 @@ def __init__(self, stream, parser=None, **kwargs):

# The current token being created
self.currentToken = None
super(HTMLTokenizer, self).__init__()
super().__init__()

def __iter__(self):
""" This is where the magic happens.
Expand Down
2 changes: 0 additions & 2 deletions html5lib/_trie/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

from .py import Trie as PyTrie

Trie = PyTrie
Expand Down
9 changes: 2 additions & 7 deletions html5lib/_trie/_base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from __future__ import absolute_import, division, unicode_literals

try:
from collections.abc import Mapping
except ImportError: # Python 2.7
from collections import Mapping
from collections.abc import Mapping


class Trie(Mapping):
"""Abstract base class for tries"""

def keys(self, prefix=None):
# pylint:disable=arguments-differ
keys = super(Trie, self).keys()
keys = super().keys()

if prefix is None:
return set(keys)
Expand Down
5 changes: 1 addition & 4 deletions html5lib/_trie/datrie.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import absolute_import, division, unicode_literals

from datrie import Trie as DATrie
from six import text_type

from ._base import Trie as ABCTrie

Expand All @@ -10,7 +7,7 @@ class Trie(ABCTrie):
def __init__(self, data):
chars = set()
for key in data.keys():
if not isinstance(key, text_type):
if not isinstance(key, str):
raise TypeError("All keys must be strings")
for char in key:
chars.add(char)
Expand Down
5 changes: 1 addition & 4 deletions html5lib/_trie/py.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from __future__ import absolute_import, division, unicode_literals
from six import text_type

from bisect import bisect_left

from ._base import Trie as ABCTrie


class Trie(ABCTrie):
def __init__(self, data):
if not all(isinstance(x, text_type) for x in data.keys()):
if not all(isinstance(x, str) for x in data.keys()):
raise TypeError("All keys must be strings")

self._data = data
Expand Down
8 changes: 2 additions & 6 deletions html5lib/_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from __future__ import absolute_import, division, unicode_literals

from types import ModuleType

from six import text_type

try:
import xml.etree.cElementTree as default_etree
except ImportError:
Expand All @@ -23,10 +19,10 @@
# escapes.
try:
_x = eval('"\\uD800"') # pylint:disable=eval-used
if not isinstance(_x, text_type):
if not isinstance(_x, str):
# We need this with u"" because of http://bugs.jython.org/issue2039
_x = eval('u"\\uD800"') # pylint:disable=eval-used
assert isinstance(_x, text_type)
assert isinstance(_x, str)
except: # pylint:disable=bare-except
supports_lone_surrogates = False
else:
Expand Down
2 changes: 0 additions & 2 deletions html5lib/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

import string

EOF = None
Expand Down
2 changes: 0 additions & 2 deletions html5lib/filters/alphabeticalattributes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

from . import base

from collections import OrderedDict
Expand Down
5 changes: 1 addition & 4 deletions html5lib/filters/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import absolute_import, division, unicode_literals


class Filter(object):
class Filter:
def __init__(self, source):
self.source = source

Expand Down
2 changes: 0 additions & 2 deletions html5lib/filters/inject_meta_charset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

from . import base


Expand Down
Loading