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

« back to all changes in this revision

Viewing changes to ivle/cgirequest.py

  • Committer: William Grant
  • Date: 2009-04-28 08:25:30 UTC
  • Revision ID: grantw@unimelb.edu.au-20090428082530-u6w762gn0cyokpwf
Remove ivle.conf dependency from ivle.webapp.filesystem.serve.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
import sys
29
29
import os
 
30
import os.path
30
31
import cgi
31
32
import urllib
32
33
import traceback
137
138
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
138
139
        # Split the given path into the app (top-level dir) and sub-path
139
140
        # (after first stripping away the root directory)
140
 
        path = ivle.util.unmake_path(self.uri)
 
141
        path = self.unmake_path(self.uri)
141
142
        if self.publicmode:
142
143
            self.app = None
143
144
            (_, self.path) = (ivle.util.split_path(path))
272
273
        self.flush()
273
274
        sys.exit(self.status)
274
275
 
 
276
    def unmake_path(self, path):
 
277
        """Strip the IVLE URL prefix from the given path, if present.
 
278
 
 
279
        Also normalises the path.
 
280
        """
 
281
        path = os.path.normpath(path)
 
282
        root = os.path.normpath(ivle.conf.root_dir)
 
283
 
 
284
        if path.startswith(root):
 
285
            path = path[len(root):]
 
286
            # Take out the slash as well
 
287
            if len(path) > 0 and path[0] == os.sep:
 
288
                path = path[1:]
 
289
 
 
290
        return path
 
291
 
275
292
    def get_session(self):
276
293
        """Returns a mod_python Session object for this request.
277
294
        Note that this is dependent on mod_python and may need to change