<s> """<STR_LIT>""" <EOL> import sys <EOL> import werkzeug <EOL> werkzeug . exceptions = sys . modules [ __name__ ] <EOL> from werkzeug . _internal import _get_environ <EOL> from werkzeug . _compat import iteritems , integer_types , text_type , implements_to_string <EOL> from werkzeug . wrappers import Response <EOL> @ implements_to_string <EOL> class HTTPException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> code = None <EOL> description = None <EOL> def __init__ ( self , description = None , response = None ) : <EOL> Exception . __init__ ( self ) <EOL> if description is not None : <EOL> self . description = description <EOL> self . response = response <EOL> @ classmethod <EOL> def wrap ( cls , exception , name = None ) : <EOL> """<STR_LIT>""" <EOL> class newcls ( cls , exception ) : <EOL> def __init__ ( self , arg = None , * args , ** kwargs ) : <EOL> cls . __init__ ( self , * args , ** kwargs ) <EOL> exception . __init__ ( self , arg ) <EOL> newcls . __module__ = sys . _getframe ( <NUM_LIT:1> ) . f_globals . get ( '<STR_LIT>' ) <EOL> newcls . __name__ = name or cls . __name__ + exception . __name__ <EOL> return newcls <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return HTTP_STATUS_CODES . get ( self . code , '<STR_LIT>' ) <EOL> def get_description ( self , environ = None ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT>' % escape ( self . description ) <EOL> def get_body ( self , environ = None ) : <EOL> """<STR_LIT>""" <EOL> return text_type ( ( <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> u'<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT:code>' : self . code , <EOL> '<STR_LIT:name>' : escape ( self . name ) , <EOL> '<STR_LIT:description>' : self . get_description ( environ ) <EOL> } ) <EOL> def get_headers ( self , environ = None ) : <EOL> """<STR_LIT>""" <EOL> return [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] <EOL> def get_response ( self , environ = None ) : <EOL> """<STR_LIT>""" <EOL> if self . response is not None : <EOL> return self . response <EOL> if environ is not None : <EOL> environ = _get_environ ( environ ) <EOL> headers = self . get_headers ( environ ) <EOL> return Response ( self . get_body ( environ ) , self . code , headers ) <EOL> def __call__ ( self , environ , start_response ) : <EOL> """<STR_LIT>""" <EOL> response = self . get_response ( environ ) <EOL> return response ( environ , start_response ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . code , self . name ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self ) <EOL> class BadRequest ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class ClientDisconnected ( BadRequest ) : <EOL> """<STR_LIT>""" <EOL> class SecurityError ( BadRequest ) : <EOL> """<STR_LIT>""" <EOL> class Unauthorized ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class Forbidden ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class NotFound ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class MethodNotAllowed ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = '<STR_LIT>' <EOL> def __init__ ( self , valid_methods = None , description = None ) : <EOL> """<STR_LIT>""" <EOL> HTTPException . __init__ ( self , description ) <EOL> self . valid_methods = valid_methods <EOL> def get_headers ( self , environ ) : <EOL> headers = HTTPException . get_headers ( self , environ ) <EOL> if self . valid_methods : <EOL> headers . append ( ( '<STR_LIT>' , '<STR_LIT:U+002CU+0020>' . join ( self . valid_methods ) ) ) <EOL> return headers <EOL> class NotAcceptable ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class RequestTimeout ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class Conflict ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class Gone ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class LengthRequired ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class PreconditionFailed ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class RequestEntityTooLarge ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class RequestURITooLarge ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class UnsupportedMediaType ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class RequestedRangeNotSatisfiable ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class ExpectationFailed ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class ImATeapot ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class UnprocessableEntity ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class PreconditionRequired ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class TooManyRequests ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class RequestHeaderFieldsTooLarge ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class InternalServerError ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class NotImplemented ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class BadGateway ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> class ServiceUnavailable ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> default_exceptions = { } <EOL> __all__ = [ '<STR_LIT>' ] <EOL> def _find_exceptions ( ) : <EOL> for name , obj in iteritems ( globals ( ) ) : <EOL> try : <EOL> if getattr ( obj , '<STR_LIT:code>' , None ) is not None : <EOL> default_exceptions [ obj . code ] = obj <EOL> __all__ . append ( obj . __name__ ) <EOL> except TypeError : <EOL> continue <EOL> _find_exceptions ( ) <EOL> del _find_exceptions <EOL> class Aborter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , mapping = None , extra = None ) : <EOL> if mapping is None : <EOL> mapping = default_exceptions <EOL> self . mapping = dict ( mapping ) <EOL> if extra is not None : <EOL> self . mapping . update ( extra ) <EOL> def __call__ ( self , code , * args , ** kwargs ) : <EOL> if not args and not kwargs and not isinstance ( code , integer_types ) : <EOL> raise HTTPException ( response = code ) <EOL> if code not in self . mapping : <EOL> raise LookupError ( '<STR_LIT>' % code ) <EOL> raise self . mapping [ code ] ( * args , ** kwargs ) <EOL> abort = Aborter ( ) <EOL> BadRequestKeyError = BadRequest . wrap ( KeyError ) <EOL> from werkzeug . utils import escape <EOL> from werkzeug . http import HTTP_STATUS_CODES </s>
