~ubuntu-branches/ubuntu/trusty/python-formencode/trusty-proposed

« back to all changes in this revision

Viewing changes to formencode/interfaces.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-24 12:54:57 UTC
  • mfrom: (1.1.6) (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140224125457-l6vywmz9ip22q60e
Tags: 1.2.6-1ubuntu1
Remove tests that fail without network connection. See #738722.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Interfaces for FormEncode (for documentation purposes only)
3
 
"""
4
 
 
5
 
 
6
 
class Attribute(object):
7
 
 
8
 
    def __init__(self, description, name=None):
9
 
        self.description = description
10
 
        self.name = name
11
 
 
12
 
 
13
 
class Interface(object):
14
 
    pass
15
 
 
16
 
 
17
 
class IDeclarative(Interface):
18
 
 
19
 
    def __init__(**kw):
20
 
        """
21
 
        Instantiates this class with all the keywords being used to
22
 
        update the instance variables.
23
 
        """
24
 
 
25
 
    def __call__(**kw):
26
 
        """
27
 
        Returns a copy with all attributes using the given keywords,
28
 
        being updated.
29
 
        """
30
 
 
31
 
 
32
 
class IValidator(IDeclarative):
33
 
 
34
 
    messages = Attribute("""
35
 
    A dictionary of messages (with formatting strings) for error
36
 
    responses""", name='messages')
37
 
    if_missing = Attribute("""
38
 
    If the source that this validator would handle is missing (e.g.,
39
 
    a field that was not specified), use this value.  If
40
 
    Validator.NoDefault, then if the field is missing an exception
41
 
    should be raised.""", name='ifMissing')
42
 
    repeating = Attribute("""
43
 
    A boolean; this object accepts lists if true, subvalidators can be
44
 
    found in the validators attribute.""", name='repeating')
45
 
    compound = Attribute("""
46
 
    A boolean; this object has a dictionary of validators if this is
47
 
    true, subvalidators can be found in the field attribute (a
48
 
    dictionary).""", name='compound')
49
 
 
50
 
    def to_python(value, state=None):
51
 
        """
52
 
        Convert `value` from its foreign representation to its Python
53
 
        representation.  `state` is for application-specific hooks.
54
 
        """
55
 
 
56
 
    def from_python(value, state=None):
57
 
        """
58
 
        Convert `value` from its Python representation to the foreign
59
 
        representation.  `state` is for application-specific hooks.
60
 
        """
61
 
 
62
 
    def message(name, default):
63
 
        """
64
 
        Return the message (from the `messages` attribute) that goes
65
 
        with `name`, or return default if `name` not found `default`.
66
 
        """
67
 
 
68
 
 
69
 
class ISchema(IValidator):
70
 
 
71
 
    fields = Attribute('A dictionary of (field name: validator)', name='fields')
 
1
"""
 
2
Interfaces for FormEncode (for documentation purposes only)
 
3
"""
 
4
 
 
5
 
 
6
class Attribute(object):
 
7
 
 
8
    def __init__(self, description, name=None):
 
9
        self.description = description
 
10
        self.name = name
 
11
 
 
12
 
 
13
class Interface(object):
 
14
    pass
 
15
 
 
16
 
 
17
class IDeclarative(Interface):
 
18
 
 
19
    def __init__(**kw):
 
20
        """
 
21
        Instantiates this class with all the keywords being used to
 
22
        update the instance variables.
 
23
        """
 
24
 
 
25
    def __call__(**kw):
 
26
        """
 
27
        Returns a copy with all attributes using the given keywords,
 
28
        being updated.
 
29
        """
 
30
 
 
31
 
 
32
class IValidator(IDeclarative):
 
33
 
 
34
    messages = Attribute("""
 
35
    A dictionary of messages (with formatting strings) for error
 
36
    responses""", name='messages')
 
37
    if_missing = Attribute("""
 
38
    If the source that this validator would handle is missing (e.g.,
 
39
    a field that was not specified), use this value.  If
 
40
    Validator.NoDefault, then if the field is missing an exception
 
41
    should be raised.""", name='ifMissing')
 
42
    repeating = Attribute("""
 
43
    A boolean; this object accepts lists if true, subvalidators can be
 
44
    found in the validators attribute.""", name='repeating')
 
45
    compound = Attribute("""
 
46
    A boolean; this object has a dictionary of validators if this is
 
47
    true, subvalidators can be found in the field attribute (a
 
48
    dictionary).""", name='compound')
 
49
 
 
50
    def to_python(value, state=None):
 
51
        """
 
52
        Convert `value` from its foreign representation to its Python
 
53
        representation.  `state` is for application-specific hooks.
 
54
        """
 
55
 
 
56
    def from_python(value, state=None):
 
57
        """
 
58
        Convert `value` from its Python representation to the foreign
 
59
        representation.  `state` is for application-specific hooks.
 
60
        """
 
61
 
 
62
    def message(name, default):
 
63
        """
 
64
        Return the message (from the `messages` attribute) that goes
 
65
        with `name`, or return default if `name` not found `default`.
 
66
        """
 
67
 
 
68
 
 
69
class ISchema(IValidator):
 
70
 
 
71
    fields = Attribute('A dictionary of (field name: validator)', name='fields')