Skip to content

Commit

Permalink
Improve discoverability for Python 2 compatibility code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Mar 12, 2019
1 parent cb0670d commit acc057b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -57,6 +57,7 @@ def read(*rnames):
install_requires=[
'zope.interface',
'setuptools',
'six',
],
extras_require=dict(test=['zope.testing']),
)
4 changes: 2 additions & 2 deletions src/martian/compat3.py
@@ -1,4 +1,4 @@
import sys
import six
import types


Expand All @@ -8,7 +8,7 @@
CLASS_TYPES = (type,)


if sys.version_info[0] < 3:
if six.PY2:
str = unicode # NOQA
else:
str = str
3 changes: 2 additions & 1 deletion src/martian/directive.py
@@ -1,3 +1,4 @@
import six
import sys
import inspect

Expand Down Expand Up @@ -262,7 +263,7 @@ def __init__(self, *args, **kw):
# To get a correct error message, we construct a function that has
# the same signature as factory(), but without "self".
def check_factory_signature(self, *arguments, **kw):
if sys.version_info.major == 2:
if six.PY2:
(args, varargs, varkw, defaults) = inspect.getargspec(self.factory)
argspec = inspect.formatargspec(args[1:], varargs, varkw, defaults)
else:
Expand Down
3 changes: 2 additions & 1 deletion src/martian/testing.py
@@ -1,3 +1,4 @@
import six
import sys
from types import ModuleType
from types import FunctionType
Expand Down Expand Up @@ -65,7 +66,7 @@ def __init__(cls, classname, bases, dict_):
return type.__init__(cls, classname, bases, dict_)


if sys.version_info[0] < 3:
if six.PY2:

class FakeModuleObject(object):
pass
Expand Down
7 changes: 4 additions & 3 deletions src/martian/util.py
Expand Up @@ -15,6 +15,7 @@
"""

import re
import six
import sys
import inspect

Expand All @@ -26,15 +27,15 @@

def not_unicode_or_ascii(value):
# python3 compatibility
if sys.version_info < (3,) and isinstance(value, unicode): # NOQA
if six.PY2 and isinstance(value, unicode): # NOQA
return False
if not isinstance(value, str):
return True
return is_not_ascii(value)


# extra compatibility for python3.2
if sys.version_info < (3,):
# extra compatibility for python2.7
if six.PY2:
is_not_ascii = re.compile(eval(r'u"[\u0080-\uffff]"')).search
else:
is_not_ascii = re.compile(eval(r'"[\u0080-\uffff]"')).search
Expand Down

0 comments on commit acc057b

Please sign in to comment.