Home | Trees | Indices | Help |
---|
|
object --+ | basevalidator.BaseValidator --+ | CheckLength
Only allow values of a certain sizes.
Length limitations are expressed as (inclusive) minimum and maximum sizes. This is most useful for strings, but could be used for lists.
For example:
>>> v = CheckLength(min=2, max=4) >>> v("abc") 'abc' >>> v("abcde") #doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: 'abcde' is longer than 4 >>> v("a") Traceback (most recent call last): ... ValueError: 'a' is shorter than 2 >>> v = CheckLength(max=4) >>> v("abc") 'abc' >>> v("abcde") Traceback (most recent call last): ... ValueError: 'abcde' is longer than 4 >>> v("a") 'a' >>> v = CheckLength(min=2) >>> v("abc") 'abc' >>> v("abcde") 'abcde' >>> v("a") Traceback (most recent call last): ... ValueError: 'a' is shorter than 2
|
|||
|
|||
|
|||
|
|||
Inherited from Inherited from |
|
|||
Inherited from |
|
|
|
Check a value is of the desired form. This is the workhorse method that is called by validate to check passed values. As such, errors are signalled by either by throwing a meaningful exception or by returning false. This is one of the obvious and easiest places to customize behaviour by overriding in a subclass.
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jul 22 15:13:46 2011 | http://epydoc.sourceforge.net |