csb43.utils¶
Utils.
- csb43.utils.b_left_pad(bvalue, n, fill=b' ')¶
Pad with fill chars at the leftside and return a record of n chars”.
- Parameters:
bvalue (bytes)
n (int)
fill (bytes)
- Return type:
bytes
- csb43.utils.b_right_pad(bvalue, n, fill=b' ')¶
Pad with fill chars at the rightside and return a record of n chars.
- Parameters:
bvalue (bytes)
n (int)
fill (bytes)
- Return type:
bytes
- csb43.utils.export_currency_code(value)¶
Export currency code as string.
- Parameters:
value (Any)
- Return type:
str
- csb43.utils.export_date(value)¶
Export a date as a string.
- Parameters:
value (Any)
- Return type:
str
- csb43.utils.export_decimal(value, fallback=None)¶
Export decimal as a serializable type.
- Parameters:
value (Decimal)
fallback (_T | None)
- Return type:
Decimal | float | str | _T
- csb43.utils.force_notnull(value)¶
Raise ValueError if value is None, otherwise return value.
- Parameters:
value (_T | None)
- Return type:
_T
- csb43.utils.nullable(f)¶
Decorate a function as nullable.
Return None if function value is None
- Parameters:
f (Callable[[Concatenate[_T, ~_P]], _R])
- Return type:
_Nullable[_T, _R, ~_P]
Currency definitions.
- class csb43.utils.currency.AnyCurrency(*args, **kwargs)¶
Protocol for a currency object compatible with pycountry.
- class csb43.utils.currency.CurrencyLite(alpha_3, numeric)¶
A cheap alternative to pycountry Currency.
- Parameters:
alpha_3 (str | None)
numeric (str | None)
- csb43.utils.currency.currency_from_iso_code(code)¶
Convert a ISO code to a currency.
Return AnyCurrency from an ISO 4217 numeric or letter code.
Return None if no code was found.
- Parameters:
code (str)
- Return type:
AnyCurrency | None
- csb43.utils.currency.currency_from_iso_letter(alpha_3)¶
Return a currency object from an alpha_3 ISO 4217 code.
- Parameters:
alpha_3 (str)
- Return type:
- csb43.utils.currency.currency_from_iso_number(numeric)¶
Return a currency object from a numeric ISO 4217 code.
- Parameters:
numeric (str | None)
- Return type:
AnyCurrency | None
- csb43.utils.currency.is_currency(obj)¶
Return True is obj is a currency object.
- Parameters:
obj (Any)
- Return type:
bool
- csb43.utils.currency.simplify_currency(obj)¶
Convert currency to CurrencyLite.
- Parameters:
obj (AnyCurrency)
- Return type:
- csb43.utils.currency.yaml_currency_representer(dumper, obj)¶
Return a serializable object for yaml.
A yaml representer for AnyCurrency.
- Parameters:
dumper (SafeRepresenter)
obj (AnyCurrency)
- Return type:
ScalarNode
Functions for tabulated strings manipulation.
- csb43.utils.tabulated.adjust_table_width(data, delim='||', gap=1, indent=0)¶
Adjust width for columns marked by sep.
- Parameters:
data (Sequence[str])
delim (str)
gap (int)
indent (int)
- Return type:
Iterator[str]