object_parser package¶
Submodules¶
object_parser.errors module¶
- class object_parser.errors.ErrorMessages[source]¶
Bases:
object
A static class with can be subclassed
- object_parser.errors.to_string(errors: BuildErrors) str [source]¶
object_parser.factory module¶
- class object_parser.factory.Factory(cls: type, parent_keys: ~typing.List[str] = None, *, errors=<class 'mash.object_parser.errors.ErrorMessages'>)[source]¶
Bases:
ABC
An interface for instantiating objects from json-like data.
- build(data={})[source]¶
Initialize self.cls with fields from data. All child objects are recursively instantiated as well, based on type annotations.
See object_parser_example.py for a larger usecase example.
Raises¶
BuildError (for a single field)
BuildErrors (for multiple invalid fields).
User-defineable methods¶
Process values - cls.parse_value() can be used to pre-process input values before instantiating objects - cls.__post_init__() can be used to check an object after initialization
Process keys - cls.parse_key() can be used to pre-process input keys. - cls.verify_key_format() defaults to verify_key_format - cls._key_synonyms: dict can be used to define alternative keys
object_parser.oas module¶
Generate a OAS/Swagger component See: [OAS](https://swagger.io/specification/)
- class object_parser.oas.K[source]¶
Bases:
object
OAS keys
- components = 'components'¶
- doc = 'description'¶
- props = 'properties'¶
- schemas = 'schemas'¶
- class object_parser.oas.OAS(*args, **kwds)[source]¶
Bases:
dict
A key-value map that represents an OAS. It that can be converted to JSON or YAML and viewed in: https://editor.swagger.io/
- property components¶
- extend(obj: object)[source]¶
Generate OAS/Swagger components from a class See: [OAS](https://swagger.io/specification/) E.g.
components: schemas: User: properties: id: type: integer name: type: string
object_parser.object_parser module¶
Parse json-like data and init objects such as dataclasses.
# Classes
factory.Factory is a generic interface.
factory.JSONFactory is a concrete implementation.
errors.ErrorMessages exposes a few custom strings.
object_parser.object_parser_standards module¶
- class object_parser.object_parser_standards.A(x: int = 0, y: int = 1, z: int = 10)[source]¶
Bases:
object
- class object_parser.object_parser_standards.B(left: object_parser.object_parser_standards.A, right: object_parser.object_parser_standards.A, top: object_parser.object_parser_standards.A, bottom: object_parser.object_parser_standards.A)[source]¶
Bases:
object
- class object_parser.object_parser_standards.C(a: object_parser.object_parser_standards.A, b: object_parser.object_parser_standards.B, x: int, y: float, z: List[object_parser.object_parser_standards.A])[source]¶
Bases:
object