dissec.patterns – Pattern definitions

class dissec.patterns.BasicKey(*, name: str, skip_right_padding: Any = False)

Basic key for dissect patterns.

name: Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]

Name of the key.

skip_right_padding: bool

Whether to skip right padding.

classmethod parse(raw: str, /) BasicKeyType

Parse a basic key.

Parameters:

raw – Textual form of the key to parse.

Returns:

Pattern.

Raises:

ValueError – Could not parse a key.

class dissec.patterns.SkipKey(*, name: str = '', skip_right_padding: Any = False)

Skip key for dissect patterns.

name: str

Optional name of the skip key.

skip_right_padding: bool

Whether to skip right padding.

classmethod parse(raw: str, /) SkipKeyType

Parse a skip key.

Parameters:

raw – Textual form of the key to parse.

Returns:

Pattern.

Raises:

ValueError – Could not parse a key.

class dissec.patterns.AppendKey(*, name: str, append_order: int | None = None, skip_right_padding: Any = False)

Append key for dissect patterns.

name: Annotated[str, StringConstraints(min_length=1)]

Optional name of the skip key.

append_order: int | None

The position at which to append the key.

skip_right_padding: bool

Whether to skip right padding.

classmethod parse(raw: str, /) AppendKeyType

Parse a skip key.

Parameters:

raw – Textual form of the key to parse.

Returns:

Pattern.

Raises:

ValueError – Could not parse a key.

class dissec.patterns.FieldNameKey(*, name: str, skip_right_padding: Any = False)

Field name key for dissect patterns.

name: Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]

Optional name of the skip key.

skip_right_padding: bool

Whether to skip right padding.

classmethod parse(raw: str, /) FieldNameKeyType

Parse a skip key.

Parameters:

raw – Textual form of the key to parse.

Returns:

Pattern.

Raises:

ValueError – Could not parse a key.

class dissec.patterns.FieldValueKey(*, name: str, skip_right_padding: Any = False)

Field value key for dissect patterns.

name: Annotated[str, StringConstraints(strip_whitespace=None, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=None, pattern=None)]

Optional name of the skip key.

skip_right_padding: bool

Whether to skip right padding.

classmethod parse(raw: str, /) FieldValueKeyType

Parse a skip key.

Parameters:

raw – Textual form of the key to parse.

Returns:

Pattern.

Raises:

ValueError – Could not parse a key.

dissec.patterns.Key

Key type for dissect patterns.

alias of BasicKey | SkipKey | AppendKey | FieldNameKey | FieldValueKey

class dissec.patterns.Pattern(*, prefix: str = '', pairs: Sequence[tuple[BasicKey | SkipKey | AppendKey | FieldNameKey | FieldValueKey, str]] = ())

Dissect pattern.

For more information, see Dissect patterns.

classmethod parse_key(raw: str, /, *, runk: Runk | None = None) Key

Parse a key for a dissect pattern.

Parameters:
  • raw – Raw dissect key.

  • runk – Runk instance.

Returns:

Dissect key.

classmethod parse(raw: str, /, *, runk: Runk | None = None) PatternType

Parse a pattern.

Parameters:
  • raw – Textual form of the pattern to parse.

  • runk – Runk instance to start from.

Returns:

Pattern.

property prefix: str

Prefix, i.e. chunk of text that must be ignored at the start.

property pairs: Sequence[tuple[BasicKey | SkipKey | AppendKey | FieldNameKey | FieldValueKey, str]]

Key / delimiter pairs to use to parse the string.

property pattern: Pattern

Pattern.

dissect(raw: str, /, *, append_separator: str = '') dict[str, str]

Use the pattern to dissect a string.

Parameters:
  • raw – Raw string to dissect.

  • append_separator – Separator to use with append fields.

Returns:

Extracted data.

Raises:

ValueError – Raw string dissection was not possible.