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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

  • Committer: William Grant
  • Date: 2009-12-08 03:43:27 UTC
  • Revision ID: grantw@unimelb.edu.au-20091208034327-iv33bf1kn9lim6mh
make_svn_auth now only generates a new password if none is already known by the DB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
import routes
41
41
 
42
42
from ivle import util
43
 
import ivle.conf
 
43
import ivle.config
44
44
from ivle.dispatch.request import Request
45
45
import ivle.webapp.security
46
46
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
47
47
from ivle.webapp.base.xhtml import XHTMLView, XHTMLErrorView
48
48
from ivle.webapp.errors import HTTPError, Unauthorized, NotFound
49
49
 
50
 
def generate_route_mapper(view_plugins, attr):
 
50
config = ivle.config.Config()
 
51
 
 
52
def generate_router(view_plugins, attr):
51
53
    """
52
54
    Build a Mapper object for doing URL matching using 'routes', based on the
53
55
    given plugin registry.
71
73
    @param apachereq: An Apache request object.
72
74
    """
73
75
    # Make the request object into an IVLE request which can be given to views
74
 
    req = Request(apachereq)
 
76
    req = Request(apachereq, config)
75
77
 
76
78
    # Hack? Try and get the user login early just in case we throw an error
77
79
    # (most likely 404) to stop us seeing not logged in even when we are.
82
84
        if user and user.valid:
83
85
            req.user = user
84
86
 
85
 
    conf = ivle.config.Config()
86
 
    req.config = conf
87
 
 
88
87
    if req.publicmode:
89
 
        req.mapper = generate_route_mapper(conf.plugin_index[PublicViewPlugin],
90
 
                                           'public_urls')
 
88
        req.mapper = generate_router(config.plugin_index[PublicViewPlugin],
 
89
                                    'public_urls')
91
90
    else:
92
 
        req.mapper = generate_route_mapper(conf.plugin_index[ViewPlugin],
93
 
                                           'urls')
 
91
        req.mapper = generate_router(config.plugin_index[ViewPlugin], 'urls')
94
92
 
95
93
    matchdict = req.mapper.match(req.uri)
96
94
    if matchdict is not None:
128
126
                return req.OK
129
127
            else:
130
128
                return e.code
 
129
        except mod_python.apache.SERVER_RETURN:
 
130
            # A mod_python-specific Apache error.
 
131
            # XXX: We need to raise these because req.throw_error() uses them.
 
132
            # Remove this after Google Code issue 117 is fixed.
 
133
            raise
131
134
        except Exception, e:
132
135
            # A non-HTTPError appeared. We have an unknown exception. Panic.
133
136
            handle_unknown_exception(req, *sys.exc_info())
136
139
            req.store.commit()
137
140
            return req.OK
138
141
    else:
 
142
        req.status = 404
139
143
        XHTMLErrorView(req, NotFound()).render(req)
140
144
        return req.OK
141
145
 
150
154
    the IVLE request is created.
151
155
    """
152
156
    req.content_type = "text/html"
153
 
    logfile = os.path.join(ivle.conf.log_path, 'ivle_error.log')
 
157
    logfile = os.path.join(config['paths']['logs'], 'ivle_error.log')
154
158
    logfail = False
 
159
 
 
160
    # XXX: This remains here for ivle.interpret's IVLEErrors. Once we rewrite
 
161
    #      fileservice, req.status should always be 500 (ISE) here.
155
162
    try:
156
163
        httpcode = exc_value.httpcode
157
164
        req.status = httpcode
158
165
    except AttributeError:
159
166
        httpcode = None
160
167
        req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
 
168
 
161
169
    try:
162
170
        publicmode = req.publicmode
163
171
    except AttributeError:
186
194
    # misbehaves (which is currently very easy, if things aren't set up
187
195
    # correctly).
188
196
    # Write the traceback.
189
 
    # If this is a non-4xx IVLEError, get the message and httpcode and
190
 
    # make the error message a bit nicer (but still include the
191
 
    # traceback).
192
 
    # We also need to special-case IVLEJailError, as we can get another
 
197
 
 
198
    # We need to special-case IVLEJailError, as we can get another
193
199
    # almost-exception out of it.
194
 
 
195
 
    codename, msg = None, None
196
 
 
197
200
    if exc_type is util.IVLEJailError:
198
 
        msg = exc_value.type_str + ": " + exc_value.message
199
201
        tb = 'Exception information extracted from IVLEJailError:\n'
200
202
        tb += urllib.unquote(exc_value.info)
201
203
    else:
202
 
        try:
203
 
            codename, msg = req.get_http_codename(httpcode)
204
 
        except AttributeError:
205
 
            pass
206
 
 
207
204
        tb = ''.join(traceback.format_exception(exc_type, exc_value,
208
205
                                                exc_traceback))
209
206
 
210
 
    logging.error('%s\n%s'%(str(msg), tb))
 
207
    logging.error('\n' + tb)
211
208
 
212
209
    # Error messages are only displayed is the user is NOT a student,
213
210
    # or if there has been a problem logging the error message
217
214
<html xmlns="http://www.w3.org/1999/xhtml">
218
215
<head><title>IVLE Internal Server Error</title></head>
219
216
<body>
220
 
<h1>IVLE Internal Server Error""")
221
 
    if show_errors:
222
 
        if codename is not None and \
223
 
           httpcode != mod_python.apache.HTTP_INTERNAL_SERVER_ERROR:
224
 
            req.write(": %s" % cgi.escape(codename))
225
 
 
226
 
    req.write("""</h1>
 
217
<h1>IVLE Internal Server Error</h1>
227
218
<p>An error has occured which is the fault of the IVLE developers or
228
219
administrators. """)
229
220
 
235
226
    req.write("</p>")
236
227
 
237
228
    if show_errors:
238
 
        if msg is not None:
239
 
            req.write("<p>%s</p>\n" % cgi.escape(msg))
240
 
        if httpcode is not None:
241
 
            req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
242
229
        req.write("<h2>Debugging information</h2>")
243
 
 
244
230
        req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
245
231
    req.write("</body></html>")