~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-01-22 04:47:42 UTC
  • mfrom: (1080.1.93 storm)
  • Revision ID: grantw@unimelb.edu.au-20090122044742-sa8gnww0ma2bm2rv
Merge Storm branch. ivle.db is dead. Watch out for the schema change.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2008 The University of Melbourne
 
2
# Copyright (C) 2007-2009 The University of Melbourne
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
 
# Module: dispatch.request
19
18
# Author: Matt Giuca
20
 
# Date:   12/12/2007
21
 
 
22
 
# Builds an IVLE request object from a mod_python request object.
23
 
# See design notes/apps/dispatch.txt for a full specification of this request
24
 
# object.
 
19
 
 
20
"""
 
21
IVLE Request Object
 
22
 
 
23
Builds an IVLE request object from a mod_python request object.
 
24
See design notes/apps/dispatch.txt for a full specification of this request
 
25
object.
 
26
"""
25
27
 
26
28
import mod_python
27
29
from mod_python import (util, Session, Cookie)
28
30
 
29
31
import ivle.util
30
32
import ivle.conf
 
33
import ivle.database
31
34
import plugins.console # XXX: Relies on www/ being in the Python path.
32
35
 
33
36
class Request:
48
51
        user (read)
49
52
            User object. Details of the user who is currently logged in, or
50
53
            None.
 
54
        store (read)
 
55
            storm.store.Store instance. Holds a database transaction open,
 
56
            which is available for the entire lifetime of the request.
51
57
        hostname (read)
52
58
            String. Hostname the server is running on.
53
59
        headers_in (read)
192
198
        self.headers_in = req.headers_in
193
199
        self.headers_out = req.headers_out
194
200
 
 
201
        # Open a database connection and transaction, keep it around for users
 
202
        # of the Request object to use
 
203
        self.store = ivle.database.get_store()
 
204
 
195
205
        # Default values for the output members
196
206
        self.status = Request.HTTP_OK
197
207
        self.content_type = None        # Use Apache's default
206
216
        self.write_javascript_settings = True
207
217
        self.got_common_vars = False
208
218
 
 
219
    def __del__(self):
 
220
        """Cleanup."""
 
221
        self.store.close()
 
222
 
209
223
    def __writeheaders(self):
210
224
        """Writes out the HTTP and HTML headers before any real data is
211
225
        written."""
306
320
        httpcode: An HTTP response status code. Pass a constant from the
307
321
        Request class.
308
322
        """
309
 
        mod_python.util.redirect(self.apache_req, location)
 
323
        # Note: location may be a unicode, but it MUST only have ASCII
 
324
        # characters (non-ascii characters should be URL-encoded).
 
325
        mod_python.util.redirect(self.apache_req, location.encode("ascii"))
310
326
 
311
327
    def add_cookie(self, cookie, value=None, **attributes):
312
328
        """Inserts a cookie into this request object's headers."""