Skip to content

Commit

Permalink
Add Python 3 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Mar 22, 2015
1 parent 22cb10b commit 08e5340
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"

notifications:
email:
Expand Down
8 changes: 4 additions & 4 deletions jsonselect/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def cli():
if not selection:
sys.exit(2)
if args.machine_readable:
print json.dumps(selection)
print(json.dumps(selection))
elif args.list:
if hasattr(selection, '__iter__'):
for i in selection:
print i
print(i)
else:
print selection
print(selection)
else:
print json.dumps(selection, indent=4)
print(json.dumps(selection, indent=4))

cli()
13 changes: 8 additions & 5 deletions jsonselect/jsonselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import collections
import logging
import json
import sys

if sys.version_info[0] >= 3:
basestring = str

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,11 +54,11 @@
(r"\s", S_EMPTY),
(r"(-?\d+(\.\d*)([eE][+\-]?\d+)?)", S_FLOAT),
(r"string|boolean|null|array|object|number", S_TYPE),
(ur"\"([_a-zA-Z]|[^\0-\0177]|\\[^\s0-9a-fA-F])([_a-zA-Z0-9\-]"
ur"|[^\u0000-\u0177]|(\\[^\s0-9a-fA-F]))*\"", S_WORD),
(u"\"([_a-zA-Z]|[^\0-\0177]|\\\\[^\s0-9a-fA-F])([_a-zA-Z0-9\-]"
u"|[^\u0000-\u0177]|(\\\\[^\s0-9a-fA-F]))*\"", S_WORD),
(r'\.?\"([^"\\]|\\[^"])*\"', S_QUOTED_IDENTIFIER),
(ur"\.([_a-zA-Z]|[^\0-\0177]|\\[^\s0-9a-fA-F])([_a-zA-Z0-9\-]"
ur"|[^\u0000-\u0177]|(\\[^\s0-9a-fA-F]))*", S_IDENTIFIER),
(u"\.([_a-zA-Z]|[^\0-\0177]|\\\\[^\s0-9a-fA-F])([_a-zA-Z0-9\-]"
u"|[^\u0000-\u0177]|(\\\\[^\s0-9a-fA-F]))*", S_IDENTIFIER),
(r":(root|empty|first-child|last-child|only-child)", S_PCLASS),
(r":(has|expr|val|contains)", S_PCLASS_FUNC),
(r":(nth-child|nth-last-child)", S_NTH_FUNC),
Expand Down Expand Up @@ -469,6 +472,6 @@ def select(selector, obj):
parser = Parser(obj)
try:
return parser.parse(selector)
except SelectorSyntaxError, e:
except SelectorSyntaxError as e:
log.exception(e)
return False
7 changes: 6 additions & 1 deletion tests/test_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jsonselect import jsonselect
from unittest import TestCase, skip
import logging
import sys


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -117,7 +118,11 @@ def _test(self=None):
log.debug('creating %s("%s")' % (_test.__name__, selector))

if all((hasattr(i, '__iter__') for i in (selection, output))):
self.assertItemsEqual(
if sys.version_info[0] >= 3:
method = self.assertCountEqual
else:
method = self.assertItemsEqual
method(
selection,
output,
msg=msg
Expand Down

0 comments on commit 08e5340

Please sign in to comment.