summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2007-08-13 09:05:16 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2007-08-13 09:05:16 (GMT)
commitead70565fcb59b920992021a2cd43f4687e207cb (patch)
tree80c14c7173f6f575343a09d303dfceec5395b2a3 /Lib/gzip.py
parent0f98d8f8ead113933b569f2fce74229e4561f9cf (diff)
downloadcpython-ead70565fcb59b920992021a2cd43f4687e207cb.zip
cpython-ead70565fcb59b920992021a2cd43f4687e207cb.tar.gz
cpython-ead70565fcb59b920992021a2cd43f4687e207cb.tar.bz2
Retouch my last change after a comment on style from Guido.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index e7f6737..73bc550 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -149,18 +149,15 @@ class GzipFile:
def _write_gzip_header(self):
self.fileobj.write(b'\037\213') # magic header
self.fileobj.write(b'\010') # compression method
- fname = self.name
- if fname.endswith(".gz"):
- fname = fname[:-3]
- flags = 0
-
- # RFC 1952 requires the FNAME field to be Latin-1. Do not
- # include filenames that cannot be represented that way.
try:
- fname = fname.encode('latin-1')
+ # RFC 1952 requires the FNAME field to be Latin-1. Do not
+ # include filenames that cannot be represented that way.
+ fname = self.name.encode('latin-1')
+ if fname.endswith(b'.gz'):
+ fname = fname[:-3]
except UnicodeEncodeError:
- fname = ''
-
+ fname = b''
+ flags = 0
if fname:
flags = FNAME
self.fileobj.write(chr(flags).encode('latin-1'))