changeset 4142:26dbb6d47863

Added MoinMoin specific HTTP-exceptions (SurgeProtection for example)
author Florian Krupicka <florian.krupicka@googlemail.com>
date Tue, 03 Jun 2008 11:51:16 +0200
parents 049b9aaf3031
children 917970e17b73
files MoinMoin/web/exceptions.py
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/web/exceptions.py	Tue Jun 03 11:51:16 2008 +0200
@@ -0,0 +1,33 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - HTTP exceptions
+
+    @copyright: 2008-2008 MoinMoin:FlorianKrupicka
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from werkzeug import exceptions
+
+class SurgeProtection(exceptions.ServiceUnavailable):
+    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, retry_after=3600):
+        ServiceUnavailable.__init__(self)
+        self.retry_after = retry_after
+
+    def get_headers(self, environ):
+        headers = ServiceUnavailable.get_headers(self, environ)
+        headers.append(('Retry-After', '%d' % self.retry_after))
+        return headers
+
+class Forbidden(exceptions.Forbidden):
+    description = "<p>You are not allowed to access this!</p>"
+
+class PageNotFound(exceptions.NotFound):
+    pass