Esempio n. 1
0
 def register(self, validator):
     if not IValidator.isImplementedBy(validator):
         IValidator.isImplementedBy(validator)
         raise FalseValidatorError, validator
     name = validator.name
     # The following code prevents refreshing
     ##if self._validator.has_key(name):
     ##    raise AlreadyRegisteredValidatorError, name
     self._validator[name] = validator
Esempio n. 2
0
 def unregister(self, name_or_validator):
     if type(name_or_validator) is StringType:
         name = name_or_validator
     elif IValidator.isImplementedBy(name_or_validator):
         name = name_or_validator.name
     if self._validator.has_key(name):
         del self._validator[name]
Esempio n. 3
0
 def validatorFor(self, name_or_validator):
     if type(name_or_validator) in StringTypes:
         try:
             return self._validator[name_or_validator]
         except KeyError:
             raise UnknowValidatorError, name_or_validator
     elif IValidator.isImplementedBy(name_or_validator):
         return name_or_validator
     else:
         raise FalseValidatorError, name_or_validator
Esempio n. 4
0
File: record.py Progetto: a25kk/stv2
        def _subfieldValidationLayer(self, subfield):
            """
            for the individual subfields
            """
            chainname = 'Validator_%s_%s' % (self.getName(), subfield)
            current_validators = self.subfield_validators.get(subfield, ())

            if type(current_validators) is DictType:
                raise NotImplementedError, 'Please use the new syntax with validation chains'
            elif IValidationChain.isImplementedBy(current_validators):
                validators = current_validators
            elif IValidator.isImplementedBy(current_validators):
                validators = ValidationChain(chainname, validators=current_validators)
            elif type(current_validators) in (TupleType, ListType, StringType):
                if len(current_validators):
                    # got a non empty list or string - create a chain
                    try:
                        validators = ValidationChain(chainname, validators=current_validators)
                    except (UnknowValidatorError, FalseValidatorError), msg:
                        log("WARNING: Disabling validation for %s/%s: %s" % (self.getName(), subfield, msg))
                        validators = ()
                else:
                    validators = ()