/usr/lib/python3/dist-packages/dask/compatibility.py is in python3-dask 0.16.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | # flake8: noqa
from __future__ import absolute_import, division, print_function
import functools
import inspect
import operator
import sys
import types
PY3 = sys.version_info[0] == 3
PY2 = sys.version_info[0] == 2
class LZMAFile:
def __init__(self, *args, **kwargs):
raise ValueError("xz files requires the lzma module. "
"To use, install lzmaffi or backports.lzma.")
LZMA_AVAILABLE = False
if PY3:
import builtins
from queue import Queue, Empty
from itertools import zip_longest
from io import StringIO, BytesIO
from bz2 import BZ2File
from gzip import (GzipFile, compress as gzip_compress,
decompress as gzip_decompress)
try:
try:
from lzmaffi import (LZMAFile, compress as lzma_compress,
decompress as lzma_decompress)
except ImportError:
from lzma import (LZMAFile, compress as lzma_compress,
decompress as lzma_decompress)
LZMA_AVAILABLE = True
except ImportError:
# Fallback to top-level definition
pass
from urllib.request import urlopen
from urllib.parse import urlparse, urlsplit, quote, unquote
FileNotFoundError = FileNotFoundError
unicode = str
long = int
zip = zip
def apply(func, args, kwargs=None):
if kwargs:
return func(*args, **kwargs)
else:
return func(*args)
range = range
reduce = functools.reduce
operator_div = operator.truediv
def _getargspec(func):
return inspect.getfullargspec(func)
def reraise(exc, tb=None):
if exc.__traceback__ is not tb:
raise exc.with_traceback(tb)
raise exc
else:
import __builtin__ as builtins
from Queue import Queue, Empty
from itertools import izip_longest as zip_longest, izip as zip
from StringIO import StringIO
from io import BytesIO, BufferedIOBase
import bz2
import gzip
from urllib2 import urlopen
from urlparse import urlparse, urlsplit
from urllib import quote, unquote
unicode = unicode
long = long
apply = apply
range = xrange
reduce = reduce
operator_div = operator.div
FileNotFoundError = IOError
def _make_reraise():
_code = ("def reraise(exc, tb=None):"
" raise type(exc), exc, tb")
namespace = {}
exec("exec _code in namespace")
return namespace['reraise']
reraise = _make_reraise()
del _make_reraise
def _getargspec(func):
return inspect.getargspec(func)
def gzip_decompress(b):
f = gzip.GzipFile(fileobj=BytesIO(b))
result = f.read()
f.close()
return result
def gzip_compress(b):
bio = BytesIO()
f = gzip.GzipFile(fileobj=bio, mode='w')
f.write(b)
f.close()
bio.seek(0)
result = bio.read()
return result
if sys.version_info[1] <= 7:
class BZ2File(BufferedIOBase):
def __init__(self, *args, **kwargs):
self.__obj = bz2.BZ2File(*args, **kwargs)
def close(self):
return self.__obj.close()
@property
def closed(self):
return self.__obj.closed
def flush(self):
pass
def isatty(self):
return self.__obj.isatty()
def read(self, *args, **kwargs):
return self.__obj.read(*args, **kwargs)
def read1(self, *args, **kwargs):
return self.__obj.read(*args, **kwargs)
def readable(self):
return 'r' in self.__obj.mode
def readline(self, *args, **kwargs):
return self.__obj.readline(*args, **kwargs)
def readlines(self, *args, **kwargs):
return self.__obj.readlines(*args, **kwargs)
def seek(self, *args, **kwargs):
self.__obj.seek(*args, **kwargs)
return self.tell()
def seekable(self):
return self.readable()
def tell(self):
return self.__obj.tell()
def truncate(self, *args, **kwargs):
return self.__obj.truncate(*args, **kwargs)
def writable(self):
return 'w' in self.__obj.mode
def write(self, *args, **kwargs):
return self.__obj.write(*args, **kwargs)
def writelines(self, *args, **kwargs):
return self.__obj.writelines(*args, **kwargs)
else:
BZ2File = bz2.BZ2File
class GzipFile(BufferedIOBase):
def __init__(self, *args, **kwargs):
self.__obj = gzip.GzipFile(*args, **kwargs)
def close(self):
return self.__obj.close()
@property
def closed(self):
return self.__obj.fileobj is None
def flush(self, *args, **kwargs):
return self.__obj.flush(*args, **kwargs)
def isatty(self):
return self.__obj.isatty()
def read(self, *args, **kwargs):
return self.__obj.read(*args, **kwargs)
def read1(self, *args, **kwargs):
return self.__obj.read(*args, **kwargs)
def readable(self):
return self.__obj.mode == gzip.READ
def readline(self, *args, **kwargs):
return self.__obj.readline(*args, **kwargs)
def readlines(self, *args, **kwargs):
return self.__obj.readlines(*args, **kwargs)
def seek(self, *args, **kwargs):
self.__obj.seek(*args, **kwargs)
return self.tell()
def seekable(self):
# See https://hg.python.org/cpython/file/2.7/Lib/gzip.py#l421
return True
def tell(self):
return self.__obj.tell()
def truncate(self, *args, **kwargs):
return self.__obj.truncate(*args, **kwargs)
def writable(self):
return self.__obj.mode == gzip.WRITE
def write(self, *args, **kwargs):
return self.__obj.write(*args, **kwargs)
def writelines(self, *args, **kwargs):
return self.__obj.writelines(*args, **kwargs)
try:
try:
from lzmaffi import (LZMAFile, compress as lzma_compress,
decompress as lzma_decompress)
except ImportError:
from backports.lzma import LZMAFile
from backports.lzma import (LZMAFile, compress as lzma_compress,
decompress as lzma_decompress)
LZMA_AVAILABLE = True
except ImportError:
# Fallback to top-level definition
pass
def getargspec(func):
"""Version of inspect.getargspec that works for functools.partial objects"""
if isinstance(func, functools.partial):
return _getargspec(func.func)
else:
if isinstance(func, type):
return _getargspec(func.__init__)
else:
return _getargspec(func)
def bind_method(cls, name, func):
"""Bind a method to class
Parameters
----------
cls : type
class to receive bound method
name : basestring
name of method on class instance
func : function
function to be bound as method
Returns
-------
None
"""
# only python 2 has bound/unbound method issue
if not PY3:
setattr(cls, name, types.MethodType(func, None, cls))
else:
setattr(cls, name, func)
|