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

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

Drop the 4xx-series exception handling ability from
ivle.dispatch.handle_unknown_exception(). Nothing raises anything but a 5xx
IVLEError now.

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
224
229
        """Writes out the HTTP and HTML headers before any real data is
225
230
        written."""
226
231
        self.headers_written = True
227
 
        
228
 
        # app is the App object for the chosen app
229
 
        try:
230
 
            app = ivle.conf.apps.app_url[self.app]
231
 
        except KeyError:
232
 
            app = None
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
232
 
239
233
        # Prepare the HTTP and HTML headers before the first write is made
240
234
        if self.content_type != None:
270
264
    def logout(self):
271
265
        """Log out the current user by destroying the session state.
272
266
        Then redirect to the top-level IVLE page."""
273
 
        # List of cookies that IVLE uses (to be removed at logout)
274
 
        ivle_cookies = ["ivleforumcookie", "clipboard"]
275
 
        
276
267
        if hasattr(self, 'session'):
277
268
            self.session.invalidate()
278
269
            self.session.delete()
279
270
            # Invalidates all IVLE cookies
280
 
            all_cookies = Cookie.get_cookies(self)
281
 
            for cookie in all_cookies:
282
 
                if cookie in ivle_cookies:
283
 
                    self.add_cookie(Cookie.Cookie(cookie,'',expires=1,path='/'))
 
271
            all_cookies = mod_python.Cookie.get_cookies(self)
 
272
 
 
273
            # Create cookies for plugins that might request them.
 
274
            for plugin in self.config.plugin_index[CookiePlugin]:
 
275
                for cookie in plugin.cookies:
 
276
                    self.add_cookie(mod_python.Cookie.Cookie(cookie, '',
 
277
                                                    expires=1, path='/'))
284
278
        self.throw_redirect(ivle.util.make_path('')) 
285
279
 
286
280
 
302
296
        else:
303
297
            return self.apache_req.read(len)
304
298
 
305
 
    def throw_error(self, httpcode, message=None):
306
 
        """Writes out an HTTP error of the specified code. Raises an exception
307
 
        which is caught by the dispatch or web server, so any code following
308
 
        this call will not be executed.
309
 
 
310
 
        httpcode: An HTTP response status code. Pass a constant from the
311
 
        Request class.
312
 
        """
313
 
        raise ivle.util.IVLEError(httpcode, message)
314
 
 
315
299
    def throw_redirect(self, location):
316
300
        """Writes out an HTTP redirect to the specified URL. Raises an
317
301
        exception which is caught by the dispatch or web server, so any
327
311
    def add_cookie(self, cookie, value=None, **attributes):
328
312
        """Inserts a cookie into this request object's headers."""
329
313
        if value is None:
330
 
            Cookie.add_cookie(self.apache_req, cookie)
 
314
            mod_python.Cookie.add_cookie(self.apache_req, cookie)
331
315
        else:
332
 
            Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
 
316
            mod_python.Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
333
317
 
334
318
    def get_session(self):
335
319
        """Returns a mod_python Session object for this request.
337
321
        interface if porting away from mod_python."""
338
322
        # Cache the session object and set the timeout to 24 hours.
339
323
        if not hasattr(self, 'session'):
340
 
            self.session = Session.FileSession(self.apache_req,
 
324
            self.session = mod_python.Session.FileSession(self.apache_req,
341
325
                                               timeout = 60 * 60 * 24)
342
326
        return self.session
343
327
 
347
331
        interface if porting away from mod_python."""
348
332
        # Cache the fieldstorage object
349
333
        if not hasattr(self, 'fields'):
350
 
            self.fields = util.FieldStorage(self.apache_req)
 
334
            self.fields = mod_python.util.FieldStorage(self.apache_req)
351
335
        return self.fields
352
336
 
353
337
    def get_cgi_environ(self):