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

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

Update ivle.rpc.decorators to use new exceptions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
object.
26
26
"""
27
27
 
28
 
import mod_python
29
 
from mod_python import (util, Session, Cookie)
 
28
try:
 
29
    import mod_python.Session
 
30
    import mod_python.Cookie
 
31
    import mod_python.util
 
32
except ImportError:
 
33
    # This needs to be importable from outside Apache.
 
34
    pass
30
35
 
31
36
import ivle.util
32
37
import ivle.conf
33
38
import ivle.database
34
 
import plugins.console # XXX: Relies on www/ being in the Python path.
 
39
from ivle.webapp.base.plugins import CookiePlugin
35
40
 
36
41
class Request:
37
42
    """An IVLE request object. This is presented to the IVLE apps as a way of
231
236
        except KeyError:
232
237
            app = None
233
238
 
234
 
        # Write any final modifications to header content
235
 
        if app and app.useconsole and self.user:
236
 
            plugins.console.insert_scripts_styles(self.scripts, self.styles, \
237
 
                self.scripts_init)
238
 
 
239
239
        # Prepare the HTTP and HTML headers before the first write is made
240
240
        if self.content_type != None:
241
241
            self.apache_req.content_type = self.content_type
267
267
            # This includes binary strings.
268
268
            self.apache_req.write(string, flush)
269
269
 
 
270
    def logout(self):
 
271
        """Log out the current user by destroying the session state.
 
272
        Then redirect to the top-level IVLE page."""
 
273
        if hasattr(self, 'session'):
 
274
            self.session.invalidate()
 
275
            self.session.delete()
 
276
            # Invalidates all IVLE cookies
 
277
            all_cookies = mod_python.Cookie.get_cookies(self)
 
278
 
 
279
            # Create cookies for plugins that might request them.
 
280
            for plugin in self.plugin_index[CookiePlugin]:
 
281
                for cookie in plugin.cookies:
 
282
                    self.add_cookie(mod_python.Cookie.Cookie(cookie, '',
 
283
                                                    expires=1, path='/'))
 
284
        self.throw_redirect(ivle.util.make_path('')) 
 
285
 
 
286
 
270
287
    def flush(self):
271
288
        """Flushes the output buffer."""
272
289
        self.apache_req.flush()
310
327
    def add_cookie(self, cookie, value=None, **attributes):
311
328
        """Inserts a cookie into this request object's headers."""
312
329
        if value is None:
313
 
            Cookie.add_cookie(self.apache_req, cookie)
 
330
            mod_python.Cookie.add_cookie(self.apache_req, cookie)
314
331
        else:
315
 
            Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
 
332
            mod_python.Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
316
333
 
317
334
    def get_session(self):
318
335
        """Returns a mod_python Session object for this request.
320
337
        interface if porting away from mod_python."""
321
338
        # Cache the session object and set the timeout to 24 hours.
322
339
        if not hasattr(self, 'session'):
323
 
            self.session = Session.FileSession(self.apache_req,
 
340
            self.session = mod_python.Session.FileSession(self.apache_req,
324
341
                                               timeout = 60 * 60 * 24)
325
342
        return self.session
326
343
 
330
347
        interface if porting away from mod_python."""
331
348
        # Cache the fieldstorage object
332
349
        if not hasattr(self, 'fields'):
333
 
            self.fields = util.FieldStorage(self.apache_req)
 
350
            self.fields = mod_python.util.FieldStorage(self.apache_req)
334
351
        return self.fields
335
352
 
336
353
    def get_cgi_environ(self):