Package nltk :: Module data :: Class OpenOnDemandZipFile
[hide private]
[frames] | no frames]

Class OpenOnDemandZipFile

source code

zipfile.ZipFile --+
                  |
                 OpenOnDemandZipFile

A subclass of zipfile.ZipFile that closes its file pointer whenever it is not using it; and re-opens it when it needs to read data from the zipfile. This is useful for reducing the number of open file handles when many zip files are being accessed at once. OpenOnDemandZipFile must be constructed from a filename, not a file-like object (to allow re-opening). OpenOnDemandZipFile is read-only (i.e., write and writestr are disabled.

Instance Methods [hide private]
 
__init__(self, filename)
Open the ZIP file with mode read "r", write "w" or append "a".
source code
 
read(self, name)
Return file bytes (as a string) for name.
source code
 
write(self, *args, **kwargs)
Put the bytes from filename into the archive under the name arcname.
source code
 
writestr(self, *args, **kwargs)
Write a file into the archive.
source code
 
__repr__(self) source code

Inherited from zipfile.ZipFile: __del__, close, getinfo, infolist, namelist, printdir, testzip

Inherited from zipfile.ZipFile (private): _GetContents, _RealGetContents, _writecheck

Class Variables [hide private]

Inherited from zipfile.ZipFile: fp

Method Details [hide private]

__init__(self, filename)
(Constructor)

source code 

Open the ZIP file with mode read "r", write "w" or append "a".

Overrides: zipfile.ZipFile.__init__
(inherited documentation)

read(self, name)

source code 

Return file bytes (as a string) for name.

Overrides: zipfile.ZipFile.read
(inherited documentation)

write(self, *args, **kwargs)

source code 

Put the bytes from filename into the archive under the name arcname.

Raises:
  • NotImplementedError - OpenOnDemandZipfile is read-only
Overrides: zipfile.ZipFile.write

writestr(self, *args, **kwargs)

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.

Raises:
  • NotImplementedError - OpenOnDemandZipfile is read-only
Overrides: zipfile.ZipFile.writestr