In [1]:
import formencode

In [3]:
class PersonSchema(formencode.Schema):
    name = formencode.validators.ByteString()
    dob = formencode.validators.DateConverter(month_style='euro')

In [4]:
person = {'name': 'John Smith', 'dob': '01/01/2000'}

In [5]:
person_validator = PersonSchema()

In [6]:
person_validator.to_python(person)


Out[6]:
{'dob': datetime.date(2000, 1, 1), 'name': 'John Smith'}

In [7]:
no_name_person = {'dob': '01/01/2000'}

In [8]:
person_validator.to_python(no_name_person)


---------------------------------------------------------------------------
Invalid                                   Traceback (most recent call last)
<ipython-input-8-7dcf6d0e1684> in <module>()
----> 1 person_validator.to_python(no_name_person)

/home/mjuenemann/.virtualenvs/formencode/lib/python2.7/site-packages/formencode/api.pyc in to_python(self, value, state)
    473             tp = self._convert_to_python
    474             if tp:
--> 475                 value = tp(value, state)
    476             vp = self._validate_python
    477             if vp and vp is not self._validate_noop:

/home/mjuenemann/.virtualenvs/formencode/lib/python2.7/site-packages/formencode/schema.pyc in _convert_to_python(self, value_dict, state)
    215                 raise Invalid(
    216                     format_compound_error(errors),
--> 217                     value_dict, state, error_dict=errors)
    218 
    219             for validator in self.chained_validators:

Invalid: name: Missing value

In [12]:
invalid_dob_person = {'name': 'John Smith', 'dob': '31/02/2000'}

In [13]:
person_validator.to_python(invalid_dob_person)


---------------------------------------------------------------------------
Invalid                                   Traceback (most recent call last)
<ipython-input-13-df2dee3dd685> in <module>()
----> 1 person_validator.to_python(invalid_dob_person)

/home/mjuenemann/.virtualenvs/formencode/lib/python2.7/site-packages/formencode/api.pyc in to_python(self, value, state)
    473             tp = self._convert_to_python
    474             if tp:
--> 475                 value = tp(value, state)
    476             vp = self._validate_python
    477             if vp and vp is not self._validate_noop:

/home/mjuenemann/.virtualenvs/formencode/lib/python2.7/site-packages/formencode/schema.pyc in _convert_to_python(self, value_dict, state)
    215                 raise Invalid(
    216                     format_compound_error(errors),
--> 217                     value_dict, state, error_dict=errors)
    218 
    219             for validator in self.chained_validators:

Invalid: dob: That month only has 29 days

In [ ]: