0001"""
0002Interfaces for FormEncode (for documentation purposes only)
0003"""
0004
0005class Attribute(object):
0006
0007 def __init__(self, description, name=None):
0008 self.description = description
0009 self.name = name
0010
0011class Interface(object):
0012 pass
0013
0014class IDeclarative(Interface):
0015
0016 def __init__(**kw):
0017 """
0018 Instantiates this class with all the keywords being used to
0019 update the instance variables.
0020 """
0021
0022 def __call__(**kw):
0023 """
0024 Returns a copy with all attributes using the given keywords,
0025 being updated.
0026 """
0027
0028
0029class IValidator(IDeclarative):
0030
0031 messages = Attribute("""
0032 A dictionary of messages (with formatting strings) for error
0033 responses""", name='messages')
0034 if_missing = Attribute("""
0035 If the source that this validator would handle is missing (e.g.,
0036 a field that was not specified), use this value. If
0037 Validator.NoDefault, then if the field is missing an exception
0038 should be raised.""", name='ifMissing')
0039 repeating = Attribute("""
0040 A boolean; this object accepts lists if true, subvalidators can be
0041 found in the validators attribute.""", name='repeating')
0042 compound = Attribute("""
0043 A boolean; this object has a dictionary of validators if this is
0044 true, subvalidators can be found in the field attribute (a
0045 dictionary).""", name='compound')
0046
0047 def to_python(value, state=None):
0048 """
0049 Convert `value` from its foreign representation to its Python
0050 representation. `state` is for application-specific hooks.
0051 """
0052
0053 def from_python(value, state=None):
0054 """
0055 Convert `value` from its Python representation to the foreign
0056 representation. `state` is for application-specific hooks.
0057 """
0058
0059 def message(name, default):
0060 """
0061 Return the message (from the `messages` attribute) that goes
0062 with `name`, or return default if `name` not found `default`.
0063 """
0064
0065class ISchema(IValidator):
0066
0067 fields = Attribute('A dictionary of (field name: validator)', name='fields')