# HG changeset patch # User Oleg Oshmyan # Date 1308183850 -3600 # Node ID b993d9257400c4ad375447880a462ad256d579a6 # Parent d7f4b051ad79069278c5b3b98becef2ecfdef515 Updated zipfiles diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile266.diff --- a/zipfiles/zipfile266.diff Wed Jun 15 14:34:48 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ ---- /usr/lib/python2.6/zipfile.py 2010-07-05 14:48:38.000000000 +0300 -+++ zipfile.py 2010-11-25 01:39:22.749743303 +0200 -@@ -1,6 +1,7 @@ - """ - Read and write ZIP files. - """ -+# Improved by Chortos-2 in 2009 and 2010 (added bzip2 support) - import struct, os, time, sys, shutil - import binascii, cStringIO, stat - -@@ -11,8 +12,13 @@ - zlib = None - crc32 = binascii.crc32 - -+try: -+ import bz2 # We may need its compression method -+except ImportError: -+ bz2 = None -+ - __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", -- "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] -+ "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile", "ZIP_BZIP2" ] - - class BadZipfile(Exception): - pass -@@ -33,6 +39,7 @@ - # constants for Zip file compression methods - ZIP_STORED = 0 - ZIP_DEFLATED = 8 -+ZIP_BZIP2 = 12 - # Other ZIP compression methods not supported - - # Below are some formats and associated data for reading/writing headers using -@@ -467,6 +474,9 @@ - self.compreadsize = 64*1024 - if self.compress_type == ZIP_DEFLATED: - self.dc = zlib.decompressobj(-15) -+ elif self.compress_type == ZIP_BZIP2: -+ self.dc = bz2.BZ2Decompressor() -+ self.compreadsize = 900000 - - def set_univ_newlines(self, univ_newlines): - self.univ_newlines = univ_newlines -@@ -578,7 +588,7 @@ - if self.compress_type == ZIP_STORED: - lr = len(self.readbuffer) - bytesToRead = min(bytesToRead, size - lr) -- elif self.compress_type == ZIP_DEFLATED: -+ else: - 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,17 @@ - newdata = ''.join(map(self.decrypter, newdata)) - - # decompress newly read data if necessary -- if newdata and self.compress_type == ZIP_DEFLATED: -+ if newdata and self.compress_type != ZIP_STORED: - newdata = self.dc.decompress(newdata) -- self.rawbuffer = self.dc.unconsumed_tail -+ self.rawbuffer = self.dc.unconsumed_tail if self.compress_type == ZIP_DEFLATED else '' - if self.eof and len(self.rawbuffer) == 0: - # we're out of raw bytes (both from the file and - # the local buffer); flush just to make sure the - # decompressor is done -- newdata += self.dc.flush() -+ try: -+ newdata += self.dc.flush() -+ except AttributeError: -+ pass - # prevent decompressor from being used again - self.dc = None - -@@ -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". -- compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). -+ compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), -+ or ZIP_BZIP2 (requires bz2). - 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 +675,10 @@ - if not zlib: - raise RuntimeError,\ - "Compression requires the (missing) zlib module" -+ elif compression == ZIP_BZIP2: -+ if not bz2: -+ raise RuntimeError,\ -+ "Compression requires the (missing) bz2 module" - else: - raise RuntimeError, "That compression method is not supported" - -@@ -987,7 +1005,10 @@ - if zinfo.compress_type == ZIP_DEFLATED and not zlib: - raise RuntimeError, \ - "Compression requires the (missing) zlib module" -- if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): -+ if zinfo.compress_type == ZIP_BZIP2 and not bz2: -+ raise RuntimeError, \ -+ "Compression requires the (missing) bz2 module" -+ if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): - raise RuntimeError, \ - "That compression method is not supported" - if zinfo.file_size > ZIP64_LIMIT: -@@ -1048,6 +1069,8 @@ - if zinfo.compress_type == ZIP_DEFLATED: - cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, - zlib.DEFLATED, -15) -+ elif zinfo.compress_type == ZIP_BZIP2: -+ cmpr = bz2.BZ2Compressor() - else: - cmpr = None - while 1: -@@ -1105,6 +1128,10 @@ - zlib.DEFLATED, -15) - bytes = co.compress(bytes) + co.flush() - zinfo.compress_size = len(bytes) # Compressed size -+ elif zinfo.compress_type == ZIP_BZIP2: -+ co = bz2.BZ2Compressor() -+ bytes = co.compress(bytes) + co.flush() -+ zinfo.compress_size = len(bytes) # Compressed size - else: - zinfo.compress_size = zinfo.file_size - zinfo.header_offset = self.fp.tell() # Start of header bytes diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile267.diff --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zipfiles/zipfile267.diff Thu Jun 16 01:24:10 2011 +0100 @@ -0,0 +1,126 @@ +--- /usr/lib/python2.6/zipfile.py 2010-07-05 14:48:38.000000000 +0300 ++++ zipfile.py 2010-11-25 01:39:22.749743303 +0200 +@@ -1,6 +1,7 @@ + """ + Read and write ZIP files. + """ ++# Improved by Chortos-2 in 2009 and 2010 (added bzip2 support) + import struct, os, time, sys, shutil + import binascii, cStringIO, stat + +@@ -11,8 +12,13 @@ + zlib = None + crc32 = binascii.crc32 + ++try: ++ import bz2 # We may need its compression method ++except ImportError: ++ bz2 = None ++ + __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", +- "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] ++ "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile", "ZIP_BZIP2" ] + + class BadZipfile(Exception): + pass +@@ -33,6 +39,7 @@ + # constants for Zip file compression methods + ZIP_STORED = 0 + ZIP_DEFLATED = 8 ++ZIP_BZIP2 = 12 + # Other ZIP compression methods not supported + + # Below are some formats and associated data for reading/writing headers using +@@ -467,6 +474,9 @@ + self.compreadsize = 64*1024 + if self.compress_type == ZIP_DEFLATED: + self.dc = zlib.decompressobj(-15) ++ elif self.compress_type == ZIP_BZIP2: ++ self.dc = bz2.BZ2Decompressor() ++ self.compreadsize = 900000 + + def set_univ_newlines(self, univ_newlines): + self.univ_newlines = univ_newlines +@@ -578,7 +588,7 @@ + if self.compress_type == ZIP_STORED: + lr = len(self.readbuffer) + bytesToRead = min(bytesToRead, size - lr) +- elif self.compress_type == ZIP_DEFLATED: ++ else: + 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,17 @@ + newdata = ''.join(map(self.decrypter, newdata)) + + # decompress newly read data if necessary +- if newdata and self.compress_type == ZIP_DEFLATED: ++ if newdata and self.compress_type != ZIP_STORED: + newdata = self.dc.decompress(newdata) +- self.rawbuffer = self.dc.unconsumed_tail ++ self.rawbuffer = self.dc.unconsumed_tail if self.compress_type == ZIP_DEFLATED else '' + if self.eof and len(self.rawbuffer) == 0: + # we're out of raw bytes (both from the file and + # the local buffer); flush just to make sure the + # decompressor is done +- newdata += self.dc.flush() ++ try: ++ newdata += self.dc.flush() ++ except AttributeError: ++ pass + # prevent decompressor from being used again + self.dc = None + +@@ -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". +- compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). ++ compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), ++ or ZIP_BZIP2 (requires bz2). + 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 +675,10 @@ + if not zlib: + raise RuntimeError,\ + "Compression requires the (missing) zlib module" ++ elif compression == ZIP_BZIP2: ++ if not bz2: ++ raise RuntimeError,\ ++ "Compression requires the (missing) bz2 module" + else: + raise RuntimeError, "That compression method is not supported" + +@@ -987,7 +1005,10 @@ + if zinfo.compress_type == ZIP_DEFLATED and not zlib: + raise RuntimeError, \ + "Compression requires the (missing) zlib module" +- if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): ++ if zinfo.compress_type == ZIP_BZIP2 and not bz2: ++ raise RuntimeError, \ ++ "Compression requires the (missing) bz2 module" ++ if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): + raise RuntimeError, \ + "That compression method is not supported" + if zinfo.file_size > ZIP64_LIMIT: +@@ -1048,6 +1069,8 @@ + if zinfo.compress_type == ZIP_DEFLATED: + cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) ++ elif zinfo.compress_type == ZIP_BZIP2: ++ cmpr = bz2.BZ2Compressor() + else: + cmpr = None + while 1: +@@ -1105,6 +1128,10 @@ + zlib.DEFLATED, -15) + bytes = co.compress(bytes) + co.flush() + zinfo.compress_size = len(bytes) # Compressed size ++ elif zinfo.compress_type == ZIP_BZIP2: ++ co = bz2.BZ2Compressor() ++ bytes = co.compress(bytes) + co.flush() ++ zinfo.compress_size = len(bytes) # Compressed size + else: + zinfo.compress_size = zinfo.file_size + zinfo.header_offset = self.fp.tell() # Start of header bytes diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile271.diff --- a/zipfiles/zipfile271.diff Wed Jun 15 14:34:48 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ ---- /usr/local/lib/python2.7/zipfile.py 2010-11-29 00:56:38.000000000 +0000 -+++ zipfile271.py 2010-11-29 01:20:17.000000000 +0000 -@@ -1,6 +1,7 @@ - """ - Read and write ZIP files. - """ -+# Improved by Chortos-2 in 2010 (added bzip2 support) - import struct, os, time, sys, shutil - import binascii, cStringIO, stat - import io -@@ -13,8 +14,13 @@ - zlib = None - crc32 = binascii.crc32 - -+try: -+ import bz2 # We may need its compression method -+except ImportError: -+ bz2 = None -+ - __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", -- "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] -+ "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile", "ZIP_BZIP2" ] - - class BadZipfile(Exception): - pass -@@ -35,6 +41,7 @@ - # constants for Zip file compression methods - ZIP_STORED = 0 - ZIP_DEFLATED = 8 -+ZIP_BZIP2 = 12 - # Other ZIP compression methods not supported - - # Below are some formats and associated data for reading/writing headers using -@@ -483,6 +490,9 @@ - - if self._compress_type == ZIP_DEFLATED: - self._decompressor = zlib.decompressobj(-15) -+ elif self._compress_type == ZIP_BZIP2: -+ self._decompressor = bz2.BZ2Decompressor() -+ self.MIN_READ_SIZE = 900000 - self._unconsumed = '' - - self._readbuffer = '' -@@ -641,6 +651,13 @@ - self._update_crc(data, eof=eof) - self._readbuffer = self._readbuffer[self._offset:] + data - self._offset = 0 -+ elif (len(self._unconsumed) > 0 and n > len_readbuffer and -+ self._compress_type == ZIP_BZIP2): -+ data = self._decompressor.decompress(self._unconsumed) -+ -+ self._unconsumed = '' -+ self._readbuffer = self._readbuffer[self._offset:] + data -+ self._offset = 0 - - # Read from buffer. - data = self._readbuffer[self._offset: self._offset + n] -@@ -657,7 +674,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". -- compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). -+ compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), -+ or ZIP_BZIP2 (requires bz2). - allowZip64: if True ZipFile will create files with ZIP64 extensions when - needed, otherwise it will raise an exception when this would - be necessary. -@@ -677,6 +695,10 @@ - if not zlib: - raise RuntimeError,\ - "Compression requires the (missing) zlib module" -+ elif compression == ZIP_BZIP2: -+ if not bz2: -+ raise RuntimeError,\ -+ "Compression requires the (missing) bz2 module" - else: - raise RuntimeError, "That compression method is not supported" - -@@ -1011,7 +1033,10 @@ - if zinfo.compress_type == ZIP_DEFLATED and not zlib: - raise RuntimeError, \ - "Compression requires the (missing) zlib module" -- if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): -+ if zinfo.compress_type == ZIP_BZIP2 and not bz2: -+ raise RuntimeError, \ -+ "Compression requires the (missing) bz2 module" -+ if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): - raise RuntimeError, \ - "That compression method is not supported" - if zinfo.file_size > ZIP64_LIMIT: -@@ -1072,6 +1097,8 @@ - if zinfo.compress_type == ZIP_DEFLATED: - cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, - zlib.DEFLATED, -15) -+ elif zinfo.compress_type == ZIP_BZIP2: -+ cmpr = bz2.BZ2Compressor() - else: - cmpr = None - while 1: -@@ -1132,6 +1159,10 @@ - zlib.DEFLATED, -15) - bytes = co.compress(bytes) + co.flush() - zinfo.compress_size = len(bytes) # Compressed size -+ elif zinfo.compress_type == ZIP_BZIP2: -+ co = bz2.BZ2Compressor() -+ bytes = co.compress(bytes) + co.flush() -+ zinfo.compress_size = len(bytes) # Compressed size - else: - zinfo.compress_size = zinfo.file_size - zinfo.header_offset = self.fp.tell() # Start of header bytes diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile272.diff --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zipfiles/zipfile272.diff Thu Jun 16 01:24:10 2011 +0100 @@ -0,0 +1,110 @@ +--- /usr/local/lib/python2.7/zipfile.py 2011-06-15 13:20:07.000000000 +0100 ++++ zipfile27.py 2011-06-03 20:20:40.000000000 +0100 +@@ -1,6 +1,7 @@ + """ + Read and write ZIP files. + """ ++# Improved by Chortos-2 in 2010 (added bzip2 support) + import struct, os, time, sys, shutil + import binascii, cStringIO, stat + import io +@@ -13,8 +14,13 @@ + zlib = None + crc32 = binascii.crc32 + ++try: ++ import bz2 # We may need its compression method ++except ImportError: ++ bz2 = None ++ + __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", +- "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] ++ "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile", "ZIP_BZIP2" ] + + class BadZipfile(Exception): + pass +@@ -35,6 +41,7 @@ class LargeZipFile(Exception): + # constants for Zip file compression methods + ZIP_STORED = 0 + ZIP_DEFLATED = 8 ++ZIP_BZIP2 = 12 + # Other ZIP compression methods not supported + + # Below are some formats and associated data for reading/writing headers using +@@ -483,6 +490,9 @@ def __init__(self, fileobj, mode, zi + + if self._compress_type == ZIP_DEFLATED: + self._decompressor = zlib.decompressobj(-15) ++ elif self._compress_type == ZIP_BZIP2: ++ self._decompressor = bz2.BZ2Decompressor() ++ self.MIN_READ_SIZE = 900000 + self._unconsumed = '' + + self._readbuffer = '' +@@ -641,6 +651,13 @@ def read1(self, n): + self._update_crc(data, eof=eof) + self._readbuffer = self._readbuffer[self._offset:] + data + self._offset = 0 ++ elif (len(self._unconsumed) > 0 and n > len_readbuffer and ++ self._compress_type == ZIP_BZIP2): ++ data = self._decompressor.decompress(self._unconsumed) ++ ++ self._unconsumed = '' ++ self._readbuffer = self._readbuffer[self._offset:] + data ++ self._offset = 0 + + # Read from buffer. + data = self._readbuffer[self._offset: self._offset + n] +@@ -657,7 +674,8 @@ class ZipFile: + 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". +- compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). ++ compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), ++ or ZIP_BZIP2 (requires bz2). + allowZip64: if True ZipFile will create files with ZIP64 extensions when + needed, otherwise it will raise an exception when this would + be necessary. +@@ -677,6 +695,10 @@ def __init__(self, file, mode="r", c + if not zlib: + raise RuntimeError,\ + "Compression requires the (missing) zlib module" ++ elif compression == ZIP_BZIP2: ++ if not bz2: ++ raise RuntimeError,\ ++ "Compression requires the (missing) bz2 module" + else: + raise RuntimeError, "That compression method is not supported" + +@@ -1011,7 +1033,10 @@ def _writecheck(self, zinfo): + if zinfo.compress_type == ZIP_DEFLATED and not zlib: + raise RuntimeError, \ + "Compression requires the (missing) zlib module" +- if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): ++ if zinfo.compress_type == ZIP_BZIP2 and not bz2: ++ raise RuntimeError, \ ++ "Compression requires the (missing) bz2 module" ++ if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): + raise RuntimeError, \ + "That compression method is not supported" + if zinfo.file_size > ZIP64_LIMIT: +@@ -1072,6 +1097,8 @@ def write(self, filename, arcname=No + if zinfo.compress_type == ZIP_DEFLATED: + cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) ++ elif zinfo.compress_type == ZIP_BZIP2: ++ cmpr = bz2.BZ2Compressor() + else: + cmpr = None + while 1: +@@ -1132,6 +1159,10 @@ def writestr(self, zinfo_or_arcname, + zlib.DEFLATED, -15) + bytes = co.compress(bytes) + co.flush() + zinfo.compress_size = len(bytes) # Compressed size ++ elif zinfo.compress_type == ZIP_BZIP2: ++ co = bz2.BZ2Compressor() ++ bytes = co.compress(bytes) + co.flush() ++ zinfo.compress_size = len(bytes) # Compressed size + else: + zinfo.compress_size = zinfo.file_size + zinfo.header_offset = self.fp.tell() # Start of header bytes diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile31.py --- a/zipfiles/zipfile31.py Wed Jun 15 14:34:48 2011 +0100 +++ b/zipfiles/zipfile31.py Thu Jun 16 01:24:10 2011 +0100 @@ -898,8 +898,12 @@ def setpassword(self, pwd): """Set default password for encrypted files.""" - assert isinstance(pwd, bytes) - self.pwd = pwd + if pwd and not isinstance(pwd, bytes): + raise TypeError("pwd: expected bytes, got %s" % type(pwd)) + if pwd: + self.pwd = pwd + else: + self.pwd = None def read(self, name, pwd=None): """Return file bytes (as a string) for name.""" @@ -909,6 +913,8 @@ """Return file-like object for 'name'.""" if mode not in ("r", "U", "rU"): raise RuntimeError('open() requires mode "r", "U", or "rU"') + if pwd and not isinstance(pwd, bytes): + raise TypeError("pwd: expected bytes, got %s" % type(pwd)) if not self.fp: raise RuntimeError( "Attempt to read ZIP archive that was already closed") @@ -940,7 +946,13 @@ if fheader[_FH_EXTRA_FIELD_LENGTH]: zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH]) - if fname != zinfo.orig_filename.encode("utf-8"): + if zinfo.flag_bits & 0x800: + # UTF-8 filename + fname_str = fname.decode("utf-8") + else: + fname_str = fname.decode("cp437") + + if fname_str != zinfo.orig_filename: raise BadZipfile( 'File name in directory %r and header %r differ.' % (zinfo.orig_filename, fname)) @@ -961,8 +973,8 @@ # completely random, while the 12th contains the MSB of the CRC, # or the MSB of the file time depending on the header type # and is used to check the correctness of the password. - bytes = zef_file.read(12) - h = list(map(zd, bytes[0:12])) + header = zef_file.read(12) + h = list(map(zd, header[0:12])) if zinfo.flag_bits & 0x8: # compare against the file type from extended local headers check_byte = (zinfo._raw_time >> 8) & 0xff diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile313.diff --- a/zipfiles/zipfile313.diff Wed Jun 15 14:34:48 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ ---- /usr/local/lib/python3.1/zipfile.py 2010-11-29 00:59:28.000000000 +0000 -+++ zipfile313.py 2010-11-29 01:22:19.000000000 +0000 -@@ -3,6 +3,7 @@ - - XXX references to utf-8 need further investigation. - """ -+# Improved by Chortos-2 in 2010 (added bzip2 support) - import struct, os, time, sys, shutil - import binascii, io, stat - -@@ -13,8 +14,13 @@ - zlib = None - crc32 = binascii.crc32 - -+try: -+ import bz2 # We may need its compression method -+except ImportError: -+ bz2 = None -+ - __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", -- "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] -+ "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile", "ZIP_BZIP2" ] - - class BadZipfile(Exception): - pass -@@ -35,6 +41,7 @@ - # constants for Zip file compression methods - ZIP_STORED = 0 - ZIP_DEFLATED = 8 -+ZIP_BZIP2 = 12 - # Other ZIP compression methods not supported - - # Below are some formats and associated data for reading/writing headers using -@@ -477,6 +484,9 @@ - self.compreadsize = 64*1024 - if self.compress_type == ZIP_DEFLATED: - self.dc = zlib.decompressobj(-15) -+ elif self.compress_type == ZIP_BZIP2: -+ self.dc = bz2.BZ2Decompressor() -+ self.compreadsize = 900000 - - if hasattr(zipinfo, 'CRC'): - self._expected_crc = zipinfo.CRC -@@ -604,7 +614,7 @@ - if self.compress_type == ZIP_STORED: - lr = len(self.readbuffer) - bytesToRead = min(bytesToRead, size - lr) -- elif self.compress_type == ZIP_DEFLATED: -+ else: - if len(self.readbuffer) > size: - # the user has requested fewer bytes than we've already - # pulled through the decompressor; don't read any more -@@ -639,14 +649,17 @@ - newdata = bytes(map(self.decrypter, newdata)) - - # decompress newly read data if necessary -- if newdata and self.compress_type == ZIP_DEFLATED: -+ if newdata and self.compress_type != ZIP_STORED: - newdata = self.dc.decompress(newdata) -- self.rawbuffer = self.dc.unconsumed_tail -+ self.rawbuffer = self.dc.unconsumed_tail if self.compress_type == ZIP_DEFLATED else '' - if self.eof and len(self.rawbuffer) == 0: - # we're out of raw bytes (both from the file and - # the local buffer); flush just to make sure the - # decompressor is done -- newdata += self.dc.flush() -+ try: -+ newdata += self.dc.flush() -+ except AttributeError: -+ pass - # prevent decompressor from being used again - self.dc = None - -@@ -674,7 +687,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". -- compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). -+ compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), -+ or ZIP_BZIP2 (requires bz2). - allowZip64: if True ZipFile will create files with ZIP64 extensions when - needed, otherwise it will raise an exception when this would - be necessary. -@@ -694,6 +708,10 @@ - if not zlib: - raise RuntimeError( - "Compression requires the (missing) zlib module") -+ elif compression == ZIP_BZIP2: -+ if not bz2: -+ raise RuntimeError( -+ "Compression requires the (missing) bz2 module") - else: - raise RuntimeError("That compression method is not supported") - -@@ -1041,7 +1059,10 @@ - if zinfo.compress_type == ZIP_DEFLATED and not zlib: - raise RuntimeError( - "Compression requires the (missing) zlib module") -- if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): -+ if zinfo.compress_type == ZIP_BZIP2 and not bz2: -+ raise RuntimeError( -+ "Compression requires the (missing) bz2 module") -+ if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): - raise RuntimeError("That compression method is not supported") - if zinfo.file_size > ZIP64_LIMIT: - if not self._allowZip64: -@@ -1102,6 +1123,8 @@ - if zinfo.compress_type == ZIP_DEFLATED: - cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, - zlib.DEFLATED, -15) -+ elif zinfo.compress_type == ZIP_BZIP2: -+ cmpr = bz2.BZ2Compressor() - else: - cmpr = None - while 1: -@@ -1162,6 +1185,10 @@ - zlib.DEFLATED, -15) - data = co.compress(data) + co.flush() - zinfo.compress_size = len(data) # Compressed size -+ elif zinfo.compress_type == ZIP_BZIP2: -+ co = bz2.BZ2Compressor() -+ data = co.compress(data) + co.flush() -+ zinfo.compress_size = len(data) # Compressed size - else: - zinfo.compress_size = zinfo.file_size - zinfo.header_offset = self.fp.tell() # Start of header data diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile314.diff --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zipfiles/zipfile314.diff Thu Jun 16 01:24:10 2011 +0100 @@ -0,0 +1,126 @@ +--- /usr/local/lib/python3.1/zipfile.py 2011-06-16 01:02:30.000000000 +0100 ++++ zipfile31.py 2011-06-16 01:16:53.000000000 +0100 +@@ -3,6 +3,7 @@ + + XXX references to utf-8 need further investigation. + """ ++# Improved by Chortos-2 in 2010 (added bzip2 support) + import struct, os, time, sys, shutil + import binascii, io, stat + +@@ -13,8 +14,13 @@ + zlib = None + crc32 = binascii.crc32 + ++try: ++ import bz2 # We may need its compression method ++except ImportError: ++ bz2 = None ++ + __all__ = ["BadZipfile", "error", "ZIP_STORED", "ZIP_DEFLATED", "is_zipfile", +- "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile" ] ++ "ZipInfo", "ZipFile", "PyZipFile", "LargeZipFile", "ZIP_BZIP2" ] + + class BadZipfile(Exception): + pass +@@ -35,6 +41,7 @@ class LargeZipFile(Exception): + # constants for Zip file compression methods + ZIP_STORED = 0 + ZIP_DEFLATED = 8 ++ZIP_BZIP2 = 12 + # Other ZIP compression methods not supported + + # Below are some formats and associated data for reading/writing headers using +@@ -477,6 +484,9 @@ def __init__(self, fileobj, zipinfo, + self.compreadsize = 64*1024 + if self.compress_type == ZIP_DEFLATED: + self.dc = zlib.decompressobj(-15) ++ elif self.compress_type == ZIP_BZIP2: ++ self.dc = bz2.BZ2Decompressor() ++ self.compreadsize = 900000 + + if hasattr(zipinfo, 'CRC'): + self._expected_crc = zipinfo.CRC +@@ -604,7 +614,7 @@ def read(self, size = None): + if self.compress_type == ZIP_STORED: + lr = len(self.readbuffer) + bytesToRead = min(bytesToRead, size - lr) +- elif self.compress_type == ZIP_DEFLATED: ++ else: + if len(self.readbuffer) > size: + # the user has requested fewer bytes than we've already + # pulled through the decompressor; don't read any more +@@ -639,14 +649,17 @@ def read(self, size = None): + newdata = bytes(map(self.decrypter, newdata)) + + # decompress newly read data if necessary +- if newdata and self.compress_type == ZIP_DEFLATED: ++ if newdata and self.compress_type != ZIP_STORED: + newdata = self.dc.decompress(newdata) +- self.rawbuffer = self.dc.unconsumed_tail ++ self.rawbuffer = self.dc.unconsumed_tail if self.compress_type == ZIP_DEFLATED else '' + if self.eof and len(self.rawbuffer) == 0: + # we're out of raw bytes (both from the file and + # the local buffer); flush just to make sure the + # decompressor is done +- newdata += self.dc.flush() ++ try: ++ newdata += self.dc.flush() ++ except AttributeError: ++ pass + # prevent decompressor from being used again + self.dc = None + +@@ -674,7 +687,8 @@ class ZipFile: + 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". +- compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). ++ compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), ++ or ZIP_BZIP2 (requires bz2). + allowZip64: if True ZipFile will create files with ZIP64 extensions when + needed, otherwise it will raise an exception when this would + be necessary. +@@ -694,6 +708,10 @@ def __init__(self, file, mode="r", c + if not zlib: + raise RuntimeError( + "Compression requires the (missing) zlib module") ++ elif compression == ZIP_BZIP2: ++ if not bz2: ++ raise RuntimeError( ++ "Compression requires the (missing) bz2 module") + else: + raise RuntimeError("That compression method is not supported") + +@@ -1053,7 +1071,10 @@ def _writecheck(self, zinfo): + if zinfo.compress_type == ZIP_DEFLATED and not zlib: + raise RuntimeError( + "Compression requires the (missing) zlib module") +- if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): ++ if zinfo.compress_type == ZIP_BZIP2 and not bz2: ++ raise RuntimeError( ++ "Compression requires the (missing) bz2 module") ++ if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): + raise RuntimeError("That compression method is not supported") + if zinfo.file_size > ZIP64_LIMIT: + if not self._allowZip64: +@@ -1114,6 +1135,8 @@ def write(self, filename, arcname=No + if zinfo.compress_type == ZIP_DEFLATED: + cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, + zlib.DEFLATED, -15) ++ elif zinfo.compress_type == ZIP_BZIP2: ++ cmpr = bz2.BZ2Compressor() + else: + cmpr = None + while 1: +@@ -1174,6 +1197,10 @@ def writestr(self, zinfo_or_arcname, + zlib.DEFLATED, -15) + data = co.compress(data) + co.flush() + zinfo.compress_size = len(data) # Compressed size ++ elif zinfo.compress_type == ZIP_BZIP2: ++ co = bz2.BZ2Compressor() ++ data = co.compress(data) + co.flush() ++ zinfo.compress_size = len(data) # Compressed size + else: + zinfo.compress_size = zinfo.file_size + zinfo.header_offset = self.fp.tell() # Start of header data diff -r d7f4b051ad79 -r b993d9257400 zipfiles/zipfile320.diff --- a/zipfiles/zipfile320.diff Wed Jun 15 14:34:48 2011 +0100 +++ b/zipfiles/zipfile320.diff Thu Jun 16 01:24:10 2011 +0100 @@ -1,5 +1,5 @@ ---- zipfile32-original.py 2011-03-02 16:20:51.000000000 +0000 -+++ zipfile32.py 2011-03-02 18:38:37.000000000 +0000 +--- /usr/local/lib/python3.2/zipfile.py 2011-03-28 14:47:09.000000000 +0100 ++++ zipfile32.py 2011-06-03 20:20:40.000000000 +0100 @@ -22,8 +22,14 @@ zlib = None crc32 = binascii.crc32