Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/dist
/docs/_build
/.coverage
.idea
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- '2.6'
- '2.7'
- '3.3'
- '3.4'
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://cssselect.readthedocs.io/>`_
* Source, issues and pull requests `on Github
* Source, issues and pull requests `on GitHub
<https://github.com/scrapy/cssselect>`_
* Releases `on PyPI <http://pypi.python.org/pypi/cssselect>`_
* Install with ``pip install cssselect``
19 changes: 6 additions & 13 deletions cssselect/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -554,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
Expand All @@ -573,7 +571,7 @@ def parse_series(tokens):
b = 0
else:
b = int(b)
return (a, b)
return a, b


#### Token objects
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cssselect/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cssselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ def get_error(css):
"Expected string or ident, got <DELIM '#' at 5>")
assert get_error('[href]a') == (
"Expected selector, got <IDENT 'a' at 6>")
assert get_error('[rel=stylesheet]') == None
assert get_error('[rel=stylesheet]') is None
assert get_error('[rel:stylesheet]') == (
"Operator expected, got <DELIM ':' at 4>")
assert get_error('[rel=stylesheet') == (
"Expected ']', got <EOF at 15>")
assert get_error(':lang(fr)') == None
assert get_error(':lang(fr)') is None
assert get_error(':lang(fr') == (
"Expected an argument, got <EOF at 8>")
assert get_error(':contains("foo') == (
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py25,py26,py27,py32,py33
envlist = py27,py33,py34,py35,py36

[testenv]
deps=
Expand All @@ -9,7 +9,3 @@ deps=

commands =
py.test --cov-report term --cov=cssselect

[testenv:py25]
setenv =
PIP_INSECURE = 1