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

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

  • Committer: me at id
  • Date: 2009-01-15 02:55:57 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:1149
ivle.fileservice_lib.action.get_login: Always give credentials as strs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
object.
26
26
"""
27
27
 
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
 
28
import mod_python
 
29
from mod_python import (util, Session, Cookie)
35
30
 
36
31
import ivle.util
37
32
import ivle.conf
38
33
import ivle.database
39
 
from ivle.webapp.base.plugins import CookiePlugin
 
34
import plugins.console # XXX: Relies on www/ being in the Python path.
40
35
 
41
36
class Request:
42
37
    """An IVLE request object. This is presented to the IVLE apps as a way of
236
231
        except KeyError:
237
232
            app = None
238
233
 
 
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.config.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
 
 
287
270
    def flush(self):
288
271
        """Flushes the output buffer."""
289
272
        self.apache_req.flush()
327
310
    def add_cookie(self, cookie, value=None, **attributes):
328
311
        """Inserts a cookie into this request object's headers."""
329
312
        if value is None:
330
 
            mod_python.Cookie.add_cookie(self.apache_req, cookie)
 
313
            Cookie.add_cookie(self.apache_req, cookie)
331
314
        else:
332
 
            mod_python.Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
 
315
            Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
333
316
 
334
317
    def get_session(self):
335
318
        """Returns a mod_python Session object for this request.
337
320
        interface if porting away from mod_python."""
338
321
        # Cache the session object and set the timeout to 24 hours.
339
322
        if not hasattr(self, 'session'):
340
 
            self.session = mod_python.Session.FileSession(self.apache_req,
 
323
            self.session = Session.FileSession(self.apache_req,
341
324
                                               timeout = 60 * 60 * 24)
342
325
        return self.session
343
326
 
347
330
        interface if porting away from mod_python."""
348
331
        # Cache the fieldstorage object
349
332
        if not hasattr(self, 'fields'):
350
 
            self.fields = mod_python.util.FieldStorage(self.apache_req)
 
333
            self.fields = util.FieldStorage(self.apache_req)
351
334
        return self.fields
352
335
 
353
336
    def get_cgi_environ(self):