module documentation
Provide any functions for transforming a "stringy" dict/list to one with more types.
In practice, this is just cast_stringy_data
and any support functions it needs.
Function | cast |
Take nested StringyData and return a copy with matching nodes up-typed. |
Type Alias |
|
Undocumented |
Type Alias |
|
Undocumented |
Function | _str |
Translate a commonly used boolean str into a real bool. |
Function | _str |
Translate an ISO 8601 date/time str into a date, datetime, or marked time str. |
Function | _str |
Translate a number as str into a real int or float. |
def cast_stringy_data(data:
StringyData
, bool_paths: Sequence[ str]
= (), null_paths: Sequence[ str]
= (), num_paths: Sequence[ str]
= (), date_paths: Sequence[ str]
= (), converter: Converter | None
= None) -> list | dict
:
(source)
¶
Take nested StringyData and return a copy with matching nodes up-typed.
Parameters | |
data:StringyData | A dict or list composed of str, dict and list items all the way down. |
boolSequence[ | YAMLPath queries indicating nodes to be up-typed to bool. |
nullSequence[ | YAMLPath queries indicating nodes to be up-typed to None. |
numSequence[ | YAMLPath queries indicating nodes to be up-typed to int/float. |
dateSequence[ | YAMLPath queries indicating nodes to be up-typed to date/datetime/time. |
converter:Converter | None | A Converter used to unstructure the result
to match specific type support,
defaulting to one created with mk_json_types_converter . |
Returns | |
list | dict |
|
Raises | |
ValueError | Up-typing a str failed due to an unexpected format. |
Translate a commonly used boolean str into a real bool.
Parameters | |
informalstr | A boolean represented as str, like "true", "no", "off", etc. |
Returns | |
bool | True or False to match the intent of informal_bool. |
Raises | |
ValueError | This doesn't look like enough like a bool to translate. |
Translate an ISO 8601 date/time str into a date, datetime, or marked time str.
Parameters | |
informalstr | An ISO 8601 date/time str. |
timestr | An arbitrary prefix (such as a UUID) which will be used to create a "marked time" str, rather than an (unyamlable) time instance. |
Returns | |
date | datetime | str |
|
Raises | |
ValueError | This doesn't look like enough like a date/time to translate. |