Back to index

plone3  3.1.7
Classes | Functions | Variables
validation.chain Namespace Reference

Classes

class  ValidationChain

Functions

def test

Variables

tuple StringTypes = (UnicodeType, StringType)
int V_REQUIRED = 1
int V_SUFFICIENT = 2

Detailed Description


Function Documentation

Little test script

Definition at line 175 of file chain.py.

00175 
00176 def test():
00177     """Little test script
00178     """
00179     isEmptyURL = ValidationChain('isEmptyURL',
00180                                 validators = (('isEmpty', V_SUFFICIENT), ('isURL', V_REQUIRED)),
00181                                 register=True
00182                                )
00183     #
00184     v = validationService.validatorFor('isEmptyURL')
00185     assert(v is isEmptyURL)
00186     assert(v('http://www.example.org') is True)
00187     assert(v('') is True)
00188     assert(type(v('www.example.org')) is StringType) # error
00189 
00190     isIntOrEmpty = ValidationChain('isIntOrEmpty')
00191     isIntOrEmpty.appendSufficient('isEmpty')
00192     from validators.RegexValidator import RegexValidator
00193     isPosInt = RegexValidator('isInt', r'^([+])?\d+$', title='', description='')
00194     isIntOrEmpty.appendRequired(isPosInt)
00195     validationService.register(isIntOrEmpty)
00196 
00197     v = validationService.validatorFor('isIntOrEmpty')
00198     assert(v is isIntOrEmpty)
00199     assert(v('') is True)
00200     assert(v('1') is True)
00201     assert(type(v('-1')) is StringType) # error
00202     assert(type(v('a')) is StringType) # error
00203 
00204 test()


Variable Documentation

tuple validation.chain.StringTypes = (UnicodeType, StringType)

Definition at line 15 of file chain.py.

Definition at line 17 of file chain.py.

Definition at line 18 of file chain.py.