def validate(validator):
def decorator(func):<EOL><INDENT>"""<STR_LIT>"""<EOL>@wraps(func)<EOL>def wrapper(image, size, validate=True):<EOL><INDENT>if validate:<EOL><INDENT>validator(image, size)<EOL><DEDENT>return func(image, size)<EOL><DEDENT>return wrapper<EOL><DEDENT>return decorator<EOL>
Return a decorator that validates arguments with provided `validator`
function.

This will also store the validator function as `func.validate`.
The decorator returned by this function, can bypass the validator
if `validate=False` is passed as argument otherwise the fucntion is
called directly.

The validator must raise an exception, if the function can not
be called.