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

« back to all changes in this revision

Viewing changes to ivle/cgirequest.py

  • Committer: me at id
  • Date: 2009-01-15 00:37:10 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1141
ivle.database.User: Add an authenticate() method, and a hash_password()
     staticmethod to replace the auth functions in ivle.db.

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
 
28
31
import sys
29
32
import os
30
 
import os.path
31
33
import cgi
32
34
import urllib
33
35
import traceback
138
140
        self.uri = os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO']
139
141
        # Split the given path into the app (top-level dir) and sub-path
140
142
        # (after first stripping away the root directory)
141
 
        path = self.unmake_path(self.uri)
 
143
        path = ivle.util.unmake_path(self.uri)
142
144
        if self.publicmode:
143
145
            self.app = None
144
146
            (_, self.path) = (ivle.util.split_path(path))
153
155
        self.status = CGIRequest.HTTP_OK
154
156
        self.content_type = None        # Use Apache's default
155
157
        self.location = None
 
158
        self.title = None     # Will be set by dispatch before passing to app
156
159
        self.styles = []
157
160
        self.scripts = []
 
161
        self.write_html_head_foot = False
158
162
        self.got_common_vars = False
159
163
 
160
164
 
193
197
            if k != 'Content-Type' and k != 'Location':
194
198
                print "%s: %s" % (k, v)
195
199
 
 
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)
196
204
        # Print a blank line to signal the start of output
197
205
        print
198
206
 
241
249
        else:
242
250
            return sys.stdin.read(len)
243
251
 
 
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
 
244
265
    def handle_unknown_exception(self, exc_type, exc_value, exc_tb):
245
266
        if exc_type is ivle.util.IVLEError:
246
267
            self.headers_out['X-IVLE-Error-Code'] = exc_value.httpcode
273
294
        self.flush()
274
295
        sys.exit(self.status)
275
296
 
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
 
 
292
297
    def get_session(self):
293
298
        """Returns a mod_python Session object for this request.
294
299
        Note that this is dependent on mod_python and may need to change