Utility functionality
String helper functions
Module for the string helper functions and primitive data types.
Classes:
Implementation of the error message. |
Functions:
|
Parse a string value to the appropriate Python object. |
- class configflow.misc.string.ErrorMessage[source]
Bases:
str
Implementation of the error message.
Notes
By default, error messages in the exceptions don’t support line breaks or any formatting, this decorator is solving that problem.
References
1. New line on error message in KeyError - Python 3.3
Methods:
__repr__
()Get object representation.
- __repr__() str [source]
Get object representation.
Examples
>>> msg = ErrorMessage("\nInvalid argument: 'db'.\nExpected arguments: ['db2', 'port'].") >>> repr(msg) \nInvalid argument: 'db'.\nExpected arguments: ['db2', 'port']. >>> raise ValueError(msg) Traceback (most recent call last): ... ValueError: Invalid argument: 'db'. Expected arguments: ['db2', 'port'].
- configflow.misc.string.parse(value: str) Optional[Any] [source]
Parse a string value to the appropriate Python object.
Notes
If a value is a sequence
list | tuple | set
thenparse
function will be applied to each element of a sequence.Warning
Currently
parse
function supports only primitive data typesint | str | float
and sequenceslist | tuple | set
. Sequences such asdict
will be returned as they are without parsing their inner values.Examples
>>> parse("1.2") 1.2 >>> parse("(1, 2, '3')") (1, 2, 3) >>> parse("['85', '0.23', 'cleffa', ['10', ['0.123'], 'blipbug']]") [85, 0.23, 'cleffa', [10, [0.123], 'blipbug']]