Package obitools :: Module zipfile :: Class ZipFile
[hide private]
[frames] | no frames]

Class ZipFile

source code


Class with methods to open, read, write, close, list zip files.

z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True)

Instance Methods [hide private]
 
__init__(self, file, mode='r', compression=0, allowZip64=False)
Open the ZIP file with mode read "r", write "w" or append "a".
source code
 
_GetContents(self)
Read the directory, making sure we close the file if the format is bad.
source code
 
_RealGetContents(self)
Read in the table of contents for the ZIP file.
source code
 
namelist(self)
Return a list of file names in the archive.
source code
 
infolist(self)
Return a list of class ZipInfo instances for files in the archive.
source code
 
printdir(self)
Print a table of contents for the zip file.
source code
 
testzip(self)
Read all the files and check the CRC.
source code
 
getinfo(self, name)
Return the instance of ZipInfo given 'name'.
source code
 
setpassword(self, pwd)
Set default password for encrypted files.
source code
 
read(self, name, pwd=None)
Return file bytes (as a string) for name.
source code
 
open(self, name, mode='r', pwd=None)
Return file-like object for 'name'.
source code
 
extract(self, member, path=None, pwd=None)
Extract a member from the archive to the current working directory, using its full name.
source code
 
extractall(self, path=None, members=None, pwd=None)
Extract all members from the archive to the current working directory.
source code
 
_extract_member(self, member, targetpath, pwd)
Extract the ZipInfo object 'member' to a physical file on the path targetpath.
source code
 
_writecheck(self, zinfo)
Check for errors before writing a file to the archive.
source code
 
write(self, filename, arcname=None, compress_type=None)
Put the bytes from filename into the archive under the name arcname.
source code
 
writestr(self, zinfo_or_arcname, bytes)
Write a file into the archive.
source code
 
__del__(self)
Call the "close()" method in case the user forgot.
source code
 
close(self)
Close the file, and for mode "w" and "a" write the ending records.
source code
Class Variables [hide private]
  fp = None
hash(x)
Method Details [hide private]

extract(self, member, path=None, pwd=None)

source code 

Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using `path'.

extractall(self, path=None, members=None, pwd=None)

source code 

Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist().

writestr(self, zinfo_or_arcname, bytes)

source code 

Write a file into the archive. The contents is the string 'bytes'. 'zinfo_or_arcname' is either a ZipInfo instance or the name of the file in the archive.