~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

Remove the odd handler() -> handler_() chaining in ivle.dispatch.

The unwrapped code is now so unlikely to crash that it doesn't make sense to
have the extra layer of confusion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
Apache send all requests to be handled by the module 'dispatch'.
23
23
 
24
24
Top-level handler. Handles all requests to all pages in IVLE.
25
 
Handles authentication (not authorization).
26
 
Then passes the request along to the appropriate ivle app.
 
25
Handles authentication and delegates to views for authorization,
 
26
then passes the request along to the appropriate view.
27
27
"""
28
28
 
29
29
import sys
62
62
            m.connect(routex, view=view_class, **kwargs_dict)
63
63
    return m
64
64
 
65
 
def handler(req):
66
 
    """Handles a request which may be to anywhere in the site except media.
 
65
def handler(apachereq):
 
66
    """Handles an HTTP request.
 
67
 
67
68
    Intended to be called by mod_python, as a handler.
68
69
 
69
 
    req: An Apache request object.
70
 
    """
71
 
    # Make the request object into an IVLE request which can be passed to apps
72
 
    apachereq = req
73
 
    try:
74
 
        req = Request(req)
75
 
    except Exception:
76
 
        # Pass the apachereq to error reporter, since ivle req isn't created
77
 
        # yet.
78
 
        handle_unknown_exception(apachereq, *sys.exc_info())
79
 
        # Tell Apache not to generate its own errors as well
80
 
        return mod_python.apache.OK
81
 
 
82
 
    # Run the main handler, and catch all exceptions
83
 
    try:
84
 
        return handler_(req, apachereq)
85
 
    except mod_python.apache.SERVER_RETURN:
86
 
        # An apache error. We discourage these, but they might still happen.
87
 
        # Just raise up.
88
 
        raise
89
 
    except Exception:
90
 
        handle_unknown_exception(req, *sys.exc_info())
91
 
        # Tell Apache not to generate its own errors as well
92
 
        return mod_python.apache.OK
93
 
 
94
 
def handler_(req, apachereq):
95
 
    """
96
 
    Nested handler function. May raise exceptions. The top-level handler is
97
 
    just used to catch exceptions.
98
 
    Takes both an IVLE request and an Apache req.
99
 
    """
 
70
    @param apachereq: An Apache request object.
 
71
    """
 
72
    # Make the request object into an IVLE request which can be given to views
 
73
    req = Request(apachereq)
 
74
 
100
75
    # Hack? Try and get the user login early just in case we throw an error
101
76
    # (most likely 404) to stop us seeing not logged in even when we are.
102
77
    if not req.publicmode: