From 0ac0fdccd1534856f84066a2b863ac9a0826f590 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Mon, 6 Nov 2017 15:57:40 -0500 Subject: [PATCH 1/2] Drop support for Python 2.6 Fixes #330 --- .travis.yml | 1 - README.rst | 5 ++--- html5lib/_trie/_base.py | 1 - html5lib/filters/alphabeticalattributes.py | 5 +---- html5lib/html5parser.py | 6 +----- html5lib/tests/test_alphabeticalattributes.py | 5 +---- html5lib/treewalkers/etree.py | 9 +-------- requirements.txt | 1 - setup.py | 5 ----- tox.ini | 3 +-- 10 files changed, 7 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index a6f17c3b..07fdff6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.6" - "2.7" - "3.3" - "3.4" diff --git a/README.rst b/README.rst index 2ad46090..8c151328 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ More documentation is available at https://html5lib.readthedocs.io/. Installation ------------ -html5lib works on CPython 2.6+, CPython 3.3+ and PyPy. To install it, +html5lib works on CPython 2.7+, CPython 3.3+ and PyPy. To install it, use: .. code-block:: bash @@ -128,8 +128,7 @@ Tests ----- Unit tests require the ``pytest`` and ``mock`` libraries and can be -run using the ``py.test`` command in the root directory; -``ordereddict`` is required under Python 2.6. All should pass. +run using the ``py.test`` command in the root directory. Test data are contained in a separate `html5lib-tests `_ repository and included diff --git a/html5lib/_trie/_base.py b/html5lib/_trie/_base.py index 25eece46..b2d83149 100644 --- a/html5lib/_trie/_base.py +++ b/html5lib/_trie/_base.py @@ -13,7 +13,6 @@ def keys(self, prefix=None): if prefix is None: return set(keys) - # Python 2.6: no set comprehensions return set([x for x in keys if x.startswith(prefix)]) def has_keys_with_prefix(self, prefix): diff --git a/html5lib/filters/alphabeticalattributes.py b/html5lib/filters/alphabeticalattributes.py index f938ba1a..5fea9f69 100644 --- a/html5lib/filters/alphabeticalattributes.py +++ b/html5lib/filters/alphabeticalattributes.py @@ -2,10 +2,7 @@ from . import base -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict +from collections import OrderedDict def _attr_key(attr): diff --git a/html5lib/html5parser.py b/html5lib/html5parser.py index 2abd63e4..f8309e14 100644 --- a/html5lib/html5parser.py +++ b/html5lib/html5parser.py @@ -2,11 +2,7 @@ from six import with_metaclass, viewkeys, PY3 import types - -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict +from collections import OrderedDict from . import _inputstream from . import _tokenizer diff --git a/html5lib/tests/test_alphabeticalattributes.py b/html5lib/tests/test_alphabeticalattributes.py index 9e560a1e..7d5b8e0f 100644 --- a/html5lib/tests/test_alphabeticalattributes.py +++ b/html5lib/tests/test_alphabeticalattributes.py @@ -1,9 +1,6 @@ from __future__ import absolute_import, division, unicode_literals -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict +from collections import OrderedDict import pytest diff --git a/html5lib/treewalkers/etree.py b/html5lib/treewalkers/etree.py index 8f30f078..d15a7eeb 100644 --- a/html5lib/treewalkers/etree.py +++ b/html5lib/treewalkers/etree.py @@ -1,13 +1,6 @@ from __future__ import absolute_import, division, unicode_literals -try: - from collections import OrderedDict -except ImportError: - try: - from ordereddict import OrderedDict - except ImportError: - OrderedDict = dict - +from collections import OrderedDict import re from six import string_types diff --git a/requirements.txt b/requirements.txt index 3884556f..ae7ec3d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ six>=1.9 webencodings -ordereddict ; python_version < '2.7' diff --git a/setup.py b/setup.py index cdb63fd3..3e413f2a 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,6 @@ def default_environment(): 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', @@ -107,10 +106,6 @@ def default_environment(): 'webencodings', ], extras_require={ - # A empty extra that only has a conditional marker will be - # unconditonally installed when the condition matches. - ":python_version == '2.6'": ["ordereddict"], - # A conditional extra will only install these items when the extra is # requested and the condition matches. "datrie:platform_python_implementation == 'CPython'": ["datrie"], diff --git a/tox.ini b/tox.ini index 5b78570c..0ec9805d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py26,py27,py33,py34,py35,py36,pypy}-{base,optional} +envlist = {py27,py33,py34,py35,py36,pypy}-{base,optional} [testenv] deps = @@ -9,7 +9,6 @@ deps = mock base: six base: webencodings - py26-base: ordereddict optional: -r{toxinidir}/requirements-optional.txt doc: Sphinx From 817dff46d2393b69d76d2c88c7fb84840ddbfff9 Mon Sep 17 00:00:00 2001 From: Will Kahn-Greene Date: Mon, 6 Nov 2017 16:18:02 -0500 Subject: [PATCH 2/2] Switch to set comprehension --- html5lib/_trie/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html5lib/_trie/_base.py b/html5lib/_trie/_base.py index b2d83149..a1158bbb 100644 --- a/html5lib/_trie/_base.py +++ b/html5lib/_trie/_base.py @@ -13,7 +13,7 @@ def keys(self, prefix=None): if prefix is None: return set(keys) - return set([x for x in keys if x.startswith(prefix)]) + return {x for x in keys if x.startswith(prefix)} def has_keys_with_prefix(self, prefix): for key in self.keys():