diff options
author | Yaroslav Halchenko <debian@onerussian.com> | 2012-07-02 19:00:14 -0400 |
---|---|---|
committer | Yaroslav Halchenko <debian@onerussian.com> | 2012-07-02 19:00:14 -0400 |
commit | 4219824f899d31a0fb205536bf1477d68bcc5d71 (patch) | |
tree | add886b775f49aff3751b4f668982acc88cbec46 /numpy/lib/npyio.py | |
parent | 0e3a3d96c7a8e522184c7ca0388cd9d401e902cd (diff) | |
download | numpy-4219824f899d31a0fb205536bf1477d68bcc5d71.tar.gz |
BF: PY3 and PY2 < 2.7 compatibility fixes for prev 2 commits
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index e16485ff0..b8564be03 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -2,9 +2,6 @@ __all__ = ['savetxt', 'loadtxt', 'genfromtxt', 'ndfromtxt', 'mafromtxt', 'recfromtxt', 'recfromcsv', 'load', 'loads', 'save', 'savez', 'savez_compressed', 'packbits', 'unpackbits', 'fromregex', 'DataSource'] -# Price to pay for overloading standard keywords -import __builtin__ - import numpy as np import format import sys @@ -25,13 +22,20 @@ from _iotools import LineSplitter, NameValidator, StringConverter, \ _is_string_like, has_nested_fields, flatten_dtype, \ easy_dtype, _bytes_to_name -from numpy.compat import asbytes, asstr, asbytes_nested, bytes +from numpy.compat import asbytes, asstr, asbytes_nested, bytes, isfileobj if sys.version_info[0] >= 3: from io import BytesIO else: from cStringIO import StringIO as BytesIO +if sys.version_info[:2] >= (2, 7): + def _isgzipclosed(f): + return f.closed +else: + def _isgzipclosed(f): + return getattr(f, 'myfileobj', None) is not None + _string_like = _is_string_like def seek_gzip_factory(f): @@ -362,9 +366,9 @@ def load(file, mmap_mode=None): elif isinstance(file, gzip.GzipFile): # we were provided an existing handle which we should close # only if it was closed already - own_fid = file.closed + own_fid = _isgzipclosed(file) fid = seek_gzip_factory(file) - elif isinstance(file, __builtin__.file): + elif isfileobj(file): own_fid = file.closed fid = file else: |