Validates and manipulates keyword arguments by user defined callables. Handles ValueError and missing arguments by raising HTTPError(403).
(**vkargs)
| 1980 | |
| 1981 | |
| 1982 | def validate(**vkargs): |
| 1983 | """ |
| 1984 | Validates and manipulates keyword arguments by user defined callables. |
| 1985 | Handles ValueError and missing arguments by raising HTTPError(403). |
| 1986 | """ |
| 1987 | depr('Use route wildcard filters instead.') |
| 1988 | def decorator(func): |
| 1989 | @functools.wraps(func) |
| 1990 | def wrapper(*args, **kargs): |
| 1991 | for key, value in vkargs.iteritems(): |
| 1992 | if key not in kargs: |
| 1993 | abort(403, 'Missing parameter: %s' % key) |
| 1994 | try: |
| 1995 | kargs[key] = value(kargs[key]) |
| 1996 | except ValueError: |
| 1997 | abort(403, 'Wrong parameter format for: %s' % key) |
| 1998 | return func(*args, **kargs) |
| 1999 | return wrapper |
| 2000 | return decorator |
| 2001 | |
| 2002 | |
| 2003 | def auth_basic(check, realm="private", text="Access denied"): |