Permalink
Browse files

bashlex: add python 3 support

* __nonzero__ in Py3 is __bool__
* range returns an iterator instead of a list in Py3
* made imports more specific
* setuptools have different imports in Py2 and Py3
  • Loading branch information...
1 parent d73e6de commit 9462906a6c31de2e8d47b41a268ec97c4a0491b7 @blurrymoi blurrymoi committed with Nov 18, 2016
Showing with 9 additions and 4 deletions.
  1. +1 −1 bashlex/__init__.py
  2. +1 −1 bashlex/state.py
  3. +2 −0 bashlex/tokenizer.py
  4. +4 −1 setup.py
  5. +1 −1 tests/test-parser.py
View
@@ -1,4 +1,4 @@
-from . import parser, tokenizer
+from bashlex import parser, tokenizer
parse = parser.parse
parsesingle = parser.parsesingle
View
@@ -1,3 +1,3 @@
-from . import flags, utils
+from bashlex import flags, utils
parserstate = lambda: utils.typedset(flags.parser)
@@ -168,6 +168,8 @@ def type(self):
def __nonzero__(self):
return not (self.ttype is None and self.value is None)
+ __bool__ = __nonzero__
+
def __eq__(self, other):
return isinstance(other, token) and (self.type == other.type and
self.value == other.value and
View
@@ -1,4 +1,7 @@
-from setuptools import setup
+try:
+ from setuptools import setup #Py2
+except ImportError:
+ from distutils.core import setup #Py3
setup(
name='bashlex',
@@ -945,7 +945,7 @@ def __init__(self, *args, **kwargs):
parser._parser = old
s = 'a $(b $(c))'
- for i in [None] + range(2, 5):
+ for i in [None] + list(range(2, 5)):
self.assertASTEquals(s,
commandnode(s,
wordnode('a'),

0 comments on commit 9462906

Please sign in to comment.