module utils


function sanitize_str

sanitize_str(text: Optional[str], repl: str = ' ') → str

sanitize_str trims leading / trailing spaces replacing line endings and consecutive whitespace characters with the specified replacement value

Args:

  • text (Optional[str]): the string
  • repl (str): the replacement value. Defaults to " "

Returns:

  • str: the santized string or empty string

function join_strs

join_strs(a: Optional[str], b: Optional[str], sep: str = '_') → str

join_strs conditionally joins two strings depending on if they are both not empty or None

Args:

  • a (Optional[str]): the first string
  • b (Optional[str]): the second string

Returns:

  • str: either the joined strings, the first, second or empty string

function is_undefined_or_none

is_undefined_or_none(obj: Any) → bool

is_undefined_or_none returns whether the object is undefined or none

Args:

  • obj (Any): the object to check

Returns:

  • bool: returns True if the object is undefined or empty, otherwise, False

function is_undefined_none_or_blank

is_undefined_none_or_blank(obj: Any) → bool

is_undefined_none_or_blank returns whether the object is undefined, none or blank

Will return True for the following:

        - Undefined 
        - None 
        - '' (empty string) 
        - ' ' (blank string) 
        - [] (empty list) 
        - () (empty tuple) 
        - {} (empty dict) 
        - set() (empty set) 

Args:

  • obj (Any): the object to check

Returns:

  • bool: returns True if the object is undefined, none or empty, otherwise, False

function to_list_or_empty

to_list_or_empty(obj: Any) → List[Any]

to_list_or_empty returns the object as a list if its a list or not empty or none, otherwise, []

Args:

  • obj (Any): the object to check

Returns:

  • list[Any]: returns the object as a list if its a list or not empty or none, otherwise, []

function blank_str_to_empty

blank_str_to_empty(obj: str) → str

blank_str_to_empty returns the given string if it's not blank, otherwise, empty

Args:

  • obj (str): the string to check

Returns:

  • str: returns the given string if it's not blank, otherwise, empty

function merge_dict

merge_dict(a: Dict[Any, Any], b: Dict[Any, Any]) → Dict[Any, Any]

merge_dict Merges the key/value pair mappings similarly to newtonsoft Merge.

See https://www.newtonsoft.com/json/help/html/MergeJson.htm

Args:

  • a (Dict[Any, Any]): the mappings to merge into
  • b (Dict[Any, Any]): the mappings to merge

Returns:

  • Dict[Any, Any]: the merged mappings

function read_text

read_text(
    data: Union[IO[str], IO[bytes], str, bytes],
    encoding: str = 'utf-8'
) → str

read_text Reads the given data using the supplied encoding if the data is not already a string

Args:

  • data (DataIn): the data to read
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"

Returns:

  • str: the text content

function join_subpath

join_subpath(path: Path, parent: Path, child: Path) → Path

join_subpath Joins the parts from the child relative to the parent path to the supplied path. the final file part from child will be excluded if child is a file

Args:

  • path (Path): the path to join the parts to
  • parent (Path): the parent path
  • child (Path): the child within the parent path

Returns:

  • Path: the new path

function del_empty_dirs_quietly

del_empty_dirs_quietly(path: Path) → None

del_empty_dirs_quietly Quietly deletes any empty sub directories within the path ignoring any errors that may have occurred

Args:

  • path (Path): the path to scan

function del_path_quietly

del_path_quietly(path: Path) → None

del_path_quietly Quietly deletes a path ignoring any errors that may have occurred

Allows callers to attempt to delete a path while not having to worry about file system errors

Args:

  • path (Path): the path to delete

function mkdir

mkdir(path: Path, **kwargs) → bool

mkdir wrapper around Path.mkdir forwarding additional keyword args

Allows callers to discern between a directory existing, an actual error while creating the directory and a successful creation aka the directory didn't exist previously

Args:

  • path (Path): the path

Returns:

  • bool: True if the directory was created, otherwise, False to indicate the directory already exists

function walk_path

walk_path(
    path: Path
) → Generator[Tuple[Path, List[str], List[str]], Any, NoneType]

walk_path wrapper around os.walk to semi bridge the gap of path.walk added in 3.12.

Args:

  • path (Path): the path to walk

Yields:

  • Generator[Tuple[Path, List[str], List[str]], Any, None]: the directory tree generator

function tail

tail(buffer: <class 'IO'>, last_n: int = 25, encoding: str = 'utf-8') → str

tail Reads the tail from the given file like object

Args:

  • buffer (IO): the file like object to read from
  • last_n (int, optional): the last n to read up to. Defaults to 25.
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"

Returns:

  • str: up to the last n from the file like object or empty string if the object is empty

function parse_etree

parse_etree(
    xml_in: Union[IO[str], IO[bytes], str, bytes, PathLike],
    encoding: str = 'utf-8',
    resolve_entities: bool = False,
    **kwargs
) → _ElementTree

parse_etree Parses the provided xml into a document tree

Args:

  • xml_in (FileDataIn): the xml in
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"
  • resolve_entities (bool, optional): Whether to replace entities. Defaults to False

Returns:

  • etree._ElementTree: the document tree

function etree_to_str

etree_to_str(tree: _ElementTree, encoding: str = 'utf-8', **kwargs) → str

etree_to_str Serializes the document tree to a string

Args:

  • tree ( etree._ElementTree): the document tree
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"

Returns:

  • str: the xml string

function etree_element_to_str

etree_element_to_str(element: _Element, encoding: str = 'utf-8', **kwargs) → str

etree_element_to_str Serializes the document node to a string

Args:

  • element (etree._Element): the document node
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"

Returns:

  • str: the xml string

function load_xslt

load_xslt(
    stylesheet_in: Union[IO[str], IO[bytes], str, bytes],
    encoding: str = 'utf-8'
) → XSLT

load_xslt Loads the provided xslt stylesheet

Args:

  • stylesheet_in (DataIn): the stylesheet to load
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"

Returns:

  • etree.XSLT: the xslt object

function transform_xml_str

transform_xml_str(xslt: XSLT, xml: str) → str

transform_xml_str Transforms the provided xml string using the specified xslt object parsing the provided xml using the specified parser options passing any additional arguments to the xslt transformation

Args:

  • xslt (str): the xml to transform
  • encoding (str, optional): the character encoding to use. Defaults to "utf-8"

Returns:

  • str: the output of the transformation

This file was automatically generated via lazydocs.