ZipPath

class bp.zippath.ZipPath(archive, pathInArchive)

I am a file or directory contained within a zip file.

__init__(archive, pathInArchive)

Don’t construct me directly. Use ZipArchive.child().

Parameters:
  • archive (ZipArchive) – a ZipArchive instance.
  • pathInArchive (str) – a ZIP_PATH_SEP-separated string.
__weakref__

list of weak references to the object (if defined)

child(path)

Return a new ZipPath representing a path in C{self.archive} which is a child of this path.

Note

Requesting the C{”..”} (or other special name) child will not cause L{InsecurePath} to be raised since these names do not have any special meaning inside a zip archive. Be particularly careful with the C{path} attribute (if you absolutely must use it) as this means it may include special names with special meaning outside of the context of a zip archive.

children(path)

List the children of the given path.

Returns:an iterable of all currently-existing children of the path.
Return type:iterable
descendant(path, segments)

Retrieve a child or child’s child of the given path.

Parameters:segments (iterable) – A sequence of path segments as L{str} instances.
Returns:A L{FilePath} constructed by looking up the C{segments[0]} child of this path, the C{segments[1]} child of that path, and so on.
getAccessTime()

Retrieve this file’s last access-time.

This is the same as the last access time for the archive.

Returns:a number of seconds since the epoch
Return type:int
getModificationTime()

Retrieve this file’s last modification time.

This is the time of modification recorded in the zipfile.

Returns:a number of seconds since the epoch.
Return type:int
getStatusChangeTime()

Retrieve this file’s last modification time.

This is the time of modification recorded in the zipfile.

Returns:a number of seconds since the epoch.
Return type:int
getsize()

Retrieve this file’s size.

@return: file size, in bytes

parents(path)

Retrieve an iterator of all the ancestors of the given path.

Returns:An iterator of all the ancestors of the given path, from the most recent (its immediate parent) to the root of its filesystem.
Return type:iterator
segmentsFrom(path, ancestor)

Return a list of segments between a child and its ancestor.

For example, in the case of a path X representing /a/b/c/d and a path Y representing /a/b, C{Y.segmentsFrom(X)} will return C{[‘c’, ‘d’]}.

Parameters:ancestor – an instance of the same class as self, ostensibly an ancestor of self.
Raises:ValueError – When the ‘ancestor’ parameter is not actually an ancestor, i.e. a path for /x/y/z is passed as an ancestor for /a/b/c/d.
Returns:a list of segments
Return type:list
splitext()

Return a value similar to that returned by os.path.splitext().

walk(path, descend=None)

Yield a path, then each of its children, and each of those children’s children in turn.

Parameters:descend (callable) – A one-argument callable that will return True for FilePaths that should be traversed and False otherwise. It will be called with each path for which isdir() returns True. If omitted, all directories will be traversed, including symbolic links.
Raises:LinkError – A cycle of symbolic links was found
Returns:a generator yielding FilePath-like objects
Return type:generator