comparison 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
comparison
equal deleted inserted replaced
6128:561b7a9c2bd9 6129:7f12cf241d5e
154 """ 154 """
155 response = self.get_response(environ) 155 response = self.get_response(environ)
156 return response(environ, start_response) 156 return response(environ, start_response)
157 157
158 def __str__(self): 158 def __str__(self):
159 return '%d: %s' % (self.code, self.name) 159 code = self.code if self.code is not None else '???'
160 return '%s %s: %s' % (code, self.name, self.description)
160 161
161 def __repr__(self): 162 def __repr__(self):
162 return '<%s \'%s\'>' % (self.__class__.__name__, self) 163 code = self.code if self.code is not None else '???'
164 return "<%s '%s: %s'>" % (self.__class__.__name__, code, self.name)
163 165
164 166
165 class BadRequest(HTTPException): 167 class BadRequest(HTTPException):
166 168
167 """*400* `Bad Request` 169 """*400* `Bad Request`
410 412
411 class RequestedRangeNotSatisfiable(HTTPException): 413 class RequestedRangeNotSatisfiable(HTTPException):
412 414
413 """*416* `Requested Range Not Satisfiable` 415 """*416* `Requested Range Not Satisfiable`
414 416
415 The client asked for a part of the file that lies beyond the end 417 The client asked for an invalid part of the file.
416 of the file.
417 418
418 .. versionadded:: 0.7 419 .. versionadded:: 0.7
419 """ 420 """
420 code = 416 421 code = 416
421 description = ( 422 description = (
422 'The server cannot provide the requested range.' 423 'The server cannot provide the requested range.'
423 ) 424 )
425
426 def __init__(self, length=None, units="bytes", description=None):
427 """Takes an optional `Content-Range` header value based on ``length``
428 parameter.
429 """
430 HTTPException.__init__(self, description)
431 self.length = length
432 self.units = units
433
434 def get_headers(self, environ):
435 headers = HTTPException.get_headers(self, environ)
436 if self.length is not None:
437 headers.append(
438 ('Content-Range', '%s */%d' % (self.units, self.length)))
439 return headers
424 440
425 441
426 class ExpectationFailed(HTTPException): 442 class ExpectationFailed(HTTPException):
427 443
428 """*417* `Expectation Failed` 444 """*417* `Expectation Failed`
461 """ 477 """
462 code = 422 478 code = 422
463 description = ( 479 description = (
464 'The request was well-formed but was unable to be followed ' 480 'The request was well-formed but was unable to be followed '
465 'due to semantic errors.' 481 'due to semantic errors.'
482 )
483
484
485 class Locked(HTTPException):
486
487 """*423* `Locked`
488
489 Used if the resource that is being accessed is locked.
490 """
491 code = 423
492 description = (
493 'The resource that is being accessed is locked.'
466 ) 494 )
467 495
468 496
469 class PreconditionRequired(HTTPException): 497 class PreconditionRequired(HTTPException):
470 498
510 headers is too large. 538 headers is too large.
511 """ 539 """
512 code = 431 540 code = 431
513 description = ( 541 description = (
514 'One or more header fields exceeds the maximum size.' 542 'One or more header fields exceeds the maximum size.'
543 )
544
545
546 class UnavailableForLegalReasons(HTTPException):
547
548 """*451* `Unavailable For Legal Reasons`
549
550 This status code indicates that the server is denying access to the
551 resource as a consequence of a legal demand.
552 """
553 code = 451
554 description = (
555 'Unavailable for legal reasons.'
515 ) 556 )
516 557
517 558
518 class InternalServerError(HTTPException): 559 class InternalServerError(HTTPException):
519 560
643 raise HTTPException(response=code) 684 raise HTTPException(response=code)
644 if code not in self.mapping: 685 if code not in self.mapping:
645 raise LookupError('no exception for %r' % code) 686 raise LookupError('no exception for %r' % code)
646 raise self.mapping[code](*args, **kwargs) 687 raise self.mapping[code](*args, **kwargs)
647 688
648 abort = Aborter() 689
690 def abort(status, *args, **kwargs):
691 '''
692 Raises an :py:exc:`HTTPException` for the given status code or WSGI
693 application::
694
695 abort(404) # 404 Not Found
696 abort(Response('Hello World'))
697
698 Can be passed a WSGI application or a status code. If a status code is
699 given it's looked up in the list of exceptions and will raise that
700 exception, if passed a WSGI application it will wrap it in a proxy WSGI
701 exception and raise that::
702
703 abort(404)
704 abort(Response('Hello World'))
705
706 '''
707 return _aborter(status, *args, **kwargs)
708
709 _aborter = Aborter()
649 710
650 711
651 #: an exception that is used internally to signal both a key error and a 712 #: an exception that is used internally to signal both a key error and a
652 #: bad request. Used by a lot of the datastructures. 713 #: bad request. Used by a lot of the datastructures.
653 BadRequestKeyError = BadRequest.wrap(KeyError) 714 BadRequestKeyError = BadRequest.wrap(KeyError)