Support python 2.5
This commit is contained in:
+18
-1
@@ -19,6 +19,7 @@ import shutil
|
|||||||
import tarfile
|
import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
import gzip
|
import gzip
|
||||||
|
import struct
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
@@ -212,7 +213,23 @@ class MyZipFile(zipfile.ZipFile):
|
|||||||
"Attempt to read ZIP archive that was already closed"
|
"Attempt to read ZIP archive that was already closed"
|
||||||
zinfo = self.getinfo(name)
|
zinfo = self.getinfo(name)
|
||||||
filepos = self.fp.tell()
|
filepos = self.fp.tell()
|
||||||
self.fp.seek(zinfo.file_offset, 0)
|
|
||||||
|
self.fp.seek(zinfo.header_offset, 0)
|
||||||
|
|
||||||
|
# Skip the file header:
|
||||||
|
fheader = self.fp.read(30)
|
||||||
|
if fheader[0:4] != zipfile.stringFileHeader:
|
||||||
|
raise BadZipfile, "Bad magic number for file header"
|
||||||
|
|
||||||
|
fheader = struct.unpack(zipfile.structFileHeader, fheader)
|
||||||
|
fname = self.fp.read(fheader[zipfile._FH_FILENAME_LENGTH])
|
||||||
|
if fheader[zipfile._FH_EXTRA_FIELD_LENGTH]:
|
||||||
|
self.fp.read(fheader[zipfile._FH_EXTRA_FIELD_LENGTH])
|
||||||
|
|
||||||
|
if fname != zinfo.orig_filename:
|
||||||
|
raise zipfile.BadZipfile, \
|
||||||
|
'File name in directory "%s" and header "%s" differ.' % (
|
||||||
|
zinfo.orig_filename, fname)
|
||||||
|
|
||||||
destfile = file(outname, 'wb')
|
destfile = file(outname, 'wb')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user