[Python-3000-checkins] r56896 - python/branches/py3k/Lib/gzip.py

lars.gustaebel python-3000-checkins at python.org
Fri Aug 10 14:02:33 CEST 2007


Author: lars.gustaebel
Date: Fri Aug 10 14:02:32 2007
New Revision: 56896

Modified:
   python/branches/py3k/Lib/gzip.py
Log:
RFC 1952 requires the FNAME field to be Latin-1. Do not include
filenames that cannot be represented that way.


Modified: python/branches/py3k/Lib/gzip.py
==============================================================================
--- python/branches/py3k/Lib/gzip.py	(original)
+++ python/branches/py3k/Lib/gzip.py	Fri Aug 10 14:02:32 2007
@@ -153,6 +153,14 @@
         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 @@
         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("")


More information about the Python-3000-checkins mailing list