magpie.util

Module Contents

Classes

Functions

short_str

Return a short string representation of the given object.

clean_text_content

clean_content

Return the cleaned text content from the given string (usually html content).

children_pids

Return a list of the PIDs of the children from the given process.

revalidate

Revalidate a msgspec.Struct. This is useful when you had a struct that was valid some time before, it got modified (potentially to an invalid state), and you want to make sure it is still valid.

style

pformat_twig

pformat_folder

pformat

Return a “smart” representation of an object according to its type:

pprint

Smart pretty-print function that will print an object according to its type:

rprint

Re-export of the rich.pretty.pprint() function.

Data

API

magpie.util.TRUNCATION_MARKER

‘ […]’

magpie.util.TRUNCATION_MARKER_LEN

‘len(…)’

magpie.util.short_str(obj, maxlen: int = 80) str[source]

Return a short string representation of the given object.

Parameters:
  • obj – the object for which we want a str representation

  • maxlen – the max numbers of chars allowed in the string output after which truncation will occur

Returns:

A str representation with maximum length maxlen

magpie.util.clean_text_content(content: str) str[source]
magpie.util.clean_content(content: str) str[source]

Return the cleaned text content from the given string (usually html content).

magpie.util.children_pids(pid) list[int][source]

Return a list of the PIDs of the children from the given process.

magpie.util.revalidate(obj: msgspec.Struct) None[source]

Revalidate a msgspec.Struct. This is useful when you had a struct that was valid some time before, it got modified (potentially to an invalid state), and you want to make sure it is still valid.

Parameters:

obj (msgspec.Struct) – the msgspec.Struct to revalidate

Returns:

None if obj validates successfully

Raises:

msgspec.ValidationError – on error

magpie.util.console

‘Console(…)’

class magpie.util.ColorScheme[source]

Bases: magpie.datamodel.Base

folder_name: str

None

None

key: str

None

value: str

None

type: str

None

magpie.util.colors

‘ColorScheme(…)’

magpie.util.style(text: str, color: str) str[source]
magpie.util.pformat_twig(t: magpie.datamodel.Twig) Iterator[str][source]
magpie.util.pformat_folder(f: magpie.datamodel.Folder) Iterator[str][source]
magpie.util.pformat(obj) str[source]

Return a “smart” representation of an object according to its type:

  • if a Folder or a Twig, use our own functions for a neat display

  • if a str print a nicely formatted JSON string.

magpie.util.pprint(obj)[source]

Smart pretty-print function that will print an object according to its type:

  • if a Folder or a Twig, use our own functions for a neat display

  • if a str print a nicely formatted JSON string.

magpie.util.rprint(obj)[source]

Re-export of the rich.pretty.pprint() function.