changeset 30:f17f19d9eb0a

hasattr -> try in the newly added 2.6 zipfile
author Oleg Oshmyan <chortos@inbox.lv>
date Wed, 24 Nov 2010 23:42:06 +0000
parents a8cc383b787c
children fe1463e7e24d
files 2.00/zipfile26.py 2.00/zipfile266.diff
diffstat 2 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/2.00/zipfile26.py	Wed Nov 24 23:21:31 2010 +0000
+++ b/2.00/zipfile26.py	Wed Nov 24 23:42:06 2010 +0000
@@ -625,8 +625,10 @@
                         # we're out of raw bytes (both from the file and
                         # the local buffer); flush just to make sure the
                         # decompressor is done
-                        if hasattr(self.dc, 'flush'):
+                        try:
                             newdata += self.dc.flush()
+                        except AttributeError:
+                            pass
                         # prevent decompressor from being used again
                         self.dc = None
 
--- a/2.00/zipfile266.diff	Wed Nov 24 23:21:31 2010 +0000
+++ b/2.00/zipfile266.diff	Wed Nov 24 23:42:06 2010 +0000
@@ -1,5 +1,5 @@
 --- /usr/lib/python2.6/zipfile.py	2010-07-05 14:48:38.000000000 +0300
-+++ zipfile.py	2010-08-05 03:51:16.062274000 +0300
++++ zipfile.py	2010-11-25 01:39:22.749743303 +0200
 @@ -1,6 +1,7 @@
  """
  Read and write ZIP files.
@@ -50,7 +50,7 @@
                  if len(self.readbuffer) > size:
                      # the user has requested fewer bytes than we've already
                      # pulled through the decompressor; don't read any more
-@@ -608,14 +618,15 @@
+@@ -608,14 +618,17 @@
                      newdata = ''.join(map(self.decrypter, newdata))
  
                  # decompress newly read data if necessary
@@ -64,12 +64,14 @@
                          # the local buffer); flush just to make sure the
                          # decompressor is done
 -                        newdata += self.dc.flush()
-+                        if hasattr(self.dc, 'flush'):
++                        try:
 +                            newdata += self.dc.flush()
++                        except AttributeError:
++                            pass
                          # prevent decompressor from being used again
                          self.dc = None
  
-@@ -641,7 +652,8 @@
+@@ -641,7 +654,8 @@
      file: Either the path to the file, or a file-like object.
            If it is a path, the file will be opened and closed by ZipFile.
      mode: The mode can be either read "r", write "w" or append "a".
@@ -79,7 +81,7 @@
      allowZip64: if True ZipFile will create files with ZIP64 extensions when
                  needed, otherwise it will raise an exception when this would
                  be necessary.
-@@ -661,6 +673,10 @@
+@@ -661,6 +675,10 @@
              if not zlib:
                  raise RuntimeError,\
                        "Compression requires the (missing) zlib module"
@@ -90,7 +92,7 @@
          else:
              raise RuntimeError, "That compression method is not supported"
  
-@@ -987,7 +1003,10 @@
+@@ -987,7 +1005,10 @@
          if zinfo.compress_type == ZIP_DEFLATED and not zlib:
              raise RuntimeError, \
                    "Compression requires the (missing) zlib module"
@@ -102,7 +104,7 @@
              raise RuntimeError, \
                    "That compression method is not supported"
          if zinfo.file_size > ZIP64_LIMIT:
-@@ -1048,6 +1067,8 @@
+@@ -1048,6 +1069,8 @@
          if zinfo.compress_type == ZIP_DEFLATED:
              cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
                   zlib.DEFLATED, -15)
@@ -111,7 +113,7 @@
          else:
              cmpr = None
          while 1:
-@@ -1105,6 +1126,10 @@
+@@ -1105,6 +1128,10 @@
                   zlib.DEFLATED, -15)
              bytes = co.compress(bytes) + co.flush()
              zinfo.compress_size = len(bytes)    # Compressed size