Bases: flatland.schema.base.Element
Holds other schema items.
Base class for elements that can contain other elements, such as List and Dict.
Parameters: |
|
---|
Return a class with descent validators set to *validators.
Parameter: | *validators – one or more validator functions, replacing any descent validators present on the class. |
---|---|
Returns: | a new class |
Return a class with additional descent *validators.
Parameters: |
|
---|---|
Returns: | a new class |
Validates on the first (downward) and second (upward) pass.
If descent_validators are defined on the schema, they will be evaluated before children are validated. If a validation function returns flatland.SkipAll or flatland.SkipFalse, downward validation will halt on this container and children will not be validated.
If validators are defined, they will be evaluated after children are validated.
See FieldSchema.validate_element().
>>> from flatland import List, String
>>> Names = List.named('names').of(String.named('name'))
>>> pruned = Names()
>>> pruned.set_flat([('names_0_name', 'first'),
... ('names_99_name', 'last')])
>>> pruned.value
[u'first', u'last']
>>> unpruned = Names(prune_empty=False)
>>> unpruned.set_flat([('names_0_name', 'first'),
... ('names_99_name', 'last')])
>>> len(unpruned.value)
100
>>> unpruned.value[0:3]
[u'first', None, None]
Bases: flatland.schema.containers.Container, list
Abstract base of sequence-like Containers.
Instances of Sequence hold other elements and operate like Python lists. Each sequence member will be an instance of member_schema.
Python list methods and operators may be passed instances of member_schema or plain Python values. Using plain values is a shorthand for creating an member_schema instance and set()ting it with the value:
>>> from flatland import Array, Integer
>>> Numbers = Array.of(Integer)
>>> ones = Numbers()
>>> ones.append(1)
>>> ones
[<Integer None; value=1>]
>>> another_one = Integer()
>>> another_one.set(1)
True
>>> ones.append(another_one)
>>> ones
[<Integer None; value=1>, <Integer None; value=1>]