A mapping container that acts like a scalar value.
Compound fields are dictionary-like fields that can assemble a u and value from their children, and can decompose a structured value passed to a set() into values for its children.
A simple example is a logical calendar date field composed of 3 separate Integer component fields, year, month and day. The Compound can wrap the 3 parts up into a single logical field that handles datetime.date values. Set a date on the logical field and its component fields will be set with year, month and day; alter the int value of the year component field and the logical field updates the date to match.
Composites run validation after their children.
Return a unicode, native tuple built from children’s state.
|Returns:||a 2-tuple of unicode representation, native value. These correspond to the Scalar.serialize_element() and Scalar.adapt_element() methods of Scalar objects.|
For example, a compound date field may return a ‘-‘ delimited string of year, month and day digits and a datetime.date.
Given a compound value, assign values to children.
|Parameter:||value – a value to be adapted and exploded|
For example, a compound date field may read attributes from a datetime.date value and set() them on child fields.
The decision to perform type checking on value is completely up to you and you may find you want different rules for different compound types.
A sequence container that acts like a compounded string such as CSV.
Marshals child element values to and from a single string:
>>> from flatland import JoinedString >>> el = JoinedString(['x', 'y', 'z']) >>> el.value u'x,y,z' >>> el2 = JoinedString('foo,bar') >>> el2.value u'bar' >>> el2.value u'foo,bar'
Only the joined representation is considered when flattening or restoring with set_flat(). JoinedStrings run validation after their children.
Optional, a regular expression, used preferentially to split an incoming separated value into components. Used in combination with separator, a permissive parsing policy can be combined with a normalized representation, e.g.:
>>> import re >>> schema = JoinedString.using(separator=', ', ... separator_regex=re.compile('\s*,\s*')) ... >>> schema('a , b,c,d').value u'a, b, c, d'