예제 #1
0
def MoreThan(bound, boundInclude=True):
    '''
    Validate value is more than bound, or more than or equal to bound if the boundInclude is true
    
    @param bound: a upper bound of value
    @param boundInclude: true if the bound is include
    @return: Instance of TypeValidator
    '''
    return valueSpecValidator(
        "%s%s, ...)" % toStrTuple("[" if boundInclude else "(", bound),
        lambda value: bound <= value if boundInclude else bound < value)
예제 #2
0
def LessThan(bound, boundInclude=True):
    '''
    Validate value is less than bound, or less than or equal to bound if the boundInclude is true
    
    @param bound: a lower bound of value
    @param boundInclude: true if the bound is include
    @return: Instance of TypeValidator
    '''
    return valueSpecValidator(
        "(..., %s%s" % toStrTuple(bound, "]" if boundInclude else ")"),
        lambda value: value <= bound if boundInclude else value < bound)
예제 #3
0
def Inner(lbound, ubound, lboundInclude=True, uboundInclude=True):
    '''
    Validate value is in the range
    
    @param lbound: a lower bound
    @param ubound: a upper bound
    @param lboundInclude: true if the lbound is included in the range
    @param uboundInclude: true if the ubound is included in the range
    @return: Instance of TypeValidator
    '''
    return valueSpecValidator(
        "%s%s, %s%s" % toStrTuple("[" if lboundInclude else "(", lbound,
                                  ubound, "]" if uboundInclude else ")"),
        lambda value: (lbound <= value
                       if lboundInclude else lbound < value) and
        (value <= ubound if uboundInclude else value < ubound))
예제 #4
0
def validateTypeIdentifier(type_or_tuple_or_list):
    '''
    Validate the type_or_tuple_or_list is valid type identifier
    
    @param type_or_tuple_or_list: a type, a tuple-of-type or a list-of-type
    @raise ValueError: type_or_tuple_or_list is invalid form 
    '''
    if isinstance(type_or_tuple_or_list, (tuple, list)):
        for t in type_or_tuple_or_list:
            try:
                validateTypeIdentifier(t)
            except ValueError as e:
                raise ValueError("%s in %s is invalid(%s)" %
                                 toStrTuple(t, type_or_tuple_or_list, e))
    elif not isinstance(type_or_tuple_or_list, type):
        raise ValueError("%s is invalid type" % type_or_tuple_or_list)
예제 #5
0
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except BaseException as e:
         if excepts.isValid(e):
             raise
         else:
             raise ValidationException("%s is not a checked error" %
                                       str(type(e)))
     except:
         excInfo = sys.exc_info()
         if excepts.isValid(excInfo[0]):
             raise
         else:
             raise ValidationException(
                 "%s is not a checked error(exc_info=%s)" %
                 toStrTuple(excInfo[0], excInfo))
예제 #6
0
 def __str__(self):
     return "ArgumentManipulator(params=%s, fullArgs=%s, args=%s, varargs=%s, kwargs=%s)" % toStrTuple(
         self.iaa._paramNames, self.fullArgs, self.args, self.varargs,
         self.kwArgs)
예제 #7
0
 def __str__(self):
     return "ArgumentManipulator(params=%s, fullArgs=%s, args=%s, varargs=%s, kwargs=%s)" % toStrTuple(self.iaa._paramNames, self.fullArgs, self.args, self.varargs, self.kwArgs)
예제 #8
0
 def validate(self, value):
     if not self.isValid(value):
         raise ValidationException("%s is not a valid %s" %
                                   toStrTuple(value, self))
     return generatorWrapper(value, self._eachElementType)
예제 #9
0
 def validate(self, value):
     if not self.isValid(value):
         raise ValidationException("%s is not a valid %s" %
                                   toStrTuple(value, self))
     return value
예제 #10
0
 def __str__(self):
     return "listOf(%s, min=%s, max=%s)" % toStrTuple(
         self._elementType, self._minLength, self._maxLength)
예제 #11
0
 def validate(self, value):
     if not self.isValid(value):
         raise ValidationException(
             "%s is not valid value. Must be one of %s" %
             toStrTuple(value, self._typeValidatorList))
     return value
예제 #12
0
 def validate(self, value):
     if not self.isValid(value):
         raise ValidationException("%s is not a instance of %s" %
                                   toStrTuple(value, self._pythonType))
     return value