def decorator(func): if not meta.is_instruction(func): raise exceptions.ArgumentInstructionConstraintError( func.__name__, required_numeric_bounds.__name__) @functools.wraps(func) def wrapper(arg): if not (lower <= arg <= upper): raise exceptions.ArgumentNumericBoundsError( func.instruction_name, name, arg, lower, upper) return func(arg) return wrapper
def decorator(func): if not meta.is_instruction(func): raise exceptions.ArgumentInstructionConstraintError( func.__name__, required_regex_match.__name__) @functools.wraps(func) def wrapper(arg): match = re.match(pattern, arg) if not match: raise exceptions.ArgumentPatternError(func.instruction_name, name, pattern) return func(match.groupdict()) return wrapper
def decorator(func): if not meta.is_instruction(func): raise exceptions.ArgumentInstructionConstraintError( func.__name__, required_collection_length.__name__) @functools.wraps(func) def wrapper(arg): received_length = len(arg) if received_length != length: raise exceptions.ArgumentCollectionLengthError( func.instruction_name, name, length, received_length) return func(arg) return wrapper
def decorator(func): if not meta.is_instruction(func): raise exceptions.ArgumentInstructionConstraintError( func.__name__, required.__name__) @functools.wraps(func) def wrapper(arg): if not arg: raise exceptions.ArgumentMissingError(func.instruction_name, name, func.instruction_desc) if not isinstance(arg, required_type): raise exceptions.ArgumentTypeError(func.instruction_name, name, required_type, type(arg)) return func(arg) return wrapper
def decorator(func): if not meta.is_instruction(func): raise exceptions.ArgumentInstructionConstraintError( func.__name__, required_dict_key.__name__) @functools.wraps(func) def wrapper(arg): value = arg.get(name) if value is None: raise exceptions.ArgumentMissingError(func.instruction_name, name, func.instruction_desc) if not isinstance(value, required_type): raise exceptions.ArgumentTypeError(func.instruction_name, name, required_type, type(value)) return func(arg) return wrapper
def decorator(func): if not meta.is_instruction(func): raise exceptions.ArgumentInstructionConstraintError( func.__name__, optional_dict_key.__name__) @functools.wraps(func) def wrapper(arg): value = arg.get(name) if value is not None: if not isinstance(value, required_type): raise exceptions.ArgumentTypeError(func.instruction_name, name, required_type, type(value)) if mutually_exclusive_with is not None and mutually_exclusive_with in arg: raise exceptions.ArgumentDisjointedError( func.instruction_name, name, mutually_exclusive_with) return func(arg) return wrapper