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

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

  • Committer: David Coles
  • Date: 2009-07-21 02:19:56 UTC
  • mto: (1281.1.8 aufsless)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: coles.david@gmail.com-20090721021956-c1jiwu7fhi2dna1g
Updated to work on bind mounts

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
import ivle.util
39
39
import ivle.database
40
40
from ivle.webapp.base.plugins import CookiePlugin
41
 
import ivle.webapp.security
42
41
 
43
42
class Request:
44
43
    """An IVLE request object. This is presented to the IVLE apps as a way of
95
94
    HTTP_NOT_FOUND                    = 404
96
95
    HTTP_INTERNAL_SERVER_ERROR        = 500
97
96
 
98
 
    _store = None
99
 
 
100
97
    def __init__(self, req, config):
101
98
        """Create an IVLE request from a mod_python one.
102
99
 
122
119
        # Split the given path into the app (top-level dir) and sub-path
123
120
        # (after first stripping away the root directory)
124
121
        (self.app, self.path) = (ivle.util.split_path(req.uri))
 
122
        self.user = None
125
123
        self.hostname = req.hostname
126
124
        self.headers_in = req.headers_in
127
125
        self.headers_out = req.headers_out
128
126
 
 
127
        # Open a database connection and transaction, keep it around for users
 
128
        # of the Request object to use
 
129
        self.store = ivle.database.get_store(config)
 
130
 
129
131
        # Default values for the output members
130
132
        self.status = Request.HTTP_OK
131
133
        self.content_type = None        # Use Apache's default
136
138
        self.got_common_vars = False
137
139
 
138
140
    def __del__(self):
139
 
        self.cleanup()
140
 
 
141
 
    def cleanup(self):
142
 
        """Cleanup."""
143
 
        if self._store is not None:
144
 
            self._store.close()
145
 
            self._store = None
146
 
 
147
 
    def commit(self):
148
 
        """Cleanup."""
149
 
        if self._store is not None:
150
 
            self._store.commit()
 
141
        """Cleanup."""
 
142
        self.store.close()
151
143
 
152
144
    def __writeheaders(self):
153
145
        """Writes out the HTTP and HTML headers before any real data is
277
269
            self.got_common_vars = True
278
270
        return self.apache_req.subprocess_env
279
271
 
280
 
    @property
281
 
    def store(self):
282
 
        # Open a database connection and transaction, keep it around for users
283
 
        # of the Request object to use.
284
 
        if self._store is None:
285
 
            self._store = ivle.database.get_store(self.config)
286
 
        return self._store
287
 
 
288
 
    @property
289
 
    def user(self):
290
 
        # Get and cache the request user, or None if it's not valid.
291
 
        # This is a property so that we don't create a store unless
292
 
        # some code actually requests the user.
293
 
        try:
294
 
            return self._user
295
 
        except AttributeError:
296
 
            if self.publicmode:
297
 
                self._user = None
298
 
            else:
299
 
                temp_user = ivle.webapp.security.get_user_details(self)
300
 
                if temp_user and temp_user.valid:
301
 
                    self._user = temp_user
302
 
                else:
303
 
                    self._user = None
304
 
            return self._user
305