marsh.schema.template

A set of template implementations of schemas.

These templates are useful as base classes when extending the framework to support more types.

class CallableUnmarshalSchema(*args, **kwargs)[source]

Unmarshals the arguments to a callable and uses them to call it.

Parameters:

value (Type[_T]) –

schemas: Mapping[str, UnmarshalSchema]

The schemas for the fixed attributes.

construct(*args, **kwargs)

Takes the unmarshaled arguments to the type as input and initializes an instance of the type using these arguments.

Return type:

TypeVar(_T)

Returns:

The initialized value.

class MappingUnmarshalSchema(*args, default='???', default_factory='???', **kwargs)[source]

A schema for a type with dynamic keys and values.

Parameters:

value (Type[_T]) –

key_schema: UnmarshalSchema

The schema for the key type.

value_schema: UnmarshalSchema

The schema for the value type.

construct(value)[source]

Build an instance of the type from unmarshaled keys and values.

Parameters:

value (Mapping) – The unmarshaled keys and values.

Return type:

TypeVar(_T)

Returns:

An instance of the type.

class SequenceUnmarshalSchema(*args, default='???', default_factory='???', **kwargs)[source]

A schema for a dynamic sequence of values.

Parameters:

value (Type[_T]) –

value_schema: UnmarshalSchema

The schema for the value type.

construct(value)[source]

Build an instance of the type from unmarshaled values.

Parameters:

value (Sequence) – The unmarshaled values.

Return type:

TypeVar(_T)

Returns:

An instance of the type.

class StructuredUnmarshalSchema(*args, default='???', default_factory='???', **kwargs)[source]

A schema for types with fixed attributes that are recursively unmarshaled.

Supports both positional arguments and keyword arguments. Variable versions of these arguments (typically *args/**kwargs) are also supported and are marked by * or ** infront of their names in the schemas attribute of this class.

Parameters:

value (Type[_T]) –

schemas: Mapping[str, UnmarshalSchema]

The schemas for the fixed attributes.

construct(*args, **kwargs)[source]

Takes the unmarshaled arguments to the type as input and initializes an instance of the type using these arguments.

Return type:

TypeVar(_T)

Returns:

The initialized value.

class UnionUnmarshalSchema(*args, default='???', default_factory='???', **kwargs)[source]

A schema for a union of types.

The order of the types is reflected in the order of attempted unmarshals. The value of the first type that is successfully unmarshaled is returned.

If all types failed to unmarshal an error is raised.

Parameters:

value (Type[_T]) –

schemas: Sequence[UnmarshalSchema]

The schemas for the union of types.