import sys
PY3 = sys.version_info[0] >= 3
if PY3: # pragma: no cover
basestring = str
unicode_type = str
bytes_type = bytes
def iteritems(d):
return iter(d.items())
def itervalues(d):
return iter(d.values())
range = range
zip = zip
from functools import reduce
import builtins
from urllib.request import urlretrieve
else: # pragma: no cover
# Python 2
basestring = basestring
unicode_type = unicode
bytes_type = str
def iteritems(d):
return d.iteritems()
def itervalues(d):
return d.itervalues()
range = xrange
from itertools import izip as zip, imap as map
reduce = reduce
import __builtin__ as builtins
from urllib import urlretrieve
try:
from cyordereddict import OrderedDict
except ImportError: # pragma: no cover
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
try:
# solely for isinstance checks
import dask.array
dask_array_type = (dask.array.Array,)
except ImportError: # pragma: no cover
dask_array_type = ()
try:
from contextlib import suppress
except ImportError:
# backport from Python 3.5:
class suppress:
"""Context manager to suppress specified exceptions
After the exception is suppressed, execution proceeds with the next
statement following the with statement.
with suppress(FileNotFoundError):
os.remove(somefile)
# Execution still resumes here if the file was already removed
"""
def __init__(self, *exceptions):
self._exceptions = exceptions
def __enter__(self):
pass
def __exit__(self, exctype, excinst, exctb):
# Unlike isinstance and issubclass, CPython exception handling
# currently only looks at the concrete type hierarchy (ignoring
# the instance and subclass checking hooks). While Guido considers
# that a bug rather than a feature, it's a fairly hard one to fix
# due to various internal implementation details. suppress provides
# the simpler issubclass based semantics, rather than trying to
# exactly reproduce the limitations of the CPython interpreter.
#
# See http://bugs.python.org/issue12029 for more details
return exctype is not None and issubclass(exctype, self._exceptions)
|