Class zipimporter

All Implemented Interfaces:
Serializable, Traverseproc
Direct Known Subclasses:
zipimporterDerived

public class zipimporter extends importer<PyObject> implements Traverseproc
Import Python modules and packages from ZIP-format archives.
Author:
Philip Jenvey
See Also:
  • Field Details

    • TYPE

      public static final PyType TYPE
    • __doc__

      public static final PyString __doc__
    • archive

      public String archive
      Path to the Zip archive
    • prefix

      public String prefix
      File prefix: "a/sub/directory/"
    • files

      public PyObject files
      Dict with file info {path: tocEntry}
  • Constructor Details

    • zipimporter

      public zipimporter()
    • zipimporter

      public zipimporter(PyType subType)
    • zipimporter

      public zipimporter(String path)
  • Method Details

    • getArchive

      public PyString getArchive()
      Path to the Zip archive as FS-encoded str.
    • find_module

      public PyObject find_module(String fullname)
    • find_module

      public PyObject find_module(String fullname, String path)
      Find the module for the fully qualified name.
      Parameters:
      fullname - the fully qualified name of the module
      path - if not installed on the meta-path None or a module path
      Returns:
      a loader instance if this importer can load the module, None otherwise
    • load_module

      public PyObject load_module(String fullname)
      Load a module for the fully qualified name.
      Parameters:
      fullname - the fully qualified name of the module
      Returns:
      a loaded PyModule
    • get_data

      public String get_data(String path)
      Return the uncompressed data for the file at the specified path as bytes.
      Specified by:
      get_data in class importer<PyObject>
      Parameters:
      path - a String path name within the archive
      Returns:
      a String of data in binary mode (no CRLF)
    • is_package

      public boolean is_package(String fullname)
      Return a boolean signifying whether the module is a package or not.
      Parameters:
      fullname - the fully qualified name of the module
      Returns:
      a boolean describing if the module is a package
    • get_code

      public PyObject get_code(String fullname)
      Return the code object associated with the module.
      Parameters:
      fullname - the fully qualified name of the module
      Returns:
      the module's PyCode object or None
    • get_filename

      public PyObject get_filename(String fullname)
    • get_source

      public String get_source(String fullname)
      Return the source code for the module as a string (using newline characters for line endings)
      Parameters:
      fullname - the fully qualified name of the module
      Returns:
      a String of the module's source code or null
    • makeBundle

      public org.python.modules.zipimport.zipimporter.ZipBundle makeBundle(String datapath, PyObject entry)
      Given a path to a compressed file in the archive, return the file's (uncompressed) data stream in a ZipBundle.
      Parameters:
      datapath - file's filename inside of the archive
      Returns:
      a ZipBundle with an InputStream to the file's uncompressed data
    • toString

      public String toString()
      Overrides:
      toString in class PyObject
    • traverse

      public int traverse(Visitproc visit, Object arg)
      Description copied from interface: Traverseproc
      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.
      Specified by:
      traverse in interface Traverseproc
    • refersDirectlyTo

      public boolean refersDirectlyTo(PyObject ob)
      Description copied from interface: Traverseproc
      Optional operation. Should only be implemented if it is more efficient than calling Traverseproc.traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.
      Specified by:
      refersDirectlyTo in interface Traverseproc