formencode.interfaces
Covered: 3 lines
Missed: 50 lines
Skipped 15 lines
Percent: 5 %
 1
"""
 2
Interfaces for FormEncode (for documentation purposes only)
 3
"""
 5
class Attribute(object):
 7
    def __init__(self, description, name=None):
 8
        self.description = description
 9
        self.name = name
11
class Interface(object):
12
    pass
14
class IDeclarative(Interface):
16
    def __init__(**kw):
17
        """
18
        Instantiates this class with all the keywords being used to
19
        update the instance variables.
20
        """
22
    def __call__(**kw):
23
        """
24
        Returns a copy with all attributes using the given keywords,
25
        being updated.
26
        """
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):
48
        """
49
        Convert `value` from its foreign representation to its Python
50
        representation.  `state` is for application-specific hooks.
51
        """
53
    def from_python(value, state=None):
54
        """
55
        Convert `value` from its Python representation to the foreign
56
        representation.  `state` is for application-specific hooks.
57
        """
59
    def message(name, default):
60
        """
61
        Return the message (from the `messages` attribute) that goes
62
        with `name`, or return default if `name` not found `default`.
63
        """
65
class ISchema(IValidator):
67
    fields = Attribute('A dictionary of (field name: validator)', name='fields')