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

« back to all changes in this revision

Viewing changes to ivle/cgirequest.py

  • Committer: Matt Giuca
  • Date: 2009-05-26 04:15:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090526041523-hsg5q2enlhvjb5y2
doc/man/architecture.rst: User management server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# This allows CGI scripts to create request objects and then pass them to
26
26
# normal IVLE handlers.
27
27
 
28
 
# NOTE: This object does not support write_html_head_foot (simply because we
29
 
# do not need it in its intended application: fileservice).
30
 
 
31
28
import sys
32
29
import os
 
30
import os.path
33
31
import cgi
34
32
import urllib
35
33
import traceback
140
138
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
141
139
        # Split the given path into the app (top-level dir) and sub-path
142
140
        # (after first stripping away the root directory)
143
 
        path = ivle.util.unmake_path(self.uri)
 
141
        path = self.unmake_path(self.uri)
144
142
        if self.publicmode:
145
143
            self.app = None
146
144
            (_, self.path) = (ivle.util.split_path(path))
155
153
        self.status = CGIRequest.HTTP_OK
156
154
        self.content_type = None        # Use Apache's default
157
155
        self.location = None
158
 
        self.title = None     # Will be set by dispatch before passing to app
159
156
        self.styles = []
160
157
        self.scripts = []
161
 
        self.write_html_head_foot = False
162
158
        self.got_common_vars = False
163
159
 
164
160
 
197
193
            if k != 'Content-Type' and k != 'Location':
198
194
                print "%s: %s" % (k, v)
199
195
 
200
 
        # XXX write_html_head_foot not supported
201
 
        #if self.write_html_head_foot:
202
 
        #    # Write the HTML header, pass "self" (request object)
203
 
        #    self.func_write_html_head(self)
204
196
        # Print a blank line to signal the start of output
205
197
        print
206
198
 
249
241
        else:
250
242
            return sys.stdin.read(len)
251
243
 
252
 
    def throw_error(self, httpcode, message):
253
 
        """Writes out an HTTP error of the specified code. Exits the process,
254
 
        so any code following this call will not be executed.
255
 
 
256
 
        (This is justified because of the nature of CGI, it is a single-script
257
 
        environment, there is no containing process which needs to catch an
258
 
        exception).
259
 
 
260
 
        httpcode: An HTTP response status code. Pass a constant from the
261
 
        Request class.
262
 
        """
263
 
        raise ivle.util.IVLEError(httpcode, message)
264
 
 
265
244
    def handle_unknown_exception(self, exc_type, exc_value, exc_tb):
266
245
        if exc_type is ivle.util.IVLEError:
267
246
            self.headers_out['X-IVLE-Error-Code'] = exc_value.httpcode
294
273
        self.flush()
295
274
        sys.exit(self.status)
296
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
 
297
292
    def get_session(self):
298
293
        """Returns a mod_python Session object for this request.
299
294
        Note that this is dependent on mod_python and may need to change