fqr.core.codecs.utl module¶
Codecs utility functions.
- encode(value: Any) bool | float | int | None | str | dict[bool | float | int | None | str, Serial] | list[Serial]¶
JSON encode
valueusing a corresponding encoder, otherwise returnsrepr(value).
- parse(value: AnyType, tp: type[VariadicArrayType] | type[ArrayType] | type[MappingType] | type[SupportsAnnotations] | type[AnyType]) VariadicArrayType | ArrayType | MappingType | SupportsAnnotations | AnyType | ParseErrorRef¶
Try to recursively parse python
tpfromvalue.Value should either be an instance of
tpor a valid, serialized representation of thattp(JSON string or otherwise).Returns
enm.ParseErrorRefif no valid type could be parsed, allowing for downstream validation instead of immediately raising an exception within this function.
- serialize(value: Any) str¶
Convert value to string.
- try_decode(value: Any, tp: type[AnyType]) AnyType | ParseErrorRef¶
Attempt to parse value, returning
enm.ParseErrorRefif error.
- try_parse_json(json_string: str) bool | float | int | None | str | dict[bool | float | int | None | str, Serial] | list[Serial] | ParseErrorRef¶
Attempt to parse valid JSON string, returning
enm.ParseErrorRefif error.