Bases: flatland.schema.base.Element
The base implementation of simple values such as a string or number.
Scalar subclasses are responsible for translating the most common data types in and out of Python-native form: strings, numbers, dates, times, Boolean values, etc. Any data which can be represented by a single (name, value) pair is a likely Scalar.
Scalar subclasses have two responsibilities: provide a method to adapt a value to native Python form, and provide a method to serialize the native form to a Unicode string.
This class is abstract.
Given any value, try to coerce it into native format.
Returns: | the native format or raises AdaptationError on failure. |
---|
This abstract method is called by set().
Given any value, coerce it into a Unicode representation.
Returns: | Must return a Unicode object, always. |
---|
No special effort is made to coerce values not of native or a compatible type.
This semi-abstract method is called by set(). The base implementation returns unicode(value).
Assign the native and Unicode value.
Returns: | True if adaptation of value was successful. |
---|
Attempts to adapt the given value and assigns this element’s value and u attributes in tandem.
If adaptation succeeds, .value will contain the adapted native Python value and .u will contain a Unicode serialized version of it. A native value of None will be represented as u'' in .u.
If adaptation fails, .value will be None and .u will contain unicode(value) or u'' for none.
Validates on the first, downward pass.
See FieldSchema.validate_element().
Bases: flatland.schema.scalars.Scalar
A regular old Unicode string.
Return a Unicode representation.
Returns: | a unicode value or None |
---|
If strip is true, leading and trailing whitespace will be removed.
Return a Unicode representation.
Returns: | a unicode value or u'' if *value* is ``None |
---|
If strip is true, leading and trailing whitespace will be removed.
Bases: flatland.schema.scalars.Scalar
Base for numeric fields.
Subclasses provide type_ and format attributes for adapt() and serialize().
Generic numeric coercion.
Returns: | an instance of type_ or None |
---|
Attempt to convert value using the class’s type_ callable.
Generic numeric serialization.
Returns: | a unicode string formatted with format or the unicode() of value if value is not of type_ |
---|
Converts value to a string using Python’s string formatting function and the format as the template. The value is provided to the format as a single, positional format argument.
Bases: flatland.schema.scalars.Number
Element type for Python’s int.
Bases: flatland.schema.scalars.Number
Element type for Python’s long.
Bases: flatland.schema.scalars.Number
Element type for Python’s float.
Bases: flatland.schema.scalars.Number
Element type for Python’s Decimal.
Bases: flatland.schema.scalars.Scalar
Element type for Python’s bool.
Coerce value to bool.
Returns: | a bool or None |
---|
If value is a string, returns True if the value is in true_synonyms, False if in false_synonyms and None otherwise.
For non-string values, equivalent to bool(value).
Convert bool(value) to a canonical string representation.
Returns: | either self.true or self.false. |
---|
A sequence of acceptable string equivalents for False.
Defaults to (u'off', u'false', u'False', u'0', u'')
A sequence of acceptable string equivalents for True.
Defaults to (u'on', u'true', u'True', u'1')