Update of /cvsroot/python/python/dist/src/Lib In directory usw-pr-cvs1:/tmp/cvs-serv8265/python/Lib Modified Files: gzip.py Log Message: Related to SF patch 618135: gzip.py and files > 2G. Fixed the signed/unsigned confusions when dealing with files >= 2GB. 4GB is still a hard limitation of the gzip file format, though. Testing this was a bitch on Win98SE due to frequent system freezes. It didn't freeze while running gzip, it kept freezing while trying to *create* a > 2GB test file! This wasn't Python's doing. I don't know of a reasonable way to test this functionality in regrtest.py, so I'm not checking in a test case (a test case would necessarily require creating a 2GB+ file first, using gzip to zip it, using gzip to unzip it again, and then compare before-and-after; so >4GB free space would be required, and a loooong time; I did all this "by hand" once). Bugfix candidate, I guess. Index: gzip.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/gzip.py,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** gzip.py 6 Aug 2002 17:03:25 -0000 1.35 --- gzip.py 4 Nov 2002 19:50:11 -0000 1.36 *************** *** 16,25 **** READ, WRITE = 1, 2 def write32(output, value): output.write(struct.pack("<l", value)) def write32u(output, value): ! if value < 0: ! value = value + 0x100000000L output.write(struct.pack("<L", value)) --- 16,34 ---- READ, WRITE = 1, 2 + def U32(i): + """Return i as an unsigned integer, assuming it fits in 32 bits. + + If it's >= 2GB when viewed as a 32-bit unsigned int, return a long. + """ + if i < 0: + i += 1L << 32 + return i + def write32(output, value): output.write(struct.pack("<l", value)) def write32u(output, value): ! # The L format writes the bit pattern correctly whether signed ! # or unsigned. output.write(struct.pack("<L", value)) *************** *** 158,174 **** if flag & FEXTRA: # Read & discard the extra field, if present ! xlen=ord(self.fileobj.read(1)) ! xlen=xlen+256*ord(self.fileobj.read(1)) self.fileobj.read(xlen) if flag & FNAME: # Read and discard a null-terminated string containing the filename while True: ! s=self.fileobj.read(1) ! if not s or s=='\000': break if flag & FCOMMENT: # Read and discard a null-terminated string containing a comment while True: ! s=self.fileobj.read(1) ! if not s or s=='\000': break if flag & FHCRC: self.fileobj.read(2) # Read & discard the 16-bit header CRC --- 167,185 ---- if flag & FEXTRA: # Read & discard the extra field, if present ! xlen = ord(self.fileobj.read(1)) ! xlen = xlen + 256*ord(self.fileobj.read(1)) self.fileobj.read(xlen) if flag & FNAME: # Read and discard a null-terminated string containing the filename while True: ! s = self.fileobj.read(1) ! if not s or s=='\000': ! break if flag & FCOMMENT: # Read and discard a null-terminated string containing a comment while True: ! s = self.fileobj.read(1) ! if not s or s=='\000': ! break if flag & FHCRC: self.fileobj.read(2) # Read & discard the 16-bit header CRC *************** *** 226,230 **** def _read(self, size=1024): ! if self.fileobj is None: raise EOFError, "Reached EOF" if self._new_member: --- 237,242 ---- def _read(self, size=1024): ! if self.fileobj is None: ! raise EOFError, "Reached EOF" if self._new_member: *************** *** 287,292 **** self.fileobj.seek(-8, 1) crc32 = read32(self.fileobj) ! isize = read32(self.fileobj) ! if crc32%0x100000000L != self.crc%0x100000000L: raise ValueError, "CRC check failed" elif isize != self.size: --- 299,304 ---- self.fileobj.seek(-8, 1) crc32 = read32(self.fileobj) ! isize = U32(read32(self.fileobj)) # may exceed 2GB ! if U32(crc32) != U32(self.crc): raise ValueError, "CRC check failed" elif isize != self.size: *************** *** 297,301 **** self.fileobj.write(self.compress.flush()) write32(self.fileobj, self.crc) ! write32(self.fileobj, self.size) self.fileobj = None elif self.mode == READ: --- 309,314 ---- self.fileobj.write(self.compress.flush()) write32(self.fileobj, self.crc) ! # self.size may exceed 2GB ! write32u(self.fileobj, self.size) self.fileobj = None elif self.mode == READ: *************** *** 339,345 **** raise IOError('Negative seek in write mode') count = offset - self.offset ! for i in range(count/1024): ! self.write(1024*'\0') ! self.write((count%1024)*'\0') elif self.mode == READ: if offset < self.offset: --- 352,358 ---- raise IOError('Negative seek in write mode') count = offset - self.offset ! for i in range(count // 1024): ! self.write(1024 * '\0') ! self.write((count % 1024) * '\0') elif self.mode == READ: if offset < self.offset: *************** *** 347,351 **** self.rewind() count = offset - self.offset ! for i in range(count/1024): self.read(1024) self.read(count % 1024) --- 360,365 ---- self.rewind() count = offset - self.offset ! for i in range(count // 1024): ! self.read(1024) self.read(count % 1024) *************** *** 380,388 **** def readlines(self, sizehint=0): # Negative numbers result in reading all the lines ! if sizehint <= 0: sizehint = sys.maxint L = [] while sizehint > 0: line = self.readline() ! if line == "": break L.append(line) sizehint = sizehint - len(line) --- 394,404 ---- def readlines(self, sizehint=0): # Negative numbers result in reading all the lines ! if sizehint <= 0: ! sizehint = sys.maxint L = [] while sizehint > 0: line = self.readline() ! if line == "": ! break L.append(line) sizehint = sizehint - len(line)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4