Module tenlib.transform.generic

Functions

def multiform(function: Callable[Concatenate[~OriginalType, ~OriginalParams], ~OriginalRetType])

Decorator converting a function expecting a single argument of type str or bytes into a function that applies additionally to a string or every value of a list, dict, set or TenDict, and its sub-elements.

def wrap_join_format(wrapper: str = '{}', formatter: str = '{}', jointure: str = ',', empty: str = None) ‑> Callable[[bytes], str]

Generates a function that takes one parameter, data. For every byte in data, it will format them using format, join them using jointure, and wrap the whole thing using wrapper. If the given data is empty, and empty is set, the latter is returned instead.

Examples

>>> wrap_join_format(b'ABC')
'65,66,67'
>>> wrap_join_format(formatter='{:c}', jointure='')(b'ABC')
'ABC'
>>> wrap_join_format('CONCAT({})', 'CHR(0x{:02x})')('ABC')
'CONCAT(CHR(0x41),CHR(0x42),CHR(0x43))'
>>> wrap_join_format(empty='something_else')('')
'something_else'
def to_bytes(data: bytes) ‑> bytes

Converts the parameter into bytes.

def to_str(data: str) ‑> str

Converts the parameter to a string.

def strip(data: bytes, chars=None) ‑> bytes

Calls data.strip() on every element of the object.

def not_empty(data: list) ‑> list

Removes empty items from a list.