|
2 | 2 |
|
3 | 3 | from __future__ import division, with_statement
|
4 | 4 |
|
5 |
| -import gzip |
| 5 | +from ...utils.compat import gzip as _astropy_gzip |
| 6 | +import gzip as _system_gzip |
6 | 7 | import mmap
|
7 | 8 | import os
|
8 | 9 | import tempfile
|
|
70 | 71 | GZIP_MAGIC = b('\x1f\x8b\x08')
|
71 | 72 | PKZIP_MAGIC = b('\x50\x4b\x03\x04')
|
72 | 73 |
|
| 74 | +_GZIP_FILE_TYPES = (_astropy_gzip, _system_gzip) |
73 | 75 |
|
74 | 76 | class _File(object):
|
75 | 77 | """
|
@@ -152,7 +154,7 @@ def __init__(self, fileobj=None, mode=None, memmap=False, clobber=False):
|
152 | 154 |
|
153 | 155 | self.fileobj_mode = fileobj_mode(self.__file)
|
154 | 156 |
|
155 |
| - if isinstance(fileobj, gzip.GzipFile): |
| 157 | + if isinstance(fileobj, (_astropy_gzip.GzipFile, _system_gzip.GzipFile)): |
156 | 158 | self.compression = 'gzip'
|
157 | 159 | elif isinstance(fileobj, zipfile.ZipFile):
|
158 | 160 | # Reading from zip files is supported but not writing (yet)
|
@@ -297,7 +299,7 @@ def seek(self, offset, whence=0):
|
297 | 299 | # present, we implement our own support for it here
|
298 | 300 | if not hasattr(self.__file, 'seek'):
|
299 | 301 | return
|
300 |
| - if isinstance(self.__file, gzip.GzipFile): |
| 302 | + if isinstance(self.__file, (_astropy_gzip.GzipFile, _system_gzip.GzipFile)): |
301 | 303 | if whence:
|
302 | 304 | if whence == 1:
|
303 | 305 | offset = self.__file.offset + offset
|
@@ -379,7 +381,7 @@ def _open_fileobj(self, fileobj, mode, clobber):
|
379 | 381 | elif isfile(fileobj):
|
380 | 382 | self.__file = fileobj_open(self.name, PYFITS_MODES[mode])
|
381 | 383 | else:
|
382 |
| - self.__file = gzip.open(self.name, PYFITS_MODES[mode]) |
| 384 | + self.__file = _astropy_gzip.open(self.name, PYFITS_MODES[mode]) |
383 | 385 |
|
384 | 386 | if fmode == 'ab+':
|
385 | 387 | # Return to the beginning of the file--in Python 3 when opening in
|
@@ -443,7 +445,7 @@ def _open_filename(self, filename, mode, clobber):
|
443 | 445 |
|
444 | 446 | if ext == '.gz' or magic.startswith(GZIP_MAGIC):
|
445 | 447 | # Handle gzip files
|
446 |
| - self.__file = gzip.open(self.name, PYFITS_MODES[mode]) |
| 448 | + self.__file = _astropy_gzip.open(self.name, PYFITS_MODES[mode]) |
447 | 449 | self.compression = 'gzip'
|
448 | 450 | elif ext == '.zip' or magic.startswith(PKZIP_MAGIC):
|
449 | 451 | # Handle zip files
|
@@ -534,4 +536,4 @@ def _is_random_access_file_backed(fileobj):
|
534 | 536 | from an already opened `zipfile.ZipFile` object.
|
535 | 537 | """
|
536 | 538 |
|
537 |
| - return isfile(fileobj) or isinstance(fileobj, gzip.GzipFile) |
| 539 | + return isfile(fileobj) or isinstance(fileobj, (_astropy_gzip.GzipFile, _system_gzip.GzipFile)) |
0 commit comments