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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

ivle.dispatch: Move some imports around so that it can be imported from
    outside Apache. mod_python is a bad citizen and won't be fully imported
    from the outside.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
import time
38
38
 
39
39
import mod_python
40
 
from mod_python import apache, Cookie
41
40
import routes
42
41
 
43
42
from ivle import util
44
43
import ivle.conf
45
44
import ivle.conf.apps
46
45
import apps
47
 
import login
48
46
import html
49
 
from request import Request
50
47
import plugins.console # XXX: Relies on www/ being in the Python path.
51
48
 
52
49
# XXX List of plugins, which will eventually be read in from conf
80
77
 
81
78
    req: An Apache request object.
82
79
    """
 
80
    from ivle.dispatch.request import Request
83
81
    # Make the request object into an IVLE request which can be passed to apps
84
82
    apachereq = req
85
83
    try:
89
87
        # yet.
90
88
        handle_unknown_exception(apachereq, *sys.exc_info())
91
89
        # Tell Apache not to generate its own errors as well
92
 
        return apache.OK
 
90
        return mod_python.apache.OK
93
91
 
94
92
    # Run the main handler, and catch all exceptions
95
93
    try:
101
99
    except Exception:
102
100
        handle_unknown_exception(req, *sys.exc_info())
103
101
        # Tell Apache not to generate its own errors as well
104
 
        return apache.OK
 
102
        return mod_python.apache.OK
105
103
 
106
104
def handler_(req, apachereq):
107
105
    """
109
107
    just used to catch exceptions.
110
108
    Takes both an IVLE request and an Apache req.
111
109
    """
 
110
    from ivle.dispatch import login
 
111
    from ivle.dispatch.request import Request
 
112
 
112
113
    # Hack? Try and get the user login early just in case we throw an error
113
114
    # (most likely 404) to stop us seeing not logged in even when we are.
114
115
    if not req.publicmode:
228
229
    # For some reason, some versions of mod_python have "_server" instead of
229
230
    # "main_server". So we check for both.
230
231
    try:
231
 
        admin_email = apache.main_server.server_admin
 
232
        admin_email = mod_python.apache.main_server.server_admin
232
233
    except AttributeError:
233
234
        try:
234
 
            admin_email = apache._server.server_admin
 
235
            admin_email = mod_python.apache._server.server_admin
235
236
        except AttributeError:
236
237
            admin_email = ""
237
238
    try:
239
240
        req.status = httpcode
240
241
    except AttributeError:
241
242
        httpcode = None
242
 
        req.status = apache.HTTP_INTERNAL_SERVER_ERROR
 
243
        req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
243
244
    try:
244
245
        publicmode = req.publicmode
245
246
    except AttributeError:
359
360
<h1>IVLE Internal Server Error""")
360
361
        if (show_errors):
361
362
            if (codename is not None
362
 
                        and httpcode != apache.HTTP_INTERNAL_SERVER_ERROR):
 
363
                        and httpcode != mod_python.apache.HTTP_INTERNAL_SERVER_ERROR):
363
364
                req.write(": %s" % cgi.escape(codename))
364
365
        
365
366
        req.write("""</h1>