text
¶
Module Contents¶
Functions¶
|
Safely format a python string using % and a dictionary for values. |
|
Safely convert bytes to a python string. |
- text.format_with_dict(pattern: str, values: dict[str, str]) str ¶
Safely format a python string using % and a dictionary for values.
This method is safer than using directly percent as it will escape automatically % in the pattern that cannot be replaced.
- Parameters:
pattern – a string that should be formatted
values – a dictionary containing the values of the keys that can be replaced
- text.bytes_as_str(content: bytes) str ¶
Safely convert bytes to a python string.
This function attempts the conversion assuming a utf-8 enconding. If this triggers a conversion error, it then falls back to a safe representation, where some characters might be escaped.
- Parameters:
content – content to be transformed
- Returns:
a string