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

« back to all changes in this revision

Viewing changes to ivle/cgirequest.py

  • Committer: William Grant
  • Date: 2010-02-11 05:09:56 UTC
  • Revision ID: grantw@unimelb.edu.au-20100211050956-t5i2z6b8iulxteza
Unbreak existing tests.

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)
144
141
        if self.publicmode:
145
142
            self.app = None
146
 
            (_, self.path) = (ivle.util.split_path(path))
 
143
            (_, self.path) = (ivle.util.split_path(self.uri))
147
144
        else:
148
 
            (self.app, self.path) = (ivle.util.split_path(path))
 
145
            (self.app, self.path) = (ivle.util.split_path(self.uri))
149
146
        self.user = None
150
147
        self.hostname = os.environ['SERVER_NAME']
151
148
        self.headers_in = _http_headers_in_from_cgi()
155
152
        self.status = CGIRequest.HTTP_OK
156
153
        self.content_type = None        # Use Apache's default
157
154
        self.location = None
158
 
        self.title = None     # Will be set by dispatch before passing to app
159
155
        self.styles = []
160
156
        self.scripts = []
161
 
        self.write_html_head_foot = False
162
157
        self.got_common_vars = False
163
158
 
164
159
 
197
192
            if k != 'Content-Type' and k != 'Location':
198
193
                print "%s: %s" % (k, v)
199
194
 
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
195
        # Print a blank line to signal the start of output
205
196
        print
206
197
 
249
240
        else:
250
241
            return sys.stdin.read(len)
251
242
 
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
243
    def handle_unknown_exception(self, exc_type, exc_value, exc_tb):
266
244
        if exc_type is ivle.util.IVLEError:
267
245
            self.headers_out['X-IVLE-Error-Code'] = exc_value.httpcode