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.DateTime- A 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 Python- tzinfoobject. If- default_tzinfois not specified the default tzinfo will be equivalent to UTC (Zulu time). The- default_tzinfotzinfo object is used to convert ‘naive’ datetimes to a timezone-aware representation during serialization. If- default_tzinfois explicitly set to- Nonethen 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, the- err_templateattribute is the string- Invalid date. This string is used as the interpolation subject of a dictionary composed of- valand- err.- valand- errare 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 the- default_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 the- default_tzinfoto give the serialization a timezone.- If the - colander.nullvalue is passed to the serialize method of this class, the- colander.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.Tuple- A 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.Tuple- A 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.List- A 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.Sequence- A subclass of - colander.Sequencethat converts itself to a numpy array using- gnome.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 - nodeand- cstructarguments, 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_scalaris- Trueand the- cstructdoes not have an- __iter__method or is a mapping type, the value will be turned into a single element list.- If - accept_scalaris- Falseand the- cstructdoes not have an- __iter__method or is a mapping type, an- colander.Invaliderror will be raised during serialization and deserialization.- The default of - accept_scalaris- None, which means respect the default- accept_scalarvalue attached to this instance via its constructor.
 
- class gnome.persist.extend_colander.DatetimeValue1dArray(accept_scalar=False)
- Bases: - colander.Sequence- A subclass of - colander.Sequencethat converts itself to a numpy array using- gnome.basic_types.datetime_value_2das the data type.- serialize(node, appstruct)
- Along with the normal - nodeand- appstructarguments, 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_scalaris- Trueand the- appstructdoes not have an- __iter__method or is a mapping type, the value will be turned into a single element list.- If - accept_scalaris- Falseand the- appstructdoes not have an- __iter__method or is a mapping type, an- colander.Invaliderror will be raised during serialization and deserialization.- The default of - accept_scalaris- None, which means respect the default- accept_scalarvalue attached to this instance via its constructor.
 - deserialize(node, cstruct)
- Along with the normal - nodeand- cstructarguments, 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_scalaris- Trueand the- cstructdoes not have an- __iter__method or is a mapping type, the value will be turned into a single element list.- If - accept_scalaris- Falseand the- cstructdoes not have an- __iter__method or is a mapping type, an- colander.Invaliderror will be raised during serialization and deserialization.- The default of - accept_scalaris- None, which means respect the default- accept_scalarvalue attached to this instance via its constructor.
 
- class gnome.persist.extend_colander.TimeDelta
- Bases: - colander.Float- Add a type to serialize/deserialize timedelta objects - serialize(node, appstruct)
 - deserialize(*args, **kwargs)
 
- class gnome.persist.extend_colander.OrderedCollectionType(accept_scalar=False)
- Bases: - colander.Sequence- A 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_scalaris- Trueand 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_scalaris- Falseand the value does not have an- __iter__method or is a mapping type, an- colander.Invaliderror will be raised during serialization and deserialization.- The default value of - accept_scalaris- False.- If the - colander.nullvalue is passed to the serialize method of this class, the- colander.nullvalue is returned.