dissect.target.helpers.utils#

Module Contents#

Classes#

StrEnum

Sortable and serializible string-based enum

Functions#

list_to_frozen_set

parse_path_uri

parse_options_string

slugify

Return name with all slashes '/', backslashes '' and spaces ' ' replaced by underscores '_'.

readinto

A readinto implementation that uses read().

year_rollover_helper

Helper function for determining the correct timestamps for log files without year notation.

Attributes#

dissect.target.helpers.utils.log#
class dissect.target.helpers.utils.StrEnum#

Bases: str, enum.Enum

Sortable and serializible string-based enum

dissect.target.helpers.utils.list_to_frozen_set(function: Callable) Callable#
dissect.target.helpers.utils.parse_path_uri(path: pathlib.Path) tuple[str | None, str | None, str | None]#
dissect.target.helpers.utils.parse_options_string(options: str) dict[str, str | bool]#
dissect.target.helpers.utils.SLUG_RE#
dissect.target.helpers.utils.slugify(name: str) str#

Return name with all slashes ‘/’, backslashes ‘' and spaces ‘ ‘ replaced by underscores ‘_’.

This is useful to turn a name into something that can be used as filename.

dissect.target.helpers.utils.readinto(buffer: bytearray, fh: BinaryIO) int#

A readinto implementation that uses read().

Reads the length of the buffer from fh, and fills the buffer with said data.

Parameters:
  • buffer – The buffer we read the data into.

  • fh – The file-like object we use for reading.

Returns:

the size in bytes that was read.

dissect.target.helpers.utils.STRIP_RE#
dissect.target.helpers.utils.year_rollover_helper(path: pathlib.Path, re_ts: str | re.Pattern, ts_format: str, tzinfo: year_rollover_helper.tzinfo = timezone.utc) Iterator[tuple[datetime.datetime, str]]#

Helper function for determining the correct timestamps for log files without year notation.

Supports compressed files by using open_decompress().

Parameters:
  • path – A path to the log file to parse.

  • re_ts – Regex pattern for extracting the timestamp from each line.

  • ts_format – Time format specification for parsing the timestamp.

  • tzinfo – The timezone to use when parsing timestamps.

Returns:

An iterator of tuples of the parsed timestamp and the lines of the file in reverse.