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

Guido van Rossum guido at python.org
Fri Aug 10 16:45:45 CEST 2007


Style comment: it would have been better not to reuse the fname
variable for the encoded version; this may surprise the reader.

On 8/10/07, lars.gustaebel <python-3000-checkins at python.org> wrote:
> 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("")
> _______________________________________________
> Python-3000-checkins mailing list
> Python-3000-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-3000-checkins
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000-checkins mailing list