We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error requirements starting dask-scheduler on HPC cluster
Hi
I installed dask on python3 via pip3 on HPC node. when I run the scheduler I get the following error:

File "/home/x_simco/test/lib/python3.4/site-packages/dask/compatibility.py", line 23, in <module>
    from lzmaffi import (LZMAFile, compress as lzma_compress,
ImportError: No module named 'lzmaffi'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/x_simco/test/bin/dask-scheduler", line 7, in <module>
    from distributed.cli.dask_scheduler import go
  File "/home/x_simco/test/lib/python3.4/site-packages/distributed/**init**.py", line 3, in <module>
    from .center import Center
  File "/home/x_simco/test/lib/python3.4/site-packages/distributed/center.py", line 13, in <module>
    from .core import (Server, read, write, rpc, pingpong, send_recv,
  File "/home/x_simco/test/lib/python3.4/site-packages/distributed/core.py", line 26, in <module>
    from .utils import get_traceback, truncate_exception, ignoring
  File "/home/x_simco/test/lib/python3.4/site-packages/distributed/utils.py", line 15, in <module>
    from dask import istask
  File "/home/x_simco/test/lib/python3.4/site-packages/dask/**init**.py", line 5, in <module>
    from .async import get_sync as get
  File "/home/x_simco/test/lib/python3.4/site-packages/dask/async.py", line 126, in <module>
    from .optimize import cull
  File "/home/x_simco/test/lib/python3.4/site-packages/dask/optimize.py", line 6, in <module>
    from .compatibility import zip_longest
  File "/home/x_simco/test/lib/python3.4/site-packages/dask/compatibility.py", line 26, in <module>
    from lzma import (LZMAFile, compress as lzma_compress,
  File "/software/apps/python/3.4.1/snic-1/lib/python3.4/lzma.py", line 26, in <module>
    from _lzma import *


--- END ISSUE ---

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

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/dask/compatibility.py b/dask/compatibility.py
--- a/dask/compatibility.py
+++ b/dask/compatibility.py
@@ -9,7 +9,11 @@
 PY3 = sys.version_info[0] == 3
 PY2 = sys.version_info[0] == 2
 
-LZMA_AVAILABLE = True
+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
@@ -20,11 +24,17 @@
     from gzip import (GzipFile, compress as gzip_compress,
             decompress as gzip_decompress)
     try:
-        from lzmaffi import (LZMAFile, compress as lzma_compress,
-                             decompress as lzma_decompress)
+        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:
-        from lzma import (LZMAFile, compress as lzma_compress,
-                          decompress as lzma_decompress)
+        # Fallback to top-level definition
+        pass
+
     from urllib.request import urlopen
     from urllib.parse import urlparse
     from urllib.parse import quote, unquote
@@ -204,12 +214,10 @@
             from backports.lzma import LZMAFile
             from backports.lzma import (LZMAFile, compress as lzma_compress,
                                         decompress as lzma_decompress)
+        LZMA_AVAILABLE = True
     except ImportError:
-        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
+        # Fallback to top-level definition
+        pass
 
 
 def getargspec(func):

{"golden_diff": "diff --git a/dask/compatibility.py b/dask/compatibility.py\n--- a/dask/compatibility.py\n+++ b/dask/compatibility.py\n@@ -9,7 +9,11 @@\n PY3 = sys.version_info[0] == 3\n PY2 = sys.version_info[0] == 2\n \n-LZMA_AVAILABLE = True\n+class LZMAFile:\n+    def __init__(self, *args, **kwargs):\n+        raise ValueError(\"xz files requires the lzma module. \"\n+                            \"To use, install lzmaffi or backports.lzma.\")\n+LZMA_AVAILABLE = False\n \n if PY3:\n     import builtins\n@@ -20,11 +24,17 @@\n     from gzip import (GzipFile, compress as gzip_compress,\n             decompress as gzip_decompress)\n     try:\n-        from lzmaffi import (LZMAFile, compress as lzma_compress,\n-                             decompress as lzma_decompress)\n+        try:\n+            from lzmaffi import (LZMAFile, compress as lzma_compress,\n+                                 decompress as lzma_decompress)\n+        except ImportError:\n+            from lzma import (LZMAFile, compress as lzma_compress,\n+                              decompress as lzma_decompress)\n+        LZMA_AVAILABLE = True\n     except ImportError:\n-        from lzma import (LZMAFile, compress as lzma_compress,\n-                          decompress as lzma_decompress)\n+        # Fallback to top-level definition\n+        pass\n+\n     from urllib.request import urlopen\n     from urllib.parse import urlparse\n     from urllib.parse import quote, unquote\n@@ -204,12 +214,10 @@\n             from backports.lzma import LZMAFile\n             from backports.lzma import (LZMAFile, compress as lzma_compress,\n                                         decompress as lzma_decompress)\n+        LZMA_AVAILABLE = True\n     except ImportError:\n-        class LZMAFile:\n-            def __init__(self, *args, **kwargs):\n-                raise ValueError(\"xz files requires the lzma module. \"\n-                                 \"To use, install lzmaffi or backports.lzma.\")\n-        LZMA_AVAILABLE = False\n+        # Fallback to top-level definition\n+        pass\n \n \n def getargspec(func):\n", "issue": "Error requirements starting dask-scheduler on HPC cluster\nHi\nI installed dask on python3 via pip3 on HPC node. when I run the scheduler I get the following error:\n\nFile \"/home/x_simco/test/lib/python3.4/site-packages/dask/compatibility.py\", line 23, in <module>\n    from lzmaffi import (LZMAFile, compress as lzma_compress,\nImportError: No module named 'lzmaffi'\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/home/x_simco/test/bin/dask-scheduler\", line 7, in <module>\n    from distributed.cli.dask_scheduler import go\n  File \"/home/x_simco/test/lib/python3.4/site-packages/distributed/**init**.py\", line 3, in <module>\n    from .center import Center\n  File \"/home/x_simco/test/lib/python3.4/site-packages/distributed/center.py\", line 13, in <module>\n    from .core import (Server, read, write, rpc, pingpong, send_recv,\n  File \"/home/x_simco/test/lib/python3.4/site-packages/distributed/core.py\", line 26, in <module>\n    from .utils import get_traceback, truncate_exception, ignoring\n  File \"/home/x_simco/test/lib/python3.4/site-packages/distributed/utils.py\", line 15, in <module>\n    from dask import istask\n  File \"/home/x_simco/test/lib/python3.4/site-packages/dask/**init**.py\", line 5, in <module>\n    from .async import get_sync as get\n  File \"/home/x_simco/test/lib/python3.4/site-packages/dask/async.py\", line 126, in <module>\n    from .optimize import cull\n  File \"/home/x_simco/test/lib/python3.4/site-packages/dask/optimize.py\", line 6, in <module>\n    from .compatibility import zip_longest\n  File \"/home/x_simco/test/lib/python3.4/site-packages/dask/compatibility.py\", line 26, in <module>\n    from lzma import (LZMAFile, compress as lzma_compress,\n  File \"/software/apps/python/3.4.1/snic-1/lib/python3.4/lzma.py\", line 26, in <module>\n    from _lzma import *\n\n", "before_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport functools\nimport inspect\nimport operator\nimport sys\nimport types\n\nPY3 = sys.version_info[0] == 3\nPY2 = sys.version_info[0] == 2\n\nLZMA_AVAILABLE = True\n\nif PY3:\n    import builtins\n    from queue import Queue, Empty\n    from itertools import zip_longest\n    from io import StringIO, BytesIO\n    from bz2 import BZ2File\n    from gzip import (GzipFile, compress as gzip_compress,\n            decompress as gzip_decompress)\n    try:\n        from lzmaffi import (LZMAFile, compress as lzma_compress,\n                             decompress as lzma_decompress)\n    except ImportError:\n        from lzma import (LZMAFile, compress as lzma_compress,\n                          decompress as lzma_decompress)\n    from urllib.request import urlopen\n    from urllib.parse import urlparse\n    from urllib.parse import quote, unquote\n    FileNotFoundError = FileNotFoundError\n    unicode = str\n    long = int\n    zip = zip\n    def apply(func, args, kwargs=None):\n        if kwargs:\n            return func(*args, **kwargs)\n        else:\n            return func(*args)\n    range = range\n    reduce = functools.reduce\n    operator_div = operator.truediv\n\n    def _getargspec(func):\n        return inspect.getfullargspec(func)\n\nelse:\n    import __builtin__ as builtins\n    from Queue import Queue, Empty\n    from itertools import izip_longest as zip_longest, izip as zip\n    from StringIO import StringIO\n    from io import BytesIO, BufferedIOBase\n    import bz2\n    import gzip\n    from urllib2 import urlopen\n    from urlparse import urlparse\n    from urllib import quote, unquote\n    unicode = unicode\n    long = long\n    apply = apply\n    range = xrange\n    reduce = reduce\n    operator_div = operator.div\n    FileNotFoundError = IOError\n\n    def _getargspec(func):\n        return inspect.getargspec(func)\n\n    def gzip_decompress(b):\n        f = gzip.GzipFile(fileobj=BytesIO(b))\n        result = f.read()\n        f.close()\n        return result\n\n    def gzip_compress(b):\n        bio = BytesIO()\n        f = gzip.GzipFile(fileobj=bio, mode='w')\n        f.write(b)\n        f.close()\n        bio.seek(0)\n        result = bio.read()\n        return result\n\n    if sys.version_info[1] <= 7:\n        class BZ2File(BufferedIOBase):\n            def __init__(self, *args, **kwargs):\n                self.__obj = bz2.BZ2File(*args, **kwargs)\n\n            def close(self):\n                return self.__obj.close()\n\n            @property\n            def closed(self):\n                return self.__obj.closed\n\n            def flush(self):\n                pass\n\n            def isatty(self):\n                return self.__obj.isatty()\n\n            def read(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def read1(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def readable(self):\n                return 'r' in self.__obj.mode\n\n            def readline(self, *args, **kwargs):\n                return self.__obj.readline(*args, **kwargs)\n\n            def readlines(self, *args, **kwargs):\n                return self.__obj.readlines(*args, **kwargs)\n\n            def seek(self, *args, **kwargs):\n                self.__obj.seek(*args, **kwargs)\n                return self.tell()\n\n            def seekable(self):\n                return self.readable()\n\n            def tell(self):\n                return self.__obj.tell()\n\n            def truncate(self, *args, **kwargs):\n                return self.__obj.truncate(*args, **kwargs)\n\n            def writable(self):\n                return 'w' in self.__obj.mode\n\n            def write(self, *args, **kwargs):\n                return self.__obj.write(*args, **kwargs)\n\n            def writelines(self, *args, **kwargs):\n                return self.__obj.writelines(*args, **kwargs)\n    else:\n        BZ2File = bz2.BZ2File\n\n    if sys.version_info[1] <= 6:\n        class GzipFile(BufferedIOBase):\n            def __init__(self, *args, **kwargs):\n                self.__obj = gzip.GzipFile(*args, **kwargs)\n\n            def close(self):\n                return self.__obj.close()\n\n            @property\n            def closed(self):\n                return self.__obj.fileobj is None\n\n            def flush(self, *args, **kwargs):\n                return self.__obj.flush(*args, **kwargs)\n\n            def isatty(self):\n                return self.__obj.isatty()\n\n            def read(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def read1(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def readable(self):\n                return self.__obj.mode == gzip.READ\n\n            def readline(self, *args, **kwargs):\n                return self.__obj.readline(*args, **kwargs)\n\n            def readlines(self, *args, **kwargs):\n                return self.__obj.readlines(*args, **kwargs)\n\n            def seek(self, *args, **kwargs):\n                self.__obj.seek(*args, **kwargs)\n                return self.tell()\n\n            def seekable(self):\n                # See https://hg.python.org/cpython/file/2.7/Lib/gzip.py#l421\n                return True\n\n            def tell(self):\n                return self.__obj.tell()\n\n            def truncate(self, *args, **kwargs):\n                return self.__obj.truncate(*args, **kwargs)\n\n            def writable(self):\n                return self.__obj.mode == gzip.WRITE\n\n            def write(self, *args, **kwargs):\n                return self.__obj.write(*args, **kwargs)\n\n            def writelines(self, *args, **kwargs):\n                return self.__obj.writelines(*args, **kwargs)\n    else:\n        GzipFile = gzip.GzipFile\n\n    try:\n        try:\n            from lzmaffi import (LZMAFile, compress as lzma_compress,\n                                 decompress as lzma_decompress)\n        except ImportError:\n            from backports.lzma import LZMAFile\n            from backports.lzma import (LZMAFile, compress as lzma_compress,\n                                        decompress as lzma_decompress)\n    except ImportError:\n        class LZMAFile:\n            def __init__(self, *args, **kwargs):\n                raise ValueError(\"xz files requires the lzma module. \"\n                                 \"To use, install lzmaffi or backports.lzma.\")\n        LZMA_AVAILABLE = False\n\n\ndef getargspec(func):\n    \"\"\"Version of inspect.getargspec that works for functools.partial objects\"\"\"\n    if isinstance(func, functools.partial):\n        return _getargspec(func.func)\n    else:\n        if isinstance(func, type):\n            return _getargspec(func.__init__)\n        else:\n            return _getargspec(func)\n\ndef skip(func):\n    return\n\n\ndef bind_method(cls, name, func):\n    \"\"\"Bind a method to class\n\n    Parameters\n    ----------\n\n    cls : type\n        class to receive bound method\n    name : basestring\n        name of method on class instance\n    func : function\n        function to be bound as method\n\n    Returns\n    -------\n    None\n    \"\"\"\n    # only python 2 has bound/unbound method issue\n    if not PY3:\n        setattr(cls, name, types.MethodType(func, None, cls))\n    else:\n        setattr(cls, name, func)\n", "path": "dask/compatibility.py"}], "after_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport functools\nimport inspect\nimport operator\nimport sys\nimport types\n\nPY3 = sys.version_info[0] == 3\nPY2 = sys.version_info[0] == 2\n\nclass LZMAFile:\n    def __init__(self, *args, **kwargs):\n        raise ValueError(\"xz files requires the lzma module. \"\n                            \"To use, install lzmaffi or backports.lzma.\")\nLZMA_AVAILABLE = False\n\nif PY3:\n    import builtins\n    from queue import Queue, Empty\n    from itertools import zip_longest\n    from io import StringIO, BytesIO\n    from bz2 import BZ2File\n    from gzip import (GzipFile, compress as gzip_compress,\n            decompress as gzip_decompress)\n    try:\n        try:\n            from lzmaffi import (LZMAFile, compress as lzma_compress,\n                                 decompress as lzma_decompress)\n        except ImportError:\n            from lzma import (LZMAFile, compress as lzma_compress,\n                              decompress as lzma_decompress)\n        LZMA_AVAILABLE = True\n    except ImportError:\n        # Fallback to top-level definition\n        pass\n\n    from urllib.request import urlopen\n    from urllib.parse import urlparse\n    from urllib.parse import quote, unquote\n    FileNotFoundError = FileNotFoundError\n    unicode = str\n    long = int\n    zip = zip\n    def apply(func, args, kwargs=None):\n        if kwargs:\n            return func(*args, **kwargs)\n        else:\n            return func(*args)\n    range = range\n    reduce = functools.reduce\n    operator_div = operator.truediv\n\n    def _getargspec(func):\n        return inspect.getfullargspec(func)\n\nelse:\n    import __builtin__ as builtins\n    from Queue import Queue, Empty\n    from itertools import izip_longest as zip_longest, izip as zip\n    from StringIO import StringIO\n    from io import BytesIO, BufferedIOBase\n    import bz2\n    import gzip\n    from urllib2 import urlopen\n    from urlparse import urlparse\n    from urllib import quote, unquote\n    unicode = unicode\n    long = long\n    apply = apply\n    range = xrange\n    reduce = reduce\n    operator_div = operator.div\n    FileNotFoundError = IOError\n\n    def _getargspec(func):\n        return inspect.getargspec(func)\n\n    def gzip_decompress(b):\n        f = gzip.GzipFile(fileobj=BytesIO(b))\n        result = f.read()\n        f.close()\n        return result\n\n    def gzip_compress(b):\n        bio = BytesIO()\n        f = gzip.GzipFile(fileobj=bio, mode='w')\n        f.write(b)\n        f.close()\n        bio.seek(0)\n        result = bio.read()\n        return result\n\n    if sys.version_info[1] <= 7:\n        class BZ2File(BufferedIOBase):\n            def __init__(self, *args, **kwargs):\n                self.__obj = bz2.BZ2File(*args, **kwargs)\n\n            def close(self):\n                return self.__obj.close()\n\n            @property\n            def closed(self):\n                return self.__obj.closed\n\n            def flush(self):\n                pass\n\n            def isatty(self):\n                return self.__obj.isatty()\n\n            def read(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def read1(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def readable(self):\n                return 'r' in self.__obj.mode\n\n            def readline(self, *args, **kwargs):\n                return self.__obj.readline(*args, **kwargs)\n\n            def readlines(self, *args, **kwargs):\n                return self.__obj.readlines(*args, **kwargs)\n\n            def seek(self, *args, **kwargs):\n                self.__obj.seek(*args, **kwargs)\n                return self.tell()\n\n            def seekable(self):\n                return self.readable()\n\n            def tell(self):\n                return self.__obj.tell()\n\n            def truncate(self, *args, **kwargs):\n                return self.__obj.truncate(*args, **kwargs)\n\n            def writable(self):\n                return 'w' in self.__obj.mode\n\n            def write(self, *args, **kwargs):\n                return self.__obj.write(*args, **kwargs)\n\n            def writelines(self, *args, **kwargs):\n                return self.__obj.writelines(*args, **kwargs)\n    else:\n        BZ2File = bz2.BZ2File\n\n    if sys.version_info[1] <= 6:\n        class GzipFile(BufferedIOBase):\n            def __init__(self, *args, **kwargs):\n                self.__obj = gzip.GzipFile(*args, **kwargs)\n\n            def close(self):\n                return self.__obj.close()\n\n            @property\n            def closed(self):\n                return self.__obj.fileobj is None\n\n            def flush(self, *args, **kwargs):\n                return self.__obj.flush(*args, **kwargs)\n\n            def isatty(self):\n                return self.__obj.isatty()\n\n            def read(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def read1(self, *args, **kwargs):\n                return self.__obj.read(*args, **kwargs)\n\n            def readable(self):\n                return self.__obj.mode == gzip.READ\n\n            def readline(self, *args, **kwargs):\n                return self.__obj.readline(*args, **kwargs)\n\n            def readlines(self, *args, **kwargs):\n                return self.__obj.readlines(*args, **kwargs)\n\n            def seek(self, *args, **kwargs):\n                self.__obj.seek(*args, **kwargs)\n                return self.tell()\n\n            def seekable(self):\n                # See https://hg.python.org/cpython/file/2.7/Lib/gzip.py#l421\n                return True\n\n            def tell(self):\n                return self.__obj.tell()\n\n            def truncate(self, *args, **kwargs):\n                return self.__obj.truncate(*args, **kwargs)\n\n            def writable(self):\n                return self.__obj.mode == gzip.WRITE\n\n            def write(self, *args, **kwargs):\n                return self.__obj.write(*args, **kwargs)\n\n            def writelines(self, *args, **kwargs):\n                return self.__obj.writelines(*args, **kwargs)\n    else:\n        GzipFile = gzip.GzipFile\n\n    try:\n        try:\n            from lzmaffi import (LZMAFile, compress as lzma_compress,\n                                 decompress as lzma_decompress)\n        except ImportError:\n            from backports.lzma import LZMAFile\n            from backports.lzma import (LZMAFile, compress as lzma_compress,\n                                        decompress as lzma_decompress)\n        LZMA_AVAILABLE = True\n    except ImportError:\n        # Fallback to top-level definition\n        pass\n\n\ndef getargspec(func):\n    \"\"\"Version of inspect.getargspec that works for functools.partial objects\"\"\"\n    if isinstance(func, functools.partial):\n        return _getargspec(func.func)\n    else:\n        if isinstance(func, type):\n            return _getargspec(func.__init__)\n        else:\n            return _getargspec(func)\n\ndef skip(func):\n    return\n\n\ndef bind_method(cls, name, func):\n    \"\"\"Bind a method to class\n\n    Parameters\n    ----------\n\n    cls : type\n        class to receive bound method\n    name : basestring\n        name of method on class instance\n    func : function\n        function to be bound as method\n\n    Returns\n    -------\n    None\n    \"\"\"\n    # only python 2 has bound/unbound method issue\n    if not PY3:\n        setattr(cls, name, types.MethodType(func, None, cls))\n    else:\n        setattr(cls, name, func)\n", "path": "dask/compatibility.py"}]}