module documentation
Provide any functions for transforming a "stringy" dict/list/value 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. |
| Function | _cast |
Cast date/datetime/time strings to date/datetime/time objects. |
| 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) -> TypedData:
(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, or (rarely) a str. |
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 | |
TypedData |
|
| Raises | |
ValueError | Up-typing a str failed due to an unexpected format. |
Cast date/datetime/time strings to date/datetime/time objects.
We can't currently store a time type in the intermediary YAML doc object (surgeon.data), so we mark times as special strs within surgeon.data, then do a second pass to convert them to time objects on the way out.
| Parameters | |
surgeon:Processor | A YAMLPath Processor with existing data to be up-typed. |
dateSequence[ | YAMLPath queries indicating nodes to be up-typed to date/datetime/time. |
| Returns | |
dict | list |
|
| 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. |