Back to index

moin  1.9.0~rc2
exceptions.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - HTTP exceptions
00004 
00005     Customization of werkzeug.exceptions classes for use in MoinMoin.
00006 
00007     @copyright: 2008-2008 MoinMoin:FlorianKrupicka
00008     @license: GNU GPL, see COPYING for details.
00009 """
00010 
00011 from werkzeug import exceptions
00012 
00013 HTTPException = exceptions.HTTPException
00014 
00015 class SurgeProtection(exceptions.ServiceUnavailable):
00016     """ A surge protection error in MoinMoin is based on the HTTP status
00017     `Service Unavailable`. This HTTP exception gives a short description
00018     on what triggered the surge protection mechanism to the user.
00019     """
00020 
00021     name = 'Surge protection'
00022     description = (
00023         "<strong>Warning:</strong>"
00024         "<p>You triggered the wiki's surge protection by doing too many requests in a short time.</p>"
00025         "<p>Please make a short break reading the stuff you already got.</p>"
00026         "<p>When you restart doing requests AFTER that, slow down or you might get locked out for a longer time!</p>"
00027     )
00028 
00029     def __init__(self, description=None, retry_after=3600):
00030         exceptions.ServiceUnavailable.__init__(self, description)
00031         self.retry_after = retry_after
00032 
00033     def get_headers(self, environ):
00034         headers = exceptions.ServiceUnavailable.get_headers(self, environ)
00035         headers.append(('Retry-After', '%d' % self.retry_after))
00036         return headers
00037 
00038 class Forbidden(exceptions.Forbidden):
00039     """
00040     Override the default description of werkzeug.exceptions.Forbidden to a
00041     less technical sounding one.
00042     """
00043     description = "<p>You are not allowed to access this!</p>"
00044 
00045 # handy exception raising
00046 abort = exceptions.abort