Top Description Inners Fields Constructors Methods
org.python.modules.zipimport

public Class zipimporter

extends importer<PyObject>
implements Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc
Known Direct Subclasses
org.python.modules.zipimport.zipimporterDerived
Annotations
@ExposedType
name:zipimport.zipimporter
base:PyObject
Imports
java.io.File, .IOException, .InputStream, java.util.Date, .Enumeration, java.util.logging.Level, .Logger, java.util.zip.ZipEntry, .ZipFile, org.python.core.ArgParser, .Py, .PyDictionary, .PyException, .PyInteger, .PyLong, .PyObject, .PyString, .PySystemState, .PyTuple, .PyType, .PyUnicode, .Traverseproc, .Visitproc, .imp, org.python.core.util.FileUtil, .StringUtil, .importer, org.python.expose.ExposedGet, .ExposedMethod, .ExposedNew, .ExposedType

Import Python modules and packages from ZIP-format archives.
Author
Philip Jenvey

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
zipimporter.ZipBundle

ZipBundle is a ZipFile and one of its InputStreams, bundled together so the ZipFile can be closed when finished with its InputStream.

Field Summary

Modifier and TypeField and Description
public static final PyString
public String
archive

Path to the Zip archive

public PyObject
files

Dict with file info {path: tocEntry}

private static Logger
public String
prefix

File prefix: "a/sub/directory/"

private PySystemState
sys

The PySystemState this zipimporter is associated with

public static final PyType
Inherited from org.python.core.util.importer:
logger

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
private long

Returns:

a long time (in milliseconds) value
dosTimeToEpoch
(int
a dos style timestamp (only time) integer
dosTime
,
int
a dos style date integer
dosDate
)

Convert the date/time values found in the Zip archive to a long time (in milliseconds) value.

private int

Returns:

an int, dos style date value
epochToDosDate
(long
in milliseconds, a long value
time
)

Convert a time in milliseconds since epoch to DOS date format

private int

Returns:

an int, dos style time value
epochToDosTime
(long
in milliseconds, a long value
time
)

Convert a time in milliseconds since epoch to DOS time format

public PyObject
find_module(String fullname)

public PyObject

Returns:

a loader instance if this importer can load the module, None otherwise
find_module
(String
the fully qualified name of the module
fullname
,
String
if not installed on the meta-path None or a module path
path
)

Find the module for the fully qualified name.

public PyObject

Returns:

the module's PyCode object or None
get_code
(String
the fully qualified name of the module
fullname
)

Return the code object associated with the module.

public String

Returns:

a String of data in binary mode (no CRLF)
get_data
(String
a String path name within the archive
path
)

Implements abstract org.python.core.util.importer.get_data.

Return the uncompressed data for the file at the specified path as bytes.

public PyObject
get_filename(String fullname)

public String

Returns:

a String of the module's source code or null
get_source
(String
the fully qualified name of the module
fullname
)

Return the source code for the module as a string (using newline characters for line endings)

public PyString
getArchive()

Path to the Zip archive as FS-encoded str.

protected String
getSeparator()

Implements abstract org.python.core.util.importer.getSeparator.

Returns the separator between directories and files used by this type of importer.

protected long
getSourceMtime(String
to the compiled file
path
)

Implements abstract org.python.core.util.importer.getSourceMtime.

Given a path to a compiled file in the archive, return the modification time of the matching .py file.

protected String

Returns:

a split(".")[-1] String value
getSubname
(String
a String value
fullname
)

Return fullname.split(".")[-1].

public boolean

Returns:

a boolean describing if the module is a package
is_package
(String
the fully qualified name of the module
fullname
)

Return a boolean signifying whether the module is a package or not.

public PyObject

Returns:

a loaded PyModule
load_module
(String
the fully qualified name of the module
fullname
)

Load a module for the fully qualified name.

public zipimporter.ZipBundle

Returns:

a ZipBundle with an InputStream to the file's uncompressed data
makeBundle
(String
file's filename inside of the archive
datapath
,
PyObject entry)

Implements abstract org.python.core.util.importer.makeBundle.

Given a path to a compressed file in the archive, return the file's (uncompressed) data stream in a ZipBundle.

protected PyObject
makeEntry(String fullFilename)

Implements abstract org.python.core.util.importer.makeEntry.

Returns an entry for a filename from makeFilename with a potential suffix such that this importer can make a bundle with it, or null if fullFilename doesn't exist in this importer.

protected String
makeFilename(String fullname)

Implements abstract org.python.core.util.importer.makeFilename.

Given a full module name, return the potential file path in the archive (without extension).

protected String
makeFilePath(String fullname)

Implements abstract org.python.core.util.importer.makeFilePath.

Given a full module name, return the potential file path including the archive (without extension).

protected String
makePackagePath(String fullname)

Implements abstract org.python.core.util.importer.makePackagePath.

Returns the value to fill in __path__ on a module with the given full module name created by this importer.

private PyObject

Returns:

a PyDictionary of tocEntrys
readDirectory
(String
PyString path to the archive
archive
)

readDirectory(archive) -> files dict (new reference) Given a path to a Zip archive, build a dict, mapping file names (local to the archive, using SEP as a separator) to toc entries.

private void
readZipFile(ZipFile
ZipFile to read
zipFile
,
PyObject
a dict-like PyObject
files
)

Read ZipFile metadata into a dict of toc entries.

public boolean
public String
toString()

Overrides org.python.core.PyObject.toString.

Returns a string representation of the object.

public int
traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

pack-priv final void
private void
pack-priv final PyObject
pack-priv final PyObject
pack-priv final String
pack-priv final PyObject
pack-priv final String
pack-priv final boolean
pack-priv final PyObject
pack-priv final String
Inherited from org.python.core.util.importer:
getModuleCodegetModuleInfoimporter_find_moduleimporter_is_packageimporter_load_module

Field Detail

__doc__back to summary
public static final PyString __doc__
Annotations
@ExposedGet
archiveback to summary
public String archive

Path to the Zip archive

filesback to summary
public PyObject files

Dict with file info {path: tocEntry}

Annotations
@ExposedGet
name:_files

logback to summary
private static Logger log
prefixback to summary
public String prefix

File prefix: "a/sub/directory/"

Annotations
@ExposedGet

sysback to summary
private PySystemState sys

The PySystemState this zipimporter is associated with

TYPEback to summary
public static final PyType TYPE

Hides org.python.core.PyObject.TYPE.

Constructor Detail

zipimporterback to summary
public zipimporter()
zipimporterback to summary
public zipimporter(PyType subType)
zipimporterback to summary
public zipimporter(String path)

Method Detail

dosTimeToEpochback to summary
private long dosTimeToEpoch(int dosTime, int dosDate)

Convert the date/time values found in the Zip archive to a long time (in milliseconds) value.

Parameters
dosTime:int

a dos style timestamp (only time) integer

dosDate:int

a dos style date integer

Returns:long

a long time (in milliseconds) value

Annotations
@SuppressWarnings:deprecation

epochToDosDateback to summary
private int epochToDosDate(long time)

Convert a time in milliseconds since epoch to DOS date format

Parameters
time:long

in milliseconds, a long value

Returns:int

an int, dos style date value

Annotations
@SuppressWarnings:deprecation

epochToDosTimeback to summary
private int epochToDosTime(long time)

Convert a time in milliseconds since epoch to DOS time format

Parameters
time:long

in milliseconds, a long value

Returns:int

an int, dos style time value

Annotations
@SuppressWarnings:deprecation

find_moduleback to summary
public PyObject find_module(String fullname)
find_moduleback to summary
public PyObject find_module(String fullname, String path)

Find the module for the fully qualified name.

Parameters
fullname:String

the fully qualified name of the module

path:String

if not installed on the meta-path None or a module path

Returns:PyObject

a loader instance if this importer can load the module, None otherwise

get_codeback to summary
public PyObject get_code(String fullname)

Return the code object associated with the module.

Parameters
fullname:String

the fully qualified name of the module

Returns:PyObject

the module's PyCode object or None

get_databack to summary
public String get_data(String path)

Implements abstract org.python.core.util.importer.get_data.

Return the uncompressed data for the file at the specified path as bytes.

Parameters
path:String

a String path name within the archive

Returns:String

a String of data in binary mode (no CRLF)

Annotations
@Override

get_filenameback to summary
public PyObject get_filename(String fullname)
get_sourceback to summary
public String get_source(String fullname)

Return the source code for the module as a string (using newline characters for line endings)

Parameters
fullname:String

the fully qualified name of the module

Returns:String

a String of the module's source code or null

getArchiveback to summary
public PyString getArchive()

Path to the Zip archive as FS-encoded str.

Annotations
@ExposedGet
name:archive
getSeparatorback to summary
protected String getSeparator()

Implements abstract org.python.core.util.importer.getSeparator.

Doc from org.python.core.util.importer.getSeparator.

Returns the separator between directories and files used by this type of importer.

Annotations
@Override
getSourceMtimeback to summary
protected long getSourceMtime(String path)

Implements abstract org.python.core.util.importer.getSourceMtime.

Doc from org.python.core.util.importer.getSourceMtime.

Given a path to a compiled file in the archive, return the modification time of the matching .py file.

Parameters
path:String

to the compiled file

Returns:long

long mtime of the .py, or -1 if no source is available

Annotations
@Override

getSubnameback to summary
protected String getSubname(String fullname)

Return fullname.split(".")[-1].

Parameters
fullname:String

a String value

Returns:String

a split(".")[-1] String value

is_packageback to summary
public boolean is_package(String fullname)

Return a boolean signifying whether the module is a package or not.

Parameters
fullname:String

the fully qualified name of the module

Returns:boolean

a boolean describing if the module is a package

load_moduleback to summary
public PyObject load_module(String fullname)

Load a module for the fully qualified name.

Parameters
fullname:String

the fully qualified name of the module

Returns:PyObject

a loaded PyModule

makeBundleback to summary
public zipimporter.ZipBundle makeBundle(String datapath, PyObject entry)

Implements abstract org.python.core.util.importer.makeBundle.

Given a path to a compressed file in the archive, return the file's (uncompressed) data stream in a ZipBundle.

Parameters
datapath:String

file's filename inside of the archive

Returns:zipimporter.ZipBundle

a ZipBundle with an InputStream to the file's uncompressed data

Annotations
@Override

makeEntryback to summary
protected PyObject makeEntry(String fullFilename)

Implements abstract org.python.core.util.importer.makeEntry.

Doc from org.python.core.util.importer.makeEntry.

Returns an entry for a filename from makeFilename with a potential suffix such that this importer can make a bundle with it, or null if fullFilename doesn't exist in this importer.

Annotations
@Override
makeFilenameback to summary
protected String makeFilename(String fullname)

Implements abstract org.python.core.util.importer.makeFilename.

Doc from org.python.core.util.importer.makeFilename.

Given a full module name, return the potential file path in the archive (without extension).

Annotations
@Override
makeFilePathback to summary
protected String makeFilePath(String fullname)

Implements abstract org.python.core.util.importer.makeFilePath.

Doc from org.python.core.util.importer.makeFilePath.

Given a full module name, return the potential file path including the archive (without extension).

Annotations
@Override
makePackagePathback to summary
protected String makePackagePath(String fullname)

Implements abstract org.python.core.util.importer.makePackagePath.

Doc from org.python.core.util.importer.makePackagePath.

Returns the value to fill in __path__ on a module with the given full module name created by this importer.

Annotations
@Override
readDirectoryback to summary
private PyObject readDirectory(String archive)

readDirectory(archive) -> files dict (new reference) Given a path to a Zip archive, build a dict, mapping file names (local to the archive, using SEP as a separator) to toc entries.

Parameters
archive:String

PyString path to the archive

Returns:PyObject

a PyDictionary of tocEntrys

See Also
readZipFile(ZipFile, PyObject)

readZipFileback to summary
private void readZipFile(ZipFile zipFile, PyObject files)

Read ZipFile metadata into a dict of toc entries. A tocEntry is a tuple: (__file__, # value to use for __file__, available for all files compress, # compression kind; 0 for uncompressed data_size, # size of compressed data on disk file_size, # size of decompressed data file_offset, # offset of file header from start of archive (or -1 in Jython) time, # mod time of file (in dos format) date, # mod data of file (in dos format) crc, # crc checksum of the data ) Directories can be recognized by the trailing SEP in the name, data_size and file_offset are 0.

Parameters
zipFile:ZipFile

ZipFile to read

files:PyObject

a dict-like PyObject

refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob)

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.python.core.PyObject.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override

traverseback to summary
public int traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override
zipimporter___init__back to summary
pack-priv final void zipimporter___init__(PyObject[] args, String[] kwds)
Annotations
@ExposedNew
@ExposedMethod
zipimporter___init__back to summary
private void zipimporter___init__(String path)
zipimporter_find_moduleback to summary
pack-priv final PyObject zipimporter_find_module(String fullname, String path)
Annotations
@ExposedMethod
defaults:null
zipimporter_get_codeback to summary
pack-priv final PyObject zipimporter_get_code(String fullname)
Annotations
@ExposedMethod
zipimporter_get_databack to summary
pack-priv final String zipimporter_get_data(PyObject opath)
Annotations
@ExposedMethod
zipimporter_get_filenameback to summary
pack-priv final PyObject zipimporter_get_filename(String fullname)
Annotations
@ExposedMethod
zipimporter_get_sourceback to summary
pack-priv final String zipimporter_get_source(String fullname)
Annotations
@ExposedMethod
zipimporter_is_packageback to summary
pack-priv final boolean zipimporter_is_package(String fullname)
Annotations
@ExposedMethod
zipimporter_load_moduleback to summary
pack-priv final PyObject zipimporter_load_module(String fullname)
Annotations
@ExposedMethod
zipimporter_toStringback to summary
pack-priv final String zipimporter_toString()
Annotations
@ExposedMethod
names:__repr__
org.python.modules.zipimport back to summary

private Class zipimporter.ZipBundle

extends Bundle
Class Inheritance

ZipBundle is a ZipFile and one of its InputStreams, bundled together so the ZipFile can be closed when finished with its InputStream.

Field Summary

Modifier and TypeField and Description
pack-priv ZipFile
Inherited from org.python.core.util.importer.Bundle:
inputStream

Constructor Summary

AccessConstructor and Description
public
ZipBundle(ZipFile zipFile, InputStream inputStream)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements abstract org.python.core.util.importer.Bundle.close.

Implements java.lang.AutoCloseable.close.

Close the ZipFile; implicitly closes all of its InputStreams.

Field Detail

zipFileback to summary
pack-priv ZipFile zipFile

Constructor Detail

ZipBundleback to summary
public ZipBundle(ZipFile zipFile, InputStream inputStream)

Method Detail

closeback to summary
public void close()

Implements abstract org.python.core.util.importer.Bundle.close.

Implements java.lang.AutoCloseable.close.

Close the ZipFile; implicitly closes all of its InputStreams. Raises an IOError if a problem occurred.

Annotations
@Override