2
Interfaces for FormEncode (for documentation purposes only)
5
class Attribute(object):
7
def __init__(self, description, name=None):
8
self.description = description
11
class Interface(object):
14
class IDeclarative(Interface):
18
Instantiates this class with all the keywords being used to
19
update the instance variables.
24
Returns a copy with all attributes using the given keywords,
29
class IValidator(IDeclarative):
31
messages = Attribute("""
32
A dictionary of messages (with formatting strings) for error
33
responses""", name='messages')
34
if_missing = Attribute("""
35
If the source that this validator would handle is missing (e.g.,
36
a field that was not specified), use this value. If
37
Validator.NoDefault, then if the field is missing an exception
38
should be raised.""", name='ifMissing')
39
repeating = Attribute("""
40
A boolean; this object accepts lists if true, subvalidators can be
41
found in the validators attribute.""", name='repeating')
42
compound = Attribute("""
43
A boolean; this object has a dictionary of validators if this is
44
true, subvalidators can be found in the field attribute (a
45
dictionary).""", name='compound')
47
def to_python(value, state=None):
49
Convert `value` from its foreign representation to its Python
50
representation. `state` is for application-specific hooks.
53
def from_python(value, state=None):
55
Convert `value` from its Python representation to the foreign
56
representation. `state` is for application-specific hooks.
59
def message(name, default):
61
Return the message (from the `messages` attribute) that goes
62
with `name`, or return default if `name` not found `default`.
65
class ISchema(IValidator):
67
fields = Attribute('A dictionary of (field name: validator)', name='fields')