caspia.gateway.config.schema package¶
Submodules¶
caspia.gateway.config.schema.component module¶
-
class
caspia.gateway.config.schema.component.APDS9300SensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.apds9300.APDS9300Sensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.AnalogSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.analog.AnalogSensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.BlindsSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.ComponentSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
class
TimingSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.Schema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.ButtonSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.ComponentSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.ComponentSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.Schema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.DigitalInputSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.ComponentSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.digitalinput.DigitalInput.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.MCP980XSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.mcp980x.MCP980XSensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.NodeRefField(default=<marshmallow.missing>, attribute=None, load_from=None, dump_to=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata)[source]¶ Bases:
marshmallow.fields.String-
property
context¶ The context dictionary for the parent
Schema.
-
default_error_messages= {'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'}¶
-
deserialize(value, attr=None, data=None)¶ Deserialize
value.- Raises
ValidationError – If an invalid value is passed or if a required value is missing.
-
fail(key, **kwargs)¶ A helper method that simply raises a ValidationError.
-
get_value(attr, obj, accessor=None, default=<marshmallow.missing>)¶ Return the value for a given key from an object.
-
name= None¶
-
parent= None¶
-
property
root¶ Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize(attr, obj, accessor=None)¶ Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
- Parameters
attr (str) – The attibute or key to get from the object.
obj (str) – The object to pull the key from.
accessor (callable) – Function used to pull values from
obj.
- Raises
ValidationError – In case of formatting problem
-
property
-
class
caspia.gateway.config.schema.component.PinField(as_string=False, **kwargs)[source]¶ Bases:
marshmallow.fields.Integer-
property
context¶ The context dictionary for the parent
Schema.
-
default_error_messages= {'invalid': 'Not a valid integer.'}¶
-
deserialize(value, attr=None, data=None)¶ Deserialize
value.- Raises
ValidationError – If an invalid value is passed or if a required value is missing.
-
fail(key, **kwargs)¶ A helper method that simply raises a ValidationError.
-
get_value(attr, obj, accessor=None, default=<marshmallow.missing>)¶ Return the value for a given key from an object.
-
name= None¶
-
num_type¶ alias of
builtins.int
-
parent= None¶
-
property
root¶ Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize(attr, obj, accessor=None)¶ Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
- Parameters
attr (str) – The attibute or key to get from the object.
obj (str) – The object to pull the key from.
accessor (callable) – Function used to pull values from
obj.
- Raises
ValidationError – In case of formatting problem
-
property
-
class
caspia.gateway.config.schema.component.PinModeField(default=<marshmallow.missing>, attribute=None, load_from=None, dump_to=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata)[source]¶ Bases:
marshmallow.fields.String-
property
context¶ The context dictionary for the parent
Schema.
-
default_error_messages= {'invalid': 'Not a valid string.', 'invalid_utf8': 'Not a valid utf-8 string.'}¶
-
deserialize(value, attr=None, data=None)¶ Deserialize
value.- Raises
ValidationError – If an invalid value is passed or if a required value is missing.
-
fail(key, **kwargs)¶ A helper method that simply raises a ValidationError.
-
get_value(attr, obj, accessor=None, default=<marshmallow.missing>)¶ Return the value for a given key from an object.
-
name= None¶
-
parent= None¶
-
property
root¶ Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize(attr, obj, accessor=None)¶ Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
- Parameters
attr (str) – The attibute or key to get from the object.
obj (str) – The object to pull the key from.
accessor (callable) – Function used to pull values from
obj.
- Raises
ValidationError – In case of formatting problem
-
property
-
class
caspia.gateway.config.schema.component.RelaySchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.ComponentSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.S300Schema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.s300.S300Sensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.SCD30SensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.scd30.SCD30Sensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.SHT2XSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.sht2x.SHT2XSensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.SensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.ComponentSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.SerialSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.ComponentSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.component.TSL258XSensorGainControlField(as_string=False, **kwargs)[source]¶ Bases:
marshmallow.fields.Integer-
property
context¶ The context dictionary for the parent
Schema.
-
default_error_messages= {'invalid': 'Not a valid integer.'}¶
-
deserialize(value, attr=None, data=None)¶ Deserialize
value.- Raises
ValidationError – If an invalid value is passed or if a required value is missing.
-
fail(key, **kwargs)¶ A helper method that simply raises a ValidationError.
-
get_value(attr, obj, accessor=None, default=<marshmallow.missing>)¶ Return the value for a given key from an object.
-
name= None¶
-
num_type¶ alias of
builtins.int
-
parent= None¶
-
property
root¶ Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize(attr, obj, accessor=None)¶ Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
- Parameters
attr (str) – The attibute or key to get from the object.
obj (str) – The object to pull the key from.
accessor (callable) – Function used to pull values from
obj.
- Raises
ValidationError – In case of formatting problem
-
property
-
class
caspia.gateway.config.schema.component.TSL258XSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.component.SensorSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
config_cls¶ alias of
caspia.node.components.sensors.tsl258x.TSL258XSensor.Config
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
make_config(data)¶
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
caspia.gateway.config.schema.service module¶
-
class
caspia.gateway.config.schema.service.BlindsSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'blinds'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.ButtonSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
one_of= ('location',)¶
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'button'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.CarbonDioxideSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
one_of= ('s300', 'scd30')¶
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'carbon-dioxide-sensor'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.DoorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'door'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.ElectricityMeterSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'electricity-meter'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.FanSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'fan'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.HumiditySensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
one_of= ('sht2x', 'scd30')¶
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'humidity-sensor'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.IrrigationSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'irrigation'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.LightSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'light'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.LightSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
one_of= ('analog', 'apds9300', 'tsl258x')¶
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'light-sensor'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.LockMechanismSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'lock-mechanism'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.OutletSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'outlet'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.PumpSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'pump'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.ServiceSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
marshmallow.schema.Schema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class
-
class
caspia.gateway.config.schema.service.TemperatureSensorSchema(extra=None, only=None, exclude=(), prefix='', strict=None, many=False, context=None, load_only=(), dump_only=(), partial=False)[source]¶ Bases:
caspia.gateway.config.schema.service.ServiceSchema-
class
Meta¶ Bases:
objectOptions object for a Schema.
Example usage:
class Meta: fields = ("id", "email", "date_created") exclude = ("password", "secret_attribute")
Available options:
fields: Tuple or list of fields to include in the serialized result.additional: Tuple or list of fields to include in addition to theexplicitly declared fields.
additionalandfieldsare mutually-exclusive options.
include: Dictionary of additional fields to include in the schema. It isusually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords. May be an OrderedDict.
exclude: Tuple or list of fields to exclude in the serialized result.Nested fields can be represented with dot delimiters.
dateformat: Date format for all DateTime fields that do not have theirdate format explicitly specified.
strict: If True, raise errors during marshalling rather thanstoring them.
json_module: JSON module to use for loads and dumps.Defaults to the
jsonmodule in the stdlib.
ordered: If True, order serialization output according to theorder in which fields were declared. Output of Schema.dump will be a collections.OrderedDict.
index_errors: If True, errors dictionaries will include the indexof invalid items in a collection.
load_only: Tuple or list of fields to exclude from serialized results.dump_only: Tuple or list of fields to exclude from deserialization
-
OPTIONS_CLASS¶ alias of
marshmallow.schema.SchemaOpts
-
TYPE_MAPPING= {<class 'str'>: <class 'marshmallow.fields.String'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>}¶
-
classmethod
accessor(func)¶ Decorator that registers a function for pulling values from an object to serialize. The function receives the
Schemainstance, thekeyof the value to get, theobjto serialize, and an optionaldefaultvalue.Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
add_namespace(data)¶
-
check_one_of(data)¶
-
property
dict_class¶
-
dump(obj, many=None, update_fields=True, **kwargs)¶ Serialize an object to native Python data types according to this Schema’s fields.
- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
dumps(obj, many=None, update_fields=True, *args, **kwargs)¶ Same as
dump(), except return a JSON-encoded string.- Parameters
obj – The object to serialize.
many (bool) – Whether to serialize obj as a collection. If None, the value for self.many is used.
update_fields (bool) – Whether to update the schema’s field classes. Typically set to True, but may be False when serializing a homogenous collection. This parameter is used by fields.Nested to avoid multiple updates.
- Returns
A tuple of the form (
data,errors)- Return type
MarshalResult, a collections.namedtuple
New in version 1.0.0.
-
classmethod
error_handler(func)¶ Decorator that registers an error handler function for the schema. The function receives the
Schemainstance, a dictionary of errors, and the serialized object (if serializing data) or data dictionary (if deserializing data) as arguments.Example:
class UserSchema(Schema): email = fields.Email() @UserSchema.error_handler def handle_errors(schema, errors, obj): raise ValueError('An error occurred while marshalling {}'.format(obj)) user = User(email='invalid') UserSchema().dump(user) # => raises ValueError UserSchema().load({'email': 'bademail'}) # raises ValueError
New in version 0.7.0.
Deprecated since version 2.0.0: Set the
error_handlerclass Meta option instead.
-
classmethod
get(service_type)¶
-
get_attribute(attr, obj, default)¶ Defines how to pull values from an object to serialize.
New in version 2.0.0.
-
handle_error(error, data)¶ Custom error handler function for the schema.
- Parameters
error (ValidationError) – The ValidationError raised during (de)serialization.
data – The original input data.
New in version 2.0.0.
-
load(data, many=None, partial=None)¶ Deserialize a data structure to an object defined by this Schema’s fields and
make_object().- Parameters
data (dict) – The data to deserialize.
many (bool) – Whether to deserialize data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
loads(json_data, many=None, *args, **kwargs)¶ Same as
load(), except it takes a JSON string as input.- Parameters
json_data (str) – A JSON string of the data to deserialize.
many (bool) – Whether to deserialize obj as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A tuple of the form (
data,errors)- Return type
UnmarshalResult, a collections.namedtuple
New in version 1.0.0.
-
on_bind_field(field_name, field_obj)¶ Hook to modify a field when it is bound to the Schema. No-op by default.
-
one_of= ('analog', 'mcp980x', 'sht2x', 'scd30')¶
-
opts= <marshmallow.schema.SchemaOpts object>¶
-
property
set_class¶
-
type= 'temperature-sensor'¶
-
validate(data, many=None, partial=None)¶ Validate data against the schema, returning a dictionary of validation errors.
- Parameters
data (dict) – The data to validate.
many (bool) – Whether to validate data as a collection. If None, the value for self.many is used.
partial (bool|tuple) – Whether to ignore missing fields. If None, the value for self.partial is used. If its value is an iterable, only missing fields listed in that iterable will be ignored.
- Returns
A dictionary of validation errors.
- Return type
dict
New in version 1.1.0.
-
class