comparison 2.00/zipfile313.diff @ 32:3000bb94addb

Updated zipfile to 2.7.1 and 3.1.3 final releases.
author Oleg Oshmyan <chortos@inbox.lv>
date Mon, 29 Nov 2010 01:24:22 +0000
parents a8cc383b787c
children
comparison
equal deleted inserted replaced
31:fe1463e7e24d 32:3000bb94addb
1 --- ../../zipfile.py 2010-11-24 01:54:28.000000000 +0000 1 --- /usr/local/lib/python3.1/zipfile.py 2010-11-29 00:59:28.000000000 +0000
2 +++ zipfile313.py 2010-11-24 01:55:17.000000000 +0000 2 +++ zipfile313.py 2010-11-29 01:22:19.000000000 +0000
3 @@ -3,6 +3,7 @@ 3 @@ -3,6 +3,7 @@
4 4
5 XXX references to utf-8 need further investigation. 5 XXX references to utf-8 need further investigation.
6 """ 6 """
7 +# Improved by Chortos-2 in 2010 (added bzip2 support) 7 +# Improved by Chortos-2 in 2010 (added bzip2 support)
29 ZIP_DEFLATED = 8 29 ZIP_DEFLATED = 8
30 +ZIP_BZIP2 = 12 30 +ZIP_BZIP2 = 12
31 # Other ZIP compression methods not supported 31 # Other ZIP compression methods not supported
32 32
33 # Below are some formats and associated data for reading/writing headers using 33 # Below are some formats and associated data for reading/writing headers using
34 @@ -471,6 +478,9 @@ 34 @@ -477,6 +484,9 @@
35 self.compreadsize = 64*1024 35 self.compreadsize = 64*1024
36 if self.compress_type == ZIP_DEFLATED: 36 if self.compress_type == ZIP_DEFLATED:
37 self.dc = zlib.decompressobj(-15) 37 self.dc = zlib.decompressobj(-15)
38 + elif self.compress_type == ZIP_BZIP2: 38 + elif self.compress_type == ZIP_BZIP2:
39 + self.dc = bz2.BZ2Decompressor() 39 + self.dc = bz2.BZ2Decompressor()
40 + self.compreadsize = 900000 40 + self.compreadsize = 900000
41 41
42 if hasattr(zipinfo, 'CRC'): 42 if hasattr(zipinfo, 'CRC'):
43 self._expected_crc = zipinfo.CRC 43 self._expected_crc = zipinfo.CRC
44 @@ -598,7 +608,7 @@ 44 @@ -604,7 +614,7 @@
45 if self.compress_type == ZIP_STORED: 45 if self.compress_type == ZIP_STORED:
46 lr = len(self.readbuffer) 46 lr = len(self.readbuffer)
47 bytesToRead = min(bytesToRead, size - lr) 47 bytesToRead = min(bytesToRead, size - lr)
48 - elif self.compress_type == ZIP_DEFLATED: 48 - elif self.compress_type == ZIP_DEFLATED:
49 + else: 49 + else:
50 if len(self.readbuffer) > size: 50 if len(self.readbuffer) > size:
51 # the user has requested fewer bytes than we've already 51 # the user has requested fewer bytes than we've already
52 # pulled through the decompressor; don't read any more 52 # pulled through the decompressor; don't read any more
53 @@ -633,14 +643,17 @@ 53 @@ -639,14 +649,17 @@
54 newdata = bytes(map(self.decrypter, newdata)) 54 newdata = bytes(map(self.decrypter, newdata))
55 55
56 # decompress newly read data if necessary 56 # decompress newly read data if necessary
57 - if newdata and self.compress_type == ZIP_DEFLATED: 57 - if newdata and self.compress_type == ZIP_DEFLATED:
58 + if newdata and self.compress_type != ZIP_STORED: 58 + if newdata and self.compress_type != ZIP_STORED:
69 + except AttributeError: 69 + except AttributeError:
70 + pass 70 + pass
71 # prevent decompressor from being used again 71 # prevent decompressor from being used again
72 self.dc = None 72 self.dc = None
73 73
74 @@ -668,7 +681,8 @@ 74 @@ -674,7 +687,8 @@
75 file: Either the path to the file, or a file-like object. 75 file: Either the path to the file, or a file-like object.
76 If it is a path, the file will be opened and closed by ZipFile. 76 If it is a path, the file will be opened and closed by ZipFile.
77 mode: The mode can be either read "r", write "w" or append "a". 77 mode: The mode can be either read "r", write "w" or append "a".
78 - compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). 78 - compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib).
79 + compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), 79 + compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
80 + or ZIP_BZIP2 (requires bz2). 80 + or ZIP_BZIP2 (requires bz2).
81 allowZip64: if True ZipFile will create files with ZIP64 extensions when 81 allowZip64: if True ZipFile will create files with ZIP64 extensions when
82 needed, otherwise it will raise an exception when this would 82 needed, otherwise it will raise an exception when this would
83 be necessary. 83 be necessary.
84 @@ -688,6 +702,10 @@ 84 @@ -694,6 +708,10 @@
85 if not zlib: 85 if not zlib:
86 raise RuntimeError( 86 raise RuntimeError(
87 "Compression requires the (missing) zlib module") 87 "Compression requires the (missing) zlib module")
88 + elif compression == ZIP_BZIP2: 88 + elif compression == ZIP_BZIP2:
89 + if not bz2: 89 + if not bz2:
90 + raise RuntimeError( 90 + raise RuntimeError(
91 + "Compression requires the (missing) bz2 module") 91 + "Compression requires the (missing) bz2 module")
92 else: 92 else:
93 raise RuntimeError("That compression method is not supported") 93 raise RuntimeError("That compression method is not supported")
94 94
95 @@ -1024,7 +1042,10 @@ 95 @@ -1041,7 +1059,10 @@
96 if zinfo.compress_type == ZIP_DEFLATED and not zlib: 96 if zinfo.compress_type == ZIP_DEFLATED and not zlib:
97 raise RuntimeError( 97 raise RuntimeError(
98 "Compression requires the (missing) zlib module") 98 "Compression requires the (missing) zlib module")
99 - if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): 99 - if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED):
100 + if zinfo.compress_type == ZIP_BZIP2 and not bz2: 100 + if zinfo.compress_type == ZIP_BZIP2 and not bz2:
102 + "Compression requires the (missing) bz2 module") 102 + "Compression requires the (missing) bz2 module")
103 + if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): 103 + if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2):
104 raise RuntimeError("That compression method is not supported") 104 raise RuntimeError("That compression method is not supported")
105 if zinfo.file_size > ZIP64_LIMIT: 105 if zinfo.file_size > ZIP64_LIMIT:
106 if not self._allowZip64: 106 if not self._allowZip64:
107 @@ -1085,6 +1106,8 @@ 107 @@ -1102,6 +1123,8 @@
108 if zinfo.compress_type == ZIP_DEFLATED: 108 if zinfo.compress_type == ZIP_DEFLATED:
109 cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, 109 cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
110 zlib.DEFLATED, -15) 110 zlib.DEFLATED, -15)
111 + elif zinfo.compress_type == ZIP_BZIP2: 111 + elif zinfo.compress_type == ZIP_BZIP2:
112 + cmpr = bz2.BZ2Compressor() 112 + cmpr = bz2.BZ2Compressor()
113 else: 113 else:
114 cmpr = None 114 cmpr = None
115 while 1: 115 while 1:
116 @@ -1145,6 +1168,10 @@ 116 @@ -1162,6 +1185,10 @@
117 zlib.DEFLATED, -15) 117 zlib.DEFLATED, -15)
118 data = co.compress(data) + co.flush() 118 data = co.compress(data) + co.flush()
119 zinfo.compress_size = len(data) # Compressed size 119 zinfo.compress_size = len(data) # Compressed size
120 + elif zinfo.compress_type == ZIP_BZIP2: 120 + elif zinfo.compress_type == ZIP_BZIP2:
121 + co = bz2.BZ2Compressor() 121 + co = bz2.BZ2Compressor()