From daca23b513f755298b166b328e97c0d830a9fcf1 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 14 Dec 2017 17:13:19 +0200 Subject: [PATCH 1/4] Ignore IDE metadata --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4c89f4c..b0ab86a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /dist /docs/_build /.coverage +.idea \ No newline at end of file From 83014a796af107b6eb934e085011ecdf85dc4c42 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 14 Dec 2017 17:17:49 +0200 Subject: [PATCH 2/4] Drop support for EOL Python 2.6 --- .travis.yml | 1 - README.rst | 4 ++-- cssselect/parser.py | 9 +-------- setup.py | 2 +- tox.ini | 6 +----- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index cc709f1..61edf5a 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 587c2d7..972b06b 100644 --- a/README.rst +++ b/README.rst @@ -17,9 +17,9 @@ extracted as a stand-alone project. Quick facts: * Free software: BSD licensed -* Compatible with Python 2.6+ and 3.3+ +* Compatible with Python 2.7 and 3.3+ * Latest documentation `on Read the Docs `_ -* Source, issues and pull requests `on Github +* Source, issues and pull requests `on GitHub `_ * Releases `on PyPI `_ * Install with ``pip install cssselect`` diff --git a/cssselect/parser.py b/cssselect/parser.py index fe5f53c..dd4709a 100644 --- a/cssselect/parser.py +++ b/cssselect/parser.py @@ -358,8 +358,6 @@ def parse(css): # message = "%s at %s -> %r" % ( # e, stream.used, stream.peek()) # e.msg = message -# if sys.version_info < (2,6): -# e.message = message # e.args = tuple([message]) # raise @@ -630,12 +628,7 @@ def _compile(pattern): _sub_newline_escape =re.compile(r'\\(?:\n|\r\n|\r|\f)').sub # Same as r'\1', but faster on CPython -if hasattr(operator, 'methodcaller'): - # Python 2.6+ - _replace_simple = operator.methodcaller('group', 1) -else: - def _replace_simple(match): - return match.group(1) +_replace_simple = operator.methodcaller('group', 1) def _replace_unicode(match): codepoint = int(match.group(1), 16) diff --git a/setup.py b/setup.py index 199ffc7..032aa89 100644 --- a/setup.py +++ b/setup.py @@ -29,12 +29,12 @@ url='https://github.com/scrapy/cssselect', license='BSD', packages=['cssselect'], + python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*', classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', diff --git a/tox.ini b/tox.ini index 7a3359a..a019f4e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py25,py26,py27,py32,py33 +envlist = py27,py33,py34,py35,py36 [testenv] deps= @@ -9,7 +9,3 @@ deps= commands = py.test --cov-report term --cov=cssselect - -[testenv:py25] -setenv = - PIP_INSECURE = 1 From c040d86c5458547bbbf80c5fd4aa9ce771f85234 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 14 Dec 2017 17:19:16 +0200 Subject: [PATCH 3/4] Use 'is' to compare with None --- tests/test_cssselect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_cssselect.py b/tests/test_cssselect.py index 4a0bd39..f01aa7f 100644 --- a/tests/test_cssselect.py +++ b/tests/test_cssselect.py @@ -288,12 +288,12 @@ def get_error(css): "Expected string or ident, got ") assert get_error('[href]a') == ( "Expected selector, got ") - assert get_error('[rel=stylesheet]') == None + assert get_error('[rel=stylesheet]') is None assert get_error('[rel:stylesheet]') == ( "Operator expected, got ") assert get_error('[rel=stylesheet') == ( "Expected ']', got ") - assert get_error(':lang(fr)') == None + assert get_error(':lang(fr)') is None assert get_error(':lang(fr') == ( "Expected an argument, got ") assert get_error(':contains("foo') == ( @@ -586,8 +586,8 @@ def series(css): assert series('+n') == (1, 0) assert series('-n') == (-1, 0) assert series('5') == (0, 5) - assert series('foo') == None - assert series('n+') == None + assert series('foo') is None + assert series('n+') is None def test_lang(self): document = etree.fromstring(XMLLANG_IDS) From 1060ca1f3f1746caad8673f0c99299a389f1bc7c Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 14 Dec 2017 17:20:08 +0200 Subject: [PATCH 4/4] Remove redundant parentheses --- cssselect/parser.py | 10 +++++----- cssselect/xpath.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cssselect/parser.py b/cssselect/parser.py index dd4709a..9bb039c 100644 --- a/cssselect/parser.py +++ b/cssselect/parser.py @@ -552,14 +552,14 @@ def parse_series(tokens): raise ValueError('String tokens not allowed in series.') s = ''.join(token.value for token in tokens).strip() if s == 'odd': - return (2, 1) + return 2, 1 elif s == 'even': - return (2, 0) + return 2, 0 elif s == 'n': - return (1, 0) + return 1, 0 if 'n' not in s: # Just b - return (0, int(s)) + return 0, int(s) a, b = s.split('n', 1) if not a: a = 1 @@ -571,7 +571,7 @@ def parse_series(tokens): b = 0 else: b = int(b) - return (a, b) + return a, b #### Token objects diff --git a/cssselect/xpath.py b/cssselect/xpath.py index d0eb2cb..22cd029 100644 --- a/cssselect/xpath.py +++ b/cssselect/xpath.py @@ -490,7 +490,7 @@ def xpath_nth_child_function(self, xpath, function, last=False, b_neg = (-b_min_1) % abs(a) if b_neg != 0: - b_neg = '+%s' % (b_neg) + b_neg = '+%s' % b_neg left = '(%s %s)' % (left, b_neg) expr.append('%s mod %s = 0' % (left, a))