Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ead7056

Browse files
committed
Retouch my last change after a comment on style from Guido.
1 parent 0f98d8f commit ead7056

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

Lib/gzip.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,15 @@ def _init_write(self, filename):
149149
def _write_gzip_header(self):
150150
self.fileobj.write(b'\037\213') # magic header
151151
self.fileobj.write(b'\010') # compression method
152-
fname = self.name
153-
if fname.endswith(".gz"):
154-
fname = fname[:-3]
155-
flags = 0
156-
157-
# RFC 1952 requires the FNAME field to be Latin-1. Do not
158-
# include filenames that cannot be represented that way.
159152
try:
160-
fname = fname.encode('latin-1')
153+
# RFC 1952 requires the FNAME field to be Latin-1. Do not
154+
# include filenames that cannot be represented that way.
155+
fname = self.name.encode('latin-1')
156+
if fname.endswith(b'.gz'):
157+
fname = fname[:-3]
161158
except UnicodeEncodeError:
162-
fname = ''
163-
159+
fname = b''
160+
flags = 0
164161
if fname:
165162
flags = FNAME
166163
self.fileobj.write(chr(flags).encode('latin-1'))

0 commit comments

Comments
 (0)