<s> """<STR_LIT>""" <EOL> import sys <EOL> from . _compat import integer_types , text_type <EOL> from . http import HTTP_STATUS_CODES , html_escape <EOL> class HTTPException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = '<STR_LIT>' <EOL> def __init__ ( self , description = None ) : <EOL> Exception . __init__ ( self ) <EOL> if description is not None : <EOL> self . description = description <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return HTTP_STATUS_CODES . get ( self . code , '<STR_LIT>' ) <EOL> def get_description ( self ) : <EOL> """<STR_LIT>""" <EOL> return u'<STR_LIT:%s>' % self . description <EOL> def get_body ( self ) : <EOL> """<STR_LIT>""" <EOL> return text_type ( ( u'<STR_LIT>' ) % { <EOL> '<STR_LIT:description>' : self . get_description ( ) <EOL> } ) <EOL> def get_headers ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] <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 RequestRedirect ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> def __init__ ( self , new_url ) : <EOL> self . new_url = new_url <EOL> def get_headers ( self ) : <EOL> return [ ( '<STR_LIT>' , self . new_url ) , ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) ] <EOL> def get_body ( self ) : <EOL> display_location = html_escape ( self . new_url ) <EOL> body = text_type ( ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) % ( html_escape ( self . new_url ) , display_location ) ) <EOL> return body <EOL> class BadRequest ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <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 ) : <EOL> headers = HTTPException . get_headers ( self ) <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> class GatewayTimeout ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> ) <EOL> class HTTPVersionNotSupported ( HTTPException ) : <EOL> """<STR_LIT>""" <EOL> code = <NUM_LIT> <EOL> description = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> default_exceptions = { } <EOL> __all__ = [ '<STR_LIT>' ] <EOL> def _find_exceptions ( ) : <EOL> for name , obj in globals ( ) . items ( ) : <EOL> try : <EOL> is_http_exception = issubclass ( obj , HTTPException ) <EOL> except TypeError : <EOL> is_http_exception = False <EOL> if not is_http_exception or obj . code is None : <EOL> continue <EOL> __all__ . append ( obj . __name__ ) <EOL> old_obj = default_exceptions . get ( obj . code , None ) <EOL> if old_obj is not None and issubclass ( obj , old_obj ) : <EOL> continue <EOL> default_exceptions [ obj . code ] = obj <EOL> _find_exceptions ( ) <EOL> del _find_exceptions <EOL> def abort ( code , * args , ** kwargs ) : <EOL> mapping = default_exceptions <EOL> if not args and not kwargs and not isinstance ( code , integer_types ) : <EOL> raise HTTPException ( response = code ) <EOL> if code not in mapping : <EOL> raise LookupError ( '<STR_LIT>' % code ) <EOL> raise mapping [ code ] ( * args , ** kwargs ) </s>
