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

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

  • Committer: William Grant
  • Date: 2009-06-24 10:36:40 UTC
  • Revision ID: grantw@unimelb.edu.au-20090624103640-os28zap2wkyz2udb
Simplify (and deprettify) the crash handler. It's now only used to handle crashes, so needn't be pretty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
        self.uri = req.uri
119
119
        # Split the given path into the app (top-level dir) and sub-path
120
120
        # (after first stripping away the root directory)
121
 
        (self.app, self.path) = (ivle.util.split_path(req.uri))
 
121
        path = self.unmake_path(req.uri)
 
122
        (self.app, self.path) = (ivle.util.split_path(path))
122
123
        self.user = None
123
124
        self.hostname = req.hostname
124
125
        self.headers_in = req.headers_in
237
238
        """
238
239
        return os.path.join(self.config['urls']['root'], path)
239
240
 
 
241
    def unmake_path(self, path):
 
242
        """Strip the IVLE URL prefix from the given path, if present.
 
243
 
 
244
        Also normalises the path.
 
245
 
 
246
        This method is DEPRECATED. We no longer support use of a prefix.
 
247
        """
 
248
        path = os.path.normpath(path)
 
249
        root = os.path.normpath(self.config['urls']['root'])
 
250
 
 
251
        if path.startswith(root):
 
252
            path = path[len(root):]
 
253
            # Take out the slash as well
 
254
            if len(path) > 0 and path[0] == os.sep:
 
255
                path = path[1:]
 
256
 
 
257
        return path
 
258
 
240
259
    def get_session(self):
241
260
        """Returns a mod_python Session object for this request.
242
261
        Note that this is dependent on mod_python and may need to change
269
288
            self.got_common_vars = True
270
289
        return self.apache_req.subprocess_env
271
290
 
 
291
    @staticmethod
 
292
    def get_http_codename(code):
 
293
        """Given a HTTP error code int, returns a (name, description)
 
294
        pair, suitable for displaying to the user.
 
295
        May return (None,None) if code is unknown.
 
296
        Only lists common 4xx and 5xx codes (since this is just used
 
297
        to display throw_error error messages).
 
298
        """
 
299
        try:
 
300
            return http_codenames[code]
 
301
        except KeyError:
 
302
            return None, None
 
303
 
 
304
# Human strings for HTTP response codes
 
305
http_codenames = {
 
306
    Request.HTTP_FORBIDDEN:
 
307
        ("Forbidden",
 
308
        "You are not allowed to view this part of IVLE."),
 
309
    Request.HTTP_NOT_FOUND:
 
310
        ("Not Found",
 
311
        "The application or file you requested does not exist."),
 
312
    Request.HTTP_INTERNAL_SERVER_ERROR:
 
313
        ("Internal Server Error",
 
314
        "An unknown error occured in IVLE."),
 
315
}