diff MoinMoin/support/werkzeug/exceptions.py @ 6129:7f12cf241d5e

update werkzeug to 0.12.1, update CHANGES
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 11 Apr 2017 22:42:23 +0200
parents 9f12f41504fc
children
line wrap: on
line diff
--- a/MoinMoin/support/werkzeug/exceptions.py	Tue Nov 01 17:56:32 2016 +0100
+++ b/MoinMoin/support/werkzeug/exceptions.py	Tue Apr 11 22:42:23 2017 +0200
@@ -156,10 +156,12 @@
         return response(environ, start_response)
 
     def __str__(self):
-        return '%d: %s' % (self.code, self.name)
+        code = self.code if self.code is not None else '???'
+        return '%s %s: %s' % (code, self.name, self.description)
 
     def __repr__(self):
-        return '<%s \'%s\'>' % (self.__class__.__name__, self)
+        code = self.code if self.code is not None else '???'
+        return "<%s '%s: %s'>" % (self.__class__.__name__, code, self.name)
 
 
 class BadRequest(HTTPException):
@@ -412,8 +414,7 @@
 
     """*416* `Requested Range Not Satisfiable`
 
-    The client asked for a part of the file that lies beyond the end
-    of the file.
+    The client asked for an invalid part of the file.
 
     .. versionadded:: 0.7
     """
@@ -422,6 +423,21 @@
         'The server cannot provide the requested range.'
     )
 
+    def __init__(self, length=None, units="bytes", description=None):
+        """Takes an optional `Content-Range` header value based on ``length``
+        parameter.
+        """
+        HTTPException.__init__(self, description)
+        self.length = length
+        self.units = units
+
+    def get_headers(self, environ):
+        headers = HTTPException.get_headers(self, environ)
+        if self.length is not None:
+            headers.append(
+                ('Content-Range', '%s */%d' % (self.units, self.length)))
+        return headers
+
 
 class ExpectationFailed(HTTPException):
 
@@ -466,6 +482,18 @@
     )
 
 
+class Locked(HTTPException):
+
+    """*423* `Locked`
+
+    Used if the resource that is being accessed is locked.
+    """
+    code = 423
+    description = (
+        'The resource that is being accessed is locked.'
+    )
+
+
 class PreconditionRequired(HTTPException):
 
     """*428* `Precondition Required`
@@ -515,6 +543,19 @@
     )
 
 
+class UnavailableForLegalReasons(HTTPException):
+
+    """*451* `Unavailable For Legal Reasons`
+
+    This status code indicates that the server is denying access to the
+    resource as a consequence of a legal demand.
+    """
+    code = 451
+    description = (
+        'Unavailable for legal reasons.'
+    )
+
+
 class InternalServerError(HTTPException):
 
     """*500* `Internal Server Error`
@@ -645,7 +686,27 @@
             raise LookupError('no exception for %r' % code)
         raise self.mapping[code](*args, **kwargs)
 
-abort = Aborter()
+
+def abort(status, *args, **kwargs):
+    '''
+    Raises an :py:exc:`HTTPException` for the given status code or WSGI
+    application::
+
+        abort(404)  # 404 Not Found
+        abort(Response('Hello World'))
+
+    Can be passed a WSGI application or a status code.  If a status code is
+    given it's looked up in the list of exceptions and will raise that
+    exception, if passed a WSGI application it will wrap it in a proxy WSGI
+    exception and raise that::
+
+       abort(404)
+       abort(Response('Hello World'))
+
+    '''
+    return _aborter(status, *args, **kwargs)
+
+_aborter = Aborter()
 
 
 #: an exception that is used internally to signal both a key error and a