Source code for uw.web.wsgi.authority

"""Automatic permissions checking.

Provides a function which delegates to an inner handler, first checking that
access is allowed for the user and reporting an HTTP 403 if not.
"""
from uw.web.wsgi import status, parameter

[docs]def check_authority (check, handler): """Delegate to an inner handler after checking permissions. Parameters: check -- authority checking function; handler -- inner handler to invoke assuming check passes. Returns a WSGI handler which calls check(), passing the environment and the parameters. If the result is True, it chains to handler, otherwise it reports an HTTP 403 Forbidden error. """ def result (environ, start_response): if check (environ, **parameter.get_params (environ)): return handler (environ, start_response) else: raise status.HTTPForbidden () return result