1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
michele@ionic:~/Progetti/TurboGears/svn/thirdparty/formencode/formencode$ python
Type "help", "copyright", "credits" or "license" for more information.
>>> from formencode import validators
>>> int = validators.Int()
>>> int.not_empty
False
>>> int.to_python('')
>>> int.to_python(None)
>>> int.to_python(0)
0
>>> int.to_python(False)
0
>>> int.to_python('1')
1
>>> int.to_python('1a')
Traceback (most recent call last):
...
Invalid: Please enter an integer value
>>> int.not_empty = True
>>> int.to_python('')
Traceback (most recent call last):
...
Invalid: Please enter a value
>>> int.to_python(None)
Traceback (most recent call last):
...
Invalid: Please enter a value
>>> int.to_python('1')
1
>>> int.to_python('1a')
Traceback (most recent call last):
...
Invalid: Please enter an integer value
>>> from formencode import compound
>>> any = compound.Any(validators.Int(), validators.NotEmpty())
>>> any.not_empty
False
>>> any.to_python('')
>>> any.to_python(None)
>>> any = compound.Any(validators.Int(), validators.Empty())
>>> any.not_empty
False
>>> any = compound.All(validators.Int(), validators.NotEmpty())
>>> any.not_empty
True
>>> any.to_python('')
Traceback (most recent call last):
...
Invalid: Please enter a value
>>> from formencode.foreach import ForEach
>>> from formencode.validators import Int
>>> foreach = ForEach(Int())
>>> foreach.to_python('')
[]
>>> foreach.to_python(None)
[]
>>> foreach.to_python('1')
[1]
>>> foreach.to_python('2')
[2]
>>> foreach.to_python(['2', '3'])
[2, 3]
>>> foreach.not_empty = True
>>> foreach.to_python('1')
[1]
>>> foreach.to_python('')
Traceback (most recent call last):
...
Invalid: Please enter a value
>>> foreach.if_empty = []
>>> foreach.to_python('')
Traceback (most recent call last):
...
Invalid: Please enter a value
>>> foreach.not_empty = False
>>> foreach.to_python('')
[]
>>> foreach.not_empty = False
|