Newer
Older
A collection of simple python utilities each file can be used as it's own.
Drop in replacement for a better Display class
## parsing.py
Basic functions to help parse Text and booleans.
[TODO] need more documentation
### `to_text(obj, encoding='utf-8', nonstring: str = 'simplerepr')`
### `to_bytes(obj, encoding='utf-8', nonstring: str = 'simplerepr')`
Make sure that a string is a byte string
:param `obj`: An object to make sure is a byte string. In most cases this
will be either a text string or a byte string. However, with
``nonstring='simplerepr'``, this can be used as a traceback-free
version of ``str(obj)``.
:param `encoding`: The encoding to use to transform from a text string to
a byte string. Defaults to using 'utf-8'.
:param `nonstring`: The strategy to use if a nonstring is specified in
`obj`. Default is 'simplerepr'. Valid values are:
:simplerepr: The default. This takes the `str` of the object and
then returns the bytes version of that string.
:empty: Return an empty byte string
:passthru: Return the object passed in
:strict: Raise a :exc:`TypeError`
:return: Typically this returns a byte string. If a nonstring object is
passed in this may be a different type depending on the strategy
specified by nonstring. This will never return a text string.
.. note:: If passed a byte string, this function does not check that the
string is valid in the specified encoding. If it's important that the
byte string is in the specified encoding do::
`encoded_string = to_bytes(to_text(input_string, 'latin-1'), 'utf-8')`
### `boolean(value)`
This collection is free software: you can redistribute it and/or modify it
under the terms of the MIT License as published by the Free Software Foundation.
You should have received a copy of the GNU Lesser General Public License
along with rpmd. If not, see <http://www.gnu.org/licenses/mit>.