comparison 2.00/zipfile271.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:47:05.000000000 +0000 1 --- /usr/local/lib/python2.7/zipfile.py 2010-11-29 00:56:38.000000000 +0000
2 +++ zipfile271.py 2010-11-24 01:51:31.000000000 +0000 2 +++ zipfile271.py 2010-11-29 01:20:17.000000000 +0000
3 @@ -1,6 +1,7 @@ 3 @@ -1,6 +1,7 @@
4 """ 4 """
5 Read and write ZIP files. 5 Read and write ZIP files.
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 @@ -477,6 +484,9 @@ 34 @@ -483,6 +490,9 @@
35 35
36 if self._compress_type == ZIP_DEFLATED: 36 if self._compress_type == ZIP_DEFLATED:
37 self._decompressor = zlib.decompressobj(-15) 37 self._decompressor = zlib.decompressobj(-15)
38 + elif self._compress_type == ZIP_BZIP2: 38 + elif self._compress_type == ZIP_BZIP2:
39 + self._decompressor = bz2.BZ2Decompressor() 39 + self._decompressor = bz2.BZ2Decompressor()
40 + self.MIN_READ_SIZE = 900000 40 + self.MIN_READ_SIZE = 900000
41 self._unconsumed = '' 41 self._unconsumed = ''
42 42
43 self._readbuffer = '' 43 self._readbuffer = ''
44 @@ -635,6 +645,13 @@ 44 @@ -641,6 +651,13 @@
45 self._update_crc(data, eof=eof) 45 self._update_crc(data, eof=eof)
46 self._readbuffer = self._readbuffer[self._offset:] + data 46 self._readbuffer = self._readbuffer[self._offset:] + data
47 self._offset = 0 47 self._offset = 0
48 + elif (len(self._unconsumed) > 0 and n > len_readbuffer and 48 + elif (len(self._unconsumed) > 0 and n > len_readbuffer and
49 + self._compress_type == ZIP_BZIP2): 49 + self._compress_type == ZIP_BZIP2):
53 + self._readbuffer = self._readbuffer[self._offset:] + data 53 + self._readbuffer = self._readbuffer[self._offset:] + data
54 + self._offset = 0 54 + self._offset = 0
55 55
56 # Read from buffer. 56 # Read from buffer.
57 data = self._readbuffer[self._offset: self._offset + n] 57 data = self._readbuffer[self._offset: self._offset + n]
58 @@ -651,7 +668,8 @@ 58 @@ -657,7 +674,8 @@
59 file: Either the path to the file, or a file-like object. 59 file: Either the path to the file, or a file-like object.
60 If it is a path, the file will be opened and closed by ZipFile. 60 If it is a path, the file will be opened and closed by ZipFile.
61 mode: The mode can be either read "r", write "w" or append "a". 61 mode: The mode can be either read "r", write "w" or append "a".
62 - compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib). 62 - compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib).
63 + compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib), 63 + compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
64 + or ZIP_BZIP2 (requires bz2). 64 + or ZIP_BZIP2 (requires bz2).
65 allowZip64: if True ZipFile will create files with ZIP64 extensions when 65 allowZip64: if True ZipFile will create files with ZIP64 extensions when
66 needed, otherwise it will raise an exception when this would 66 needed, otherwise it will raise an exception when this would
67 be necessary. 67 be necessary.
68 @@ -671,6 +689,10 @@ 68 @@ -677,6 +695,10 @@
69 if not zlib: 69 if not zlib:
70 raise RuntimeError,\ 70 raise RuntimeError,\
71 "Compression requires the (missing) zlib module" 71 "Compression requires the (missing) zlib module"
72 + elif compression == ZIP_BZIP2: 72 + elif compression == ZIP_BZIP2:
73 + if not bz2: 73 + if not bz2:
74 + raise RuntimeError,\ 74 + raise RuntimeError,\
75 + "Compression requires the (missing) bz2 module" 75 + "Compression requires the (missing) bz2 module"
76 else: 76 else:
77 raise RuntimeError, "That compression method is not supported" 77 raise RuntimeError, "That compression method is not supported"
78 78
79 @@ -994,7 +1016,10 @@ 79 @@ -1011,7 +1033,10 @@
80 if zinfo.compress_type == ZIP_DEFLATED and not zlib: 80 if zinfo.compress_type == ZIP_DEFLATED and not zlib:
81 raise RuntimeError, \ 81 raise RuntimeError, \
82 "Compression requires the (missing) zlib module" 82 "Compression requires the (missing) zlib module"
83 - if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): 83 - if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED):
84 + if zinfo.compress_type == ZIP_BZIP2 and not bz2: 84 + if zinfo.compress_type == ZIP_BZIP2 and not bz2:
86 + "Compression requires the (missing) bz2 module" 86 + "Compression requires the (missing) bz2 module"
87 + if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2): 87 + if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2):
88 raise RuntimeError, \ 88 raise RuntimeError, \
89 "That compression method is not supported" 89 "That compression method is not supported"
90 if zinfo.file_size > ZIP64_LIMIT: 90 if zinfo.file_size > ZIP64_LIMIT:
91 @@ -1055,6 +1080,8 @@ 91 @@ -1072,6 +1097,8 @@
92 if zinfo.compress_type == ZIP_DEFLATED: 92 if zinfo.compress_type == ZIP_DEFLATED:
93 cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, 93 cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
94 zlib.DEFLATED, -15) 94 zlib.DEFLATED, -15)
95 + elif zinfo.compress_type == ZIP_BZIP2: 95 + elif zinfo.compress_type == ZIP_BZIP2:
96 + cmpr = bz2.BZ2Compressor() 96 + cmpr = bz2.BZ2Compressor()
97 else: 97 else:
98 cmpr = None 98 cmpr = None
99 while 1: 99 while 1:
100 @@ -1115,6 +1142,10 @@ 100 @@ -1132,6 +1159,10 @@
101 zlib.DEFLATED, -15) 101 zlib.DEFLATED, -15)
102 bytes = co.compress(bytes) + co.flush() 102 bytes = co.compress(bytes) + co.flush()
103 zinfo.compress_size = len(bytes) # Compressed size 103 zinfo.compress_size = len(bytes) # Compressed size
104 + elif zinfo.compress_type == ZIP_BZIP2: 104 + elif zinfo.compress_type == ZIP_BZIP2:
105 + co = bz2.BZ2Compressor() 105 + co = bz2.BZ2Compressor()