Go to the latest version of this document.

# ``twisted`.`python`.`zippath`.`ZipPath``

class documentation

`class ZipPath(Generic[_ZipStr, _ArchiveStr], AbstractFilePath[_ZipStr]): (source)`

Known subclasses: `twisted.python.zippath.ZipArchive`

Constructor: `ZipPath(archive, pathInArchive)`

Implements interfaces: `twisted.python.filepath.IFilePath`

View In Hierarchy

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

Method | `__cmp__` | Undocumented
Method | `__init__` | Don't construct me directly. Use `ZipArchive.child()`.
Method | `__repr__` | Undocumented
Method | `basename` | Subclasses must implement this.
Method | `changed` | Clear any cached information about the state of this path on disk.
Method | `child` | Return a new ZipPath representing a path in `self.archive` which is a child of this path.
Method | `dirname` | Undocumented
Method | `exists` | Check if this file path exists.
Method | `getAccessTime` | Retrieve this file's last access-time. This is the same as the last access time for the archive.
Method | `getModificationTime` | Retrieve this file's last modification time. This is the time of modification recorded in the zipfile.
Method | `getsize` | Retrieve this file's size.
Method | `getStatusChangeTime` | Retrieve this file's last modification time. This name is provided for compatibility, and returns the same value as getmtime.
Method | `isdir` | Subclasses must implement this.
Method | `isfile` | Check if this file path refers to a regular file.
Method | `islink` | Undocumented
Method | `listdir` | Subclasses must implement this.
Method | `open` | Subclasses must implement this.
Method | `parent` | Subclasses must implement this.
Method | `parents` | Retrieve an iterator of all the ancestors of this path.
Method | `sibling` | Return a `FilePath` with the same directory as this instance but with a basename of `path`.
Method | `splitext` | Return a value similar to that returned by `os.path.splitext`.
Instance Variable | `archive` | Undocumented
Instance Variable | `path` | Undocumented
Instance Variable | `pathInArchive` | Undocumented
Property | `sep` | Return a zip directory separator.
Method | `_nativeParent` | Return parent, discarding our own encoding in favor of whatever the archive's is.
Instance Variable | `_nativePathInArchive` | Undocumented

Inherited from `AbstractFilePath`:

Method | `__hash__` | Hash the same as another `AbstractFilePath` with the same path as mine.
Method | `children` | List the children of this path object.
Method | `descendant` | Retrieve a child or child's child of this path.
Method | `getatime` | Deprecated. Use getAccessTime instead.
Method | `getContent` | Retrieve the contents of the file at this path.
Method | `getctime` | Deprecated. Use getStatusChangeTime instead.
Method | `getmtime` | Deprecated. Use getModificationTime instead.
Method | `segmentsFrom` | Return a list of segments between a child and its ancestor.
Method | `walk` | Yield myself, then each of my children, and each of those children's children in turn.
Type Variable | `Selfish` | Undocumented

def __cmp__(self, other: `object`) -> `int`: (source)
overridden in `twisted.python.zippath.ZipArchive`

Undocumented

def __init__(self, archive: `ZipArchive[_ArchiveStr]`, pathInArchive: `_ZipStr`): (source)
overridden in `twisted.python.zippath.ZipArchive`

Don't construct me directly. Use `ZipArchive.child()`.

Parameters
archive:`ZipArchive[_ArchiveStr]` | a `ZipArchive` instance.
pathInArchive:`_ZipStr` | a ZIP_PATH_SEP-separated string.

def __repr__(self) -> `str`: (source)
overridden in `twisted.python.zippath.ZipArchive`

Undocumented

def basename(self) -> `_ZipStr`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.basename`

Subclasses must implement this.

def changed(self): (source)
from `twisted.python.filepath.IFilePath`

Clear any cached information about the state of this path on disk.

def child(self, path: `OtherAnyStr`) -> `ZipPath[OtherAnyStr, _ArchiveStr]`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.child`
overridden in `twisted.python.zippath.ZipArchive`

Return a new ZipPath representing a path in `self.archive` which is a child of this path.

Note
Requesting the `".."` (or other special name) child will not cause `InsecurePath` to be raised since these names do not have any special meaning inside a zip archive. Be particularly careful with the `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.

def dirname(self) -> `_ZipStr`: (source)

Undocumented

def exists(self) -> `bool`: (source)
from `twisted.python.filepath.IFilePath`
overridden in `twisted.python.zippath.ZipArchive`

Check if this file path exists.

Returns
`bool` | `True` if the file at this file path exists, `False` otherwise.

def getAccessTime(self) -> `float`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.getAccessTime`
overridden in `twisted.python.zippath.ZipArchive`

Retrieve this file's last access-time. This is the same as the last access time for the archive.

Returns
`float` | a number of seconds since the epoch

def getModificationTime(self) -> `float`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.getModificationTime`
overridden in `twisted.python.zippath.ZipArchive`

Retrieve this file's last modification time. This is the time of modification recorded in the zipfile.

Returns
`float` | a number of seconds since the epoch.

def getsize(self) -> `int`: (source)
from `twisted.python.filepath.IFilePath`

Retrieve this file's size.

Returns
`int` | file size, in bytes

def getStatusChangeTime(self) -> `float`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.getStatusChangeTime`
overridden in `twisted.python.zippath.ZipArchive`

Retrieve this file's last modification time. This name is provided for compatibility, and returns the same value as getmtime.

Returns
`float` | a number of seconds since the epoch.

def isdir(self) -> `bool`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.isdir`

Subclasses must implement this.

def isfile(self) -> `bool`: (source)
from `twisted.python.filepath.IFilePath`

Check if this file path refers to a regular file.

Returns
`bool` | `True` if the file at this file path is a regular file, `False` otherwise.

def islink(self) -> `bool`: (source)

Undocumented

def listdir(self) -> `list[_ZipStr]`: (source)
overrides `twisted.python.filepath.AbstractFilePath.listdir`

Subclasses must implement this.

def open(self, mode: `Literal['r', 'w']` = 'r') -> `IO[bytes]`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.open`

Subclasses must implement this.

def parent(self) -> `ZipPath[_ZipStr, _ArchiveStr] | ZipArchive[_ZipStr]`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.parent`

Subclasses must implement this.

def parents(self) -> `Iterable[ZipPath[_ZipStr, _ArchiveStr] | ZipArchive[_ZipStr]]`: (source)
overrides `twisted.python.filepath.AbstractFilePath.parents`

Retrieve an iterator of all the ancestors of this path.

Returns
`Iterable[ZipPath[_ZipStr, _ArchiveStr] | ZipArchive[_ZipStr]]` | an iterator of all the ancestors of this path, from the most recent (its immediate parent) to the root of its filesystem.

def sibling(self, path: `OtherAnyStr`) -> `ZipPath[OtherAnyStr, _ArchiveStr]`: (source)
from `twisted.python.filepath.IFilePath`
overrides `twisted.python.filepath.AbstractFilePath.sibling`

Return a `FilePath` with the same directory as this instance but with a basename of `path`.

Parameters
path:`str` | The basename of the `FilePath` to return.

Returns
`FilePath` | The sibling path.

Note
for type-checking, subclasses should override this signature to make it clear that it returns the subclass and not `AbstractFilePath`.

def splitext(self) -> `tuple[_ZipStr, _ZipStr]`: (source)

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

archive: `ZipArchive[_ArchiveStr]` = (source)
overridden in `twisted.python.zippath.ZipArchive`

Undocumented

path: `_ZipStr` = (source)
overrides `twisted.python.filepath.AbstractFilePath.path`
overridden in `twisted.python.zippath.ZipArchive`

Undocumented

pathInArchive: `_ZipStr` = (source)
overridden in `twisted.python.zippath.ZipArchive`

Undocumented

@property
sep: `_ZipStr` = (source)
from `twisted.python.filepath.IFilePath`

Return a zip directory separator.

Returns
The same type as `self.path`. | Undocumented

def _nativeParent(self) -> `ZipPath[_ZipStr, _ArchiveStr] | ZipArchive[_ArchiveStr]`: (source)

Return parent, discarding our own encoding in favor of whatever the archive's is.

_nativePathInArchive: `_ArchiveStr` = (source)

Undocumented