File: exceptions.py

package info (click to toggle)
moin 1.9.9-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 76,024 kB
  • sloc: python: 143,896; java: 10,704; php: 2,385; perl: 1,574; xml: 371; makefile: 214; sh: 81; sed: 5
file content (46 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - HTTP exceptions

    Customization of werkzeug.exceptions classes for use in MoinMoin.

    @copyright: 2008-2008 MoinMoin:FlorianKrupicka
    @license: GNU GPL, see COPYING for details.
"""

from werkzeug import exceptions

HTTPException = exceptions.HTTPException

class SurgeProtection(exceptions.ServiceUnavailable):
    """ A surge protection error in MoinMoin is based on the HTTP status
    `Service Unavailable`. This HTTP exception gives a short description
    on what triggered the surge protection mechanism to the user.
    """

    name = 'Surge protection'
    description = (
        "<strong>Warning:</strong>"
        "<p>You triggered the wiki's surge protection by doing too many requests in a short time.</p>"
        "<p>Please make a short break reading the stuff you already got.</p>"
        "<p>When you restart doing requests AFTER that, slow down or you might get locked out for a longer time!</p>"
    )

    def __init__(self, description=None, retry_after=3600):
        exceptions.ServiceUnavailable.__init__(self, description)
        self.retry_after = retry_after

    def get_headers(self, environ):
        headers = exceptions.ServiceUnavailable.get_headers(self, environ)
        headers.append(('Retry-After', '%d' % self.retry_after))
        return headers

class Forbidden(exceptions.Forbidden):
    """
    Override the default description of werkzeug.exceptions.Forbidden to a
    less technical sounding one.
    """
    description = "<p>You are not allowed to access this!</p>"

# handy exception raising
abort = exceptions.abort