| Home | Trees | Indices | Help |
|---|
|
|
object --+
|
BaseValidator --+
|
WrappingValidator
Wraps functions and possible error messages in a validator.
This allows converting and validating functions to be easily encapsulated in a validator. Given the design of konval (any function that accepts & returns a value can be used as a validator), this is only slightly useful. However it does allow useful error messages to be incorporated.
For example:
>>> from string import *
>>> v = WrappingValidator (conv_fn=upper, conv_msg='not a string')
>>> v('abc')
'ABC'
>>> v(1)
Traceback (most recent call last):
...
ValueError: not a string
>>> v = WrappingValidator (val_fn=lambda x: len(x) < 4)
>>> v('abc')
'abc'
>>> v(1)
Traceback (most recent call last):
...
ValueError: can't validate '1'
Idea flinched from FormEncode.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from Inherited from |
|||
|
|||
|
Inherited from |
|||
|
|||
C'tor accepting functors for validation & conversion.
|
Transform a value to the desired form. This is the workhorse method that is called by convert to transform passed values. As such, errors are signalled by throwing a meaningful exception. This is one of the obvious and easiest places to customize behaviour by overriding in a subclass.
|
Generate an error message for a conversion problem. Parameters as per raise_conversion_error. Override in subclass if need be, for more specific and meaningful messages.
|
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.
|
Generate an error message for a validation problem. Parameters as per raise_validation_error. Override in subclass if need be, for more specific and meaningful messages.
|
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Jul 22 15:13:46 2011 | http://epydoc.sourceforge.net |