/
interfaces.py
54 lines (43 loc) · 2.03 KB
/
interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def Validator(struct, value):
"""
A validator is called after deserialization of a value.
If ``value`` is not valid, raise a :class:`colander.Invalid`
instance as an exception after.
``struct`` is a :class:`colander.Structure` instance which
contains, among other things, the default value, the name of the
value, and a ``required`` flag indicating whether this value is
required. It is often ignored in simple validators.
"""
class Type(object):
def serialize(self, struct, value):
"""
Serialize the object represented by ``value`` to a
data structure. The serialization should be composed of one or
more objects which can be deserialized by the
:meth:`colander.interfaces.Type.deserialize` method of this
type.
This method should also do type validation of ``value``.
``struct`` is a :class:`colander.Structure` instance which
contains, among other things, the default value, the name of
the value, and a ``required`` flag indicating whether this
value is required.
If the object cannot be serialized, or type validation for
``value`` fails, a :exc:`colander.Invalid` exception should be
raised.
"""
def deserialize(self, struct, value):
"""
Deserialze the serialization represented by ``value`` to a
data structure. The deserialization should be composed of one
or more objects which can be serialized by the
:meth:`colander.interfaces.Type.serialize` method of this
type.
This method should also do type validation of ``value``.
``struct`` is a :class:`colander.Structure` instance which
contains, among other things, the default value, the name of
the value, and a ``required`` flag indicating whether this
value is required.
If the object cannot be deserialized, or type validation for
``value`` fails, a :exc:`colander.Invalid` exception should be
raised.
"""