Esempio n. 1
0
File: chain.py Progetto: dtgit/dtedu
def test():
    """Little test script
    """
    isEmptyURL = ValidationChain('isEmptyURL',
                                validators = (('isEmpty', V_SUFFICIENT), ('isURL', V_REQUIRED)),
                                register=True
                               )
    #
    v = validationService.validatorFor('isEmptyURL')
    assert(v is isEmptyURL)
    assert(v('http://www.example.org') is True)
    assert(v('') is True)
    assert(type(v('www.example.org')) is StringType) # error

    isIntOrEmpty = ValidationChain('isIntOrEmpty')
    isIntOrEmpty.appendSufficient('isEmpty')
    from validators.RegexValidator import RegexValidator
    isPosInt = RegexValidator('isInt', r'^([+])?\d+$', title='', description='')
    isIntOrEmpty.appendRequired(isPosInt)
    validationService.register(isIntOrEmpty)

    v = validationService.validatorFor('isIntOrEmpty')
    assert(v is isIntOrEmpty)
    assert(v('') is True)
    assert(v('1') is True)
    assert(type(v('-1')) is StringType) # error
    assert(type(v('a')) is StringType) # error
Esempio n. 2
0
    def __init__(self, name, title='', description='', validators=(),
                 register=False):
        self.name = name
        self.title = title or name
        self.description = description
        self._v_mode = []
        self._chain = []

        if type(validators) not in (TupleType, ListType):
            validators = (validators, )
        for validator in validators:
            if type(validator) in (TupleType, ListType):
                self.append(validator[0], validator[1])
            else:
                self.appendRequired(validator)

        if register:
            validationService.register(self)
Esempio n. 3
0
    def __init__(self,
                 name,
                 title='',
                 description='',
                 validators=(),
                 register=False):
        self.name = name
        self.title = title or name
        self.description = description
        self._v_mode = []
        self._chain = []

        if type(validators) not in (TupleType, ListType):
            validators = (validators, )
        for validator in validators:
            if type(validator) in (TupleType, ListType):
                self.append(validator[0], validator[1])
            else:
                self.appendRequired(validator)

        if register:
            validationService.register(self)