1
michele@ionic:~/Progetti/TurboGears/svn/thirdparty/formencode/formencode$ python
2
Python 2.4.3 (#2, Mar 30 2006, 14:45:01)
3
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu3)] on linux2
4
Type "help", "copyright", "credits" or "license" for more information.
5
>>> from formencode import validators
6
>>> int = validators.Int()
10
>>> int.to_python(None)
13
>>> int.to_python(False)
15
>>> int.to_python('1')
17
>>> int.to_python('1a')
18
Traceback (most recent call last):
20
Invalid: Please enter an integer value
21
>>> int.not_empty = True
23
Traceback (most recent call last):
25
Invalid: Please enter a value
26
>>> int.to_python(None)
27
Traceback (most recent call last):
29
Invalid: Please enter a value
30
>>> int.to_python('1')
32
>>> int.to_python('1a')
33
Traceback (most recent call last):
35
Invalid: Please enter an integer value
36
>>> from formencode import compound
37
>>> any = compound.Any(validators.Int(), validators.NotEmpty())
41
>>> any.to_python(None)
42
>>> any = compound.Any(validators.Int(), validators.Empty())
45
>>> any = compound.All(validators.Int(), validators.NotEmpty())
49
Traceback (most recent call last):
51
Invalid: Please enter a value
52
>>> from formencode.foreach import ForEach
53
>>> from formencode.validators import Int
54
>>> foreach = ForEach(Int())
55
>>> foreach.to_python('')
57
>>> foreach.to_python(None)
59
>>> foreach.to_python('1')
61
>>> foreach.to_python('2')
63
>>> foreach.to_python(['2', '3'])
65
>>> foreach.not_empty = True
66
>>> foreach.to_python('1')
68
>>> foreach.to_python('')
69
Traceback (most recent call last):
71
Invalid: Please enter a value
72
>>> foreach.if_empty = []
73
>>> foreach.to_python('')
74
Traceback (most recent call last):
76
Invalid: Please enter a value
77
>>> foreach.not_empty = False
78
>>> foreach.to_python('')
80
>>> foreach.not_empty = False