text
====

.. py:module:: text


Functions
---------

.. autoapisummary::

   text.format_with_dict
   text.bytes_as_str


Module Contents
---------------

.. py:function:: 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.

   :param pattern: a string that should be formatted
   :param values: a dictionary containing the values of the keys that can be
       replaced


.. py:function:: 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.

   :param content: content to be transformed
   :return: a string


