:py:mod:`dissect.target.helpers.compat.path_312` ================================================ .. py:module:: dissect.target.helpers.compat.path_312 .. autoapi-nested-parse:: 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.12 implementation. Commit hash we're in sync with: .. rubric:: Notes - CPython 3.12 changed a lot in preparation of proper subclassing, so our patches differ a lot from previous versions - Flavours don't really exist anymore, but since we kind of "multi-flavour" we need to emulate it Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: dissect.target.helpers.compat.path_312.PureDissectPath dissect.target.helpers.compat.path_312.TargetPath .. py:class:: PureDissectPath(fs: dissect.target.filesystem.Filesystem, *pathsegments) Bases: :py:obj:`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. .. py:method:: __reduce__() -> tuple Helper for pickle. .. py:method:: with_segments(*pathsegments) -> TargetPath .. py:method:: is_reserved() -> bool Return True if the path contains one of the special names reserved by the system, if any. .. py:class:: TargetPath(fs: dissect.target.filesystem.Filesystem, *pathsegments) Bases: :py:obj:`pathlib.Path`, :py:obj:`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. .. py:attribute:: __slots__ :value: ('_entry',) .. py:method:: get() -> dissect.target.filesystem.FilesystemEntry .. py:method:: 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. .. py:method:: exists(*, follow_symlinks: bool = True) -> bool Whether this path exists. This method normally follows symlinks; to check whether a symlink exists, add the argument follow_symlinks=False. .. py:method:: is_dir() -> bool Whether this path is a directory. .. py:method:: is_file() -> bool Whether this path is a regular file (also True for symlinks pointing to regular files). .. py:method:: is_symlink() -> bool Whether this path is a symbolic link. .. py:method:: is_block_device() -> bool Whether this path is a block device. .. py:method:: is_char_device() -> bool Whether this path is a character device. .. py:method:: is_fifo() -> bool Whether this path is a FIFO. .. py:method:: is_socket() -> bool Whether this path is a socket. .. py:method:: open(mode: str = 'rb', buffering: int = 0, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = 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. .. py:method:: write_bytes(data: bytes) -> int :abstractmethod: Open the file in bytes mode, write to it, and close the file. .. py:method:: write_text(data: str, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None) -> int :abstractmethod: Open the file in text mode, write to it, and close the file. .. py:method:: iterdir() -> Iterator[TargetPath] Iterate over the files in this directory. Does not yield any result for the special paths '.' and '..'. .. py:method:: cwd() -> TargetPath :classmethod: :abstractmethod: Return a new path pointing to the current working directory. .. py:method:: home() -> TargetPath :classmethod: :abstractmethod: Return a new path pointing to the user's home directory (as returned by os.path.expanduser('~')). .. py:method:: absolute() -> TargetPath :abstractmethod: Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed. Use resolve() to get the canonical path to a file. .. py:method:: resolve(strict: bool = False) -> TargetPath Make the path absolute, resolving all symlinks on the way and also normalizing it. .. py:method:: owner() -> str :abstractmethod: Return the login name of the file owner. .. py:method:: group() -> str :abstractmethod: Return the group name of the file gid. .. py:method:: readlink() -> TargetPath Return the path to which the symbolic link points. .. py:method:: touch(mode: int = 438, exist_ok: bool = True) -> None :abstractmethod: Create this file with the given access mode, if it doesn't exist. .. py:method:: mkdir(mode: int = 511, parents: bool = False, exist_ok: bool = False) -> None :abstractmethod: Create a new directory at this given path. .. py:method:: chmod(mode: int, *, follow_symlinks: bool = True) -> None :abstractmethod: Change the permissions of the path, like os.chmod(). .. py:method:: lchmod(mode: int) -> None :abstractmethod: Like chmod(), except if the path points to a symlink, the symlink's permissions are changed, rather than its target's. .. py:method:: unlink(missing_ok: bool = False) -> None :abstractmethod: Remove this file or link. If the path is a directory, use rmdir() instead. .. py:method:: rmdir() -> None :abstractmethod: Remove this directory. The directory must be empty. .. py:method:: rename(target: str) -> TargetPath :abstractmethod: Rename this path to the target path. The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, *not* the directory of the Path object. Returns the new Path instance pointing to the target path. .. py:method:: replace(target: str) -> TargetPath :abstractmethod: Rename this path to the target path, overwriting if that path exists. The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, *not* the directory of the Path object. Returns the new Path instance pointing to the target path. .. py:method:: symlink_to(target: str, target_is_directory: bool = False) -> None :abstractmethod: Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink. .. py:method:: hardlink_to(target: str) -> None :abstractmethod: Make this path a hard link pointing to the same file as *target*. Note the order of arguments (self, target) is the reverse of os.link's. .. py:method:: expanduser() -> TargetPath :abstractmethod: Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)