gnome.persist.extend_colander
Extend colander’s basic types for serialization/deserialization of gnome specific types
Classes
A type representing a Python |
|
A Tuple subclass that provides defaults from child nodes. |
|
A subclass of |
|
A subclass of |
|
A subclass of |
|
A subclass of |
|
Add a type to serialize/deserialize timedelta objects |
|
A type which represents a variable-length sequence of nodes, |
Module Contents
- class gnome.persist.extend_colander.LocalDateTime(*args, **kwargs)
Bases:
colander.DateTimeA type representing a Python
datetime.datetimeobject.This type serializes python
datetime.datetimeobjects to a ISO8601 string format. The format includes the date, the time, and the timezone of the datetime.The constructor accepts an argument named
default_tzinfowhich should be a Pythontzinfoobject. Ifdefault_tzinfois not specified the default tzinfo will be equivalent to UTC (Zulu time). Thedefault_tzinfotzinfo object is used to convert ‘naive’ datetimes to a timezone-aware representation during serialization. Ifdefault_tzinfois explicitly set toNonethen no default tzinfo will be applied to naive datetimes.You can adjust the error message reported by this class by changing its
err_templateattribute in a subclass on an instance of this class. By default, theerr_templateattribute is the stringInvalid date. This string is used as the interpolation subject of a dictionary composed ofvalanderr.valanderrare the unvalidatable value and the exception caused trying to convert the value, respectively. These may be used in an overridden err_template as${val}and${err}respectively as necessary, e.g._('${val} cannot be parsed as an iso8601 date: ${err}').For convenience, this type is also willing to coerce
datetime.dateobjects to a DateTime ISO string representation during serialization. It does so by using midnight of the day as the time, and uses thedefault_tzinfoto give the serialization a timezone.Likewise, for convenience, during deserialization, this type will convert
YYYY-MM-DDISO8601 values to a datetime object. It does so by using midnight of the day as the time, and uses thedefault_tzinfoto give the serialization a timezone.If the
colander.nullvalue is passed to the serialize method of this class, thecolander.nullvalue will be returned.The subnodes of the
colander.SchemaNodethat wraps this type are ignored.- strip_timezone(_datetime)
- serialize(node, appstruct)
Serialize a DateTime object
returns an iso formatted string
- deserialize(node, cstruct)
- class gnome.persist.extend_colander.DefaultTuple
Bases:
colander.TupleA Tuple subclass that provides defaults from child nodes.
Required because Tuple returns colander.null by default when
appstructis not provided, instead of creating a Tuple of default values.- serialize(node, appstruct)
- class gnome.persist.extend_colander.NumpyFixedLen
Bases:
colander.TupleA subclass of
colander.Tuplethat converts itself to a Tuple and back to a numpy array. This is used to define schemas for Numpy arrays that have a fixed size like WorldPoint, 3D velocity of SimpleMover.- serialize(node, appstruct)
Serialize a fixed length numpy array
- deserialize(node, cstruct)
- class gnome.persist.extend_colander.NumpyArray
Bases:
colander.ListA subclass of
colander.Listthat converts itself to a more general numpy array of greater than length 1.- serialize(node, appstruct)
Serialize a numpy array
- deserialize(node, cstruct)
- class gnome.persist.extend_colander.DatetimeValue2dArray(accept_scalar=False)
Bases:
colander.SequenceA subclass of
colander.Sequencethat converts itself to a numpy array usinggnome.basic_types.datetime_value_2das the data type.- todo: serialize/deserialize must happen for each element - not very
efficient.
- serialize(node, appstruct)
Serialize a 2D Datetime value array
- deserialize(node, cstruct)
Along with the normal
nodeandcstructarguments, this method accepts an additional optional keyword argument:accept_scalar. This keyword argument can be used to override the constructor value of the same name.If
accept_scalarisTrueand thecstructdoes not have an__iter__method or is a mapping type, the value will be turned into a single element list.If
accept_scalarisFalseand thecstructdoes not have an__iter__method or is a mapping type, ancolander.Invaliderror will be raised during serialization and deserialization.The default of
accept_scalarisNone, which means respect the defaultaccept_scalarvalue attached to this instance via its constructor.
- class gnome.persist.extend_colander.DatetimeValue1dArray(accept_scalar=False)
Bases:
colander.SequenceA subclass of
colander.Sequencethat converts itself to a numpy array usinggnome.basic_types.datetime_value_2das the data type.- serialize(node, appstruct)
Along with the normal
nodeandappstructarguments, this method accepts an additional optional keyword argument:accept_scalar. This keyword argument can be used to override the constructor value of the same name.If
accept_scalarisTrueand theappstructdoes not have an__iter__method or is a mapping type, the value will be turned into a single element list.If
accept_scalarisFalseand theappstructdoes not have an__iter__method or is a mapping type, ancolander.Invaliderror will be raised during serialization and deserialization.The default of
accept_scalarisNone, which means respect the defaultaccept_scalarvalue attached to this instance via its constructor.
- deserialize(node, cstruct)
Along with the normal
nodeandcstructarguments, this method accepts an additional optional keyword argument:accept_scalar. This keyword argument can be used to override the constructor value of the same name.If
accept_scalarisTrueand thecstructdoes not have an__iter__method or is a mapping type, the value will be turned into a single element list.If
accept_scalarisFalseand thecstructdoes not have an__iter__method or is a mapping type, ancolander.Invaliderror will be raised during serialization and deserialization.The default of
accept_scalarisNone, which means respect the defaultaccept_scalarvalue attached to this instance via its constructor.
- class gnome.persist.extend_colander.TimeDelta
Bases:
colander.FloatAdd a type to serialize/deserialize timedelta objects
- serialize(node, appstruct)
- deserialize(*args, **kwargs)
- class gnome.persist.extend_colander.OrderedCollectionType(accept_scalar=False)
Bases:
colander.SequenceA type which represents a variable-length sequence of nodes, all of which must be of the same type.
The type of the first subnode of the
colander.SchemaNodethat wraps this type is considered the sequence type.The optional
accept_scalarargument to this type’s constructor indicates what should happen if the value found during serialization or deserialization does not have an__iter__method or is a mapping type.If
accept_scalarisTrueand the value does not have an__iter__method or is a mapping type, the value will be turned into a single element list.If
accept_scalarisFalseand the value does not have an__iter__method or is a mapping type, ancolander.Invaliderror will be raised during serialization and deserialization.The default value of
accept_scalarisFalse.If the
colander.nullvalue is passed to the serialize method of this class, thecolander.nullvalue is returned.