switch compat to special-case py2

This commit is contained in:
Michael Merickel
2016-01-15 20:17:56 -06:00
parent d59c27652c
commit 57c377a097

View File

@@ -1,13 +1,14 @@
import sys
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
if PY3: # pragma: no cover
string_types = str,
text_type = str
else: # pragma: no cover
if PY2:
string_types = basestring,
text_type = unicode
else:
string_types = str,
text_type = str
def text_(s, encoding='latin-1', errors='strict'):
""" If ``s`` is an instance of ``bytes``, return ``s.decode(encoding,
@@ -16,14 +17,14 @@ def text_(s, encoding='latin-1', errors='strict'):
return s.decode(encoding, errors)
return s # pragma: no cover
if PY3: # pragma: no cover
if PY2:
def is_nonstr_iter(v):
return hasattr(v, '__iter__')
else:
def is_nonstr_iter(v):
if isinstance(v, str):
return False
return hasattr(v, '__iter__')
else: # pragma: no cover
def is_nonstr_iter(v):
return hasattr(v, '__iter__')
try:
xrange = xrange