dissect.target.helpers.compat.path_310#

A pathlib.Path compatible implementation for dissect.target.

This allows for the majority of the pathlib.Path API to “just work” on dissect.target filesystems.

Most of this consists of subclassed internal classes with dissect.target specific patches, but sometimes the change to a function is small, so the entire internal function is copied and only a small part changed. To ease updating this code, the order of functions, comments and code style is kept largely the same as the original pathlib.py.

Yes, we know, this is playing with fire and it can break on new CPython releases.

The implementation is split up in multiple files, one for each CPython version. You’re currently looking at the CPython 3.10 implementation.

Commit hash we’re in sync with: b382bf5

Module Contents#

Classes#

PureDissectPath

Base class for manipulating paths without I/O.

TargetPath

PurePath subclass that can make system calls.

class dissect.target.helpers.compat.path_310.PureDissectPath#

Bases: pathlib.PurePath

Base class for manipulating paths without I/O.

PurePath represents a filesystem path and offers operations which don’t imply any actual filesystem I/O. Depending on your system, instantiating a PurePath will return either a PurePosixPath or a PureWindowsPath object. You can also instantiate either of these classes directly, regardless of your system.

property parent: TargetPath#

The logical parent of the path.

property parents: dissect.target.helpers.compat.path_common._DissectPathParents#

A sequence of this path’s logical parents.

__reduce__() tuple#

Helper for pickle.

with_name(name: str) TargetPath#

Return a new path with the file name changed.

with_stem(stem: str) TargetPath#

Return a new path with the stem changed.

with_suffix(suffix: str) TargetPath#

Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.

relative_to(*other) TargetPath#

Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not a subpath of the other path), raise ValueError.

__rtruediv__(key: str) TargetPath#
class dissect.target.helpers.compat.path_310.TargetPath#

Bases: pathlib.Path, PureDissectPath

PurePath subclass that can make system calls.

Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.

__slots__ = ('_entry',)#
get() dissect.target.filesystem.FilesystemEntry#
abstract classmethod cwd() TargetPath#

Return a new path pointing to the current working directory (as returned by os.getcwd()).

abstract classmethod home() TargetPath#

Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).

iterdir() Iterator[TargetPath]#

Iterate over the files in this directory. Does not yield any result for the special paths ‘.’ and ‘..’.

walk(top_down: bool = True, on_error: Callable[[Exception], None] = None, follow_symlinks: bool = False) Iterator[tuple[TargetPath, list[str], list[str]]]#

Walk the directory tree from this directory, similar to os.walk().

abstract absolute() TargetPath#

Return an absolute version of this path. This function works even if the path doesn’t point to anything.

No normalization is done, i.e. all ‘.’ and ‘..’ will be kept along. Use resolve() to get the canonical path to a file.

resolve(strict: bool = False) TargetPath#

Make the path absolute, resolving all symlinks on the way and also normalizing it (for example turning slashes into backslashes under Windows).

stat(*, follow_symlinks: bool = True) dissect.target.helpers.fsutil.stat_result#

Return the result of the stat() system call on this path, like os.stat() does.

open(mode: str = 'rb', buffering: int = 0, encoding: str | None = None, errors: str | None = None, newline: str | None = None) IO#

Open file and return a stream.

Supports a subset of features of the real pathlib.open/io.open.

Note: in contrast to regular Python, the mode is binary by default. Text mode has to be explicitly specified. Buffering is also disabled by default.

abstract write_bytes(data: bytes) int#

Open the file in bytes mode, write to it, and close the file.

abstract write_text(data: str, encoding: str | None = None, errors: str | None = None, newline: str | None = None) int#

Open the file in text mode, write to it, and close the file.

Return the path to which the symbolic link points.

exists() bool#

Whether this path exists.

is_dir() bool#

Whether this path is a directory.

is_file() bool#

Whether this path is a regular file (also True for symlinks pointing to regular files).

Whether this path is a symbolic link.

is_junction() bool#

Whether this path is a junction.

is_block_device() bool#

Whether this path is a block device.

is_char_device() bool#

Whether this path is a character device.

is_fifo() bool#

Whether this path is a FIFO.

is_socket() bool#

Whether this path is a socket.

abstract expanduser() TargetPath#

Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)