aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2012-06-20 01:35:22 +0200
committerNadeem Vawda <nadeem.vawda@gmail.com>2012-06-20 01:35:22 +0200
commit103e8113e4bb4ad3687d641f660481c72904d571 (patch)
tree6cbac120aa945c22821830b42077fa933d486431 /Lib/gzip.py
parentIssue #15101: Make pool finalizer avoid joining current thread. (diff)
downloadcpython-103e8113e4bb4ad3687d641f660481c72904d571.tar.gz
cpython-103e8113e4bb4ad3687d641f660481c72904d571.tar.bz2
cpython-103e8113e4bb4ad3687d641f660481c72904d571.zip
Fix GzipFile's handling of filenames given as bytes objects.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 1de23b6972f..ee45e50ffba 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -159,9 +159,8 @@ 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') and isinstance(fileobj.name, str):
- filename = fileobj.name
- else:
+ filename = getattr(fileobj, 'name', '')
+ if not isinstance(filename, (str, bytes)):
filename = ''
if mode is None:
if hasattr(fileobj, 'mode'): mode = fileobj.mode
@@ -236,7 +235,8 @@ class GzipFile(io.BufferedIOBase):
# RFC 1952 requires the FNAME field to be Latin-1. Do not
# include filenames that cannot be represented that way.
fname = os.path.basename(self.name)
- fname = fname.encode('latin-1')
+ if not isinstance(fname, bytes):
+ fname = fname.encode('latin-1')
if fname.endswith(b'.gz'):
fname = fname[:-3]
except UnicodeEncodeError: