diff options
author | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-01-18 07:32:25 (GMT) |
---|---|---|
committer | Nadeem Vawda <nadeem.vawda@gmail.com> | 2012-01-18 07:32:25 (GMT) |
commit | 50a4d5debb952bb319d8a8141e47a39c3fb03250 (patch) | |
tree | 6d841af85219705d274635be1dba15dc9bb85b31 | |
parent | 5c1d814e6fc3fc154db288cab557106e72a53506 (diff) | |
parent | 892b0b928df40da72b0d88c5e1a2c879eff543c4 (diff) | |
download | cpython-50a4d5debb952bb319d8a8141e47a39c3fb03250.zip cpython-50a4d5debb952bb319d8a8141e47a39c3fb03250.tar.gz cpython-50a4d5debb952bb319d8a8141e47a39c3fb03250.tar.bz2 |
Merge: #13781: Fix GzipFile to work with os.fdopen()'d file objects.
-rw-r--r-- | Lib/gzip.py | 6 | ||||
-rw-r--r-- | Lib/test/test_gzip.py | 8 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 15 insertions, 2 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index e6b8193..93dda4e 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -144,8 +144,10 @@ class GzipFile(io.BufferedIOBase): if fileobj is None: fileobj = self.myfileobj = builtins.open(filename, mode or 'rb') if filename is None: - if hasattr(fileobj, 'name'): filename = fileobj.name - else: filename = '' + if hasattr(fileobj, 'name') and isinstance(fileobj.name, str): + filename = fileobj.name + else: + filename = '' if mode is None: if hasattr(fileobj, 'mode'): mode = fileobj.mode else: mode = 'rb' diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index 9c7a96e..d2b4871 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -346,6 +346,14 @@ class TestGzip(unittest.TestCase): with io.TextIOWrapper(f, encoding="ascii") as t: self.assertEqual(t.readlines(), lines) + def test_fileobj_from_fdopen(self): + # Issue #13781: Opening a GzipFile for writing fails when using a + # fileobj created with os.fdopen(). + fd = os.open(self.filename, os.O_WRONLY | os.O_CREAT) + with os.fdopen(fd, "wb") as f: + with gzip.GzipFile(fileobj=f, mode="w") as g: + pass + # Testing compress/decompress shortcut functions def test_compress(self): @@ -447,6 +447,9 @@ Core and Builtins Library ------- +- Issue #13781: Fix GzipFile bug that caused an exception to be raised when + opening for writing using a fileobj returned by os.fdopen(). + - Issue #13803: Under Solaris, distutils doesn't include bitness in the directory name. |