summaryrefslogtreecommitdiff
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-01-19 00:40:46 +0200
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-01-19 00:40:46 +0200
commitd7664dee0c35c01e71fc0ea65d0b7547dfb0212a (patch)
treeb2e677ee3580ab47d9379de12b97603c09c3ec49 /Lib/gzip.py
parente09bc1e8f54620e938b7e076830b872a8daabd2c (diff)
downloadcpython-git-d7664dee0c35c01e71fc0ea65d0b7547dfb0212a.tar.gz
Issue #13781: Fix GzipFile to work with os.fdopen()'d file objects.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 2bcb4dbfb0..8fdac8397d 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -88,8 +88,12 @@ class GzipFile(io.BufferedIOBase):
if fileobj is None:
fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
if filename is None:
- if hasattr(fileobj, 'name'): filename = fileobj.name
- else: filename = ''
+ # Issue #13781: os.fdopen() creates a fileobj with a bogus name
+ # attribute. Avoid saving this in the gzip header's filename field.
+ if hasattr(fileobj, 'name') and fileobj.name != '<fdopen>':
+ filename = fileobj.name
+ else:
+ filename = ''
if mode is None:
if hasattr(fileobj, 'mode'): mode = fileobj.mode
else: mode = 'rb'