diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2007-08-10 12:02:32 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2007-08-10 12:02:32 (GMT) |
commit | 5590d8cc8af29f6d1ff2158ddbef0e457279c5f1 (patch) | |
tree | e37f7b1929475c09e52ba5136534dd46dac73896 /Lib | |
parent | 36f938fbdf66e414c8e0c743246dc306c6b9c452 (diff) | |
download | cpython-5590d8cc8af29f6d1ff2158ddbef0e457279c5f1.zip cpython-5590d8cc8af29f6d1ff2158ddbef0e457279c5f1.tar.gz cpython-5590d8cc8af29f6d1ff2158ddbef0e457279c5f1.tar.bz2 |
RFC 1952 requires the FNAME field to be Latin-1. Do not include
filenames that cannot be represented that way.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/gzip.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index b6cc80e..e7f6737 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -153,6 +153,14 @@ class GzipFile: 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') + except UnicodeEncodeError: + fname = '' + if fname: flags = FNAME self.fileobj.write(chr(flags).encode('latin-1')) @@ -160,8 +168,7 @@ class GzipFile: self.fileobj.write(b'\002') self.fileobj.write(b'\377') if fname: - # XXX: Ist utf-8 the correct encoding? - self.fileobj.write(fname.encode('utf-8') + b'\000') + self.fileobj.write(fname + b'\000') def _init_read(self): self.crc = zlib.crc32("") |