#NEWLINE# def __call__( self , env , start_response ) : #NEWLINE# #INDENT# 'WSGI `app` method.\n\n        Makes instances of API callable from a WSGI server. May be used to\n        host an API or called directly in order to simulate requests when\n        testing the API.\n\n        See also PEP 3333.\n\n        Args:\n            env (dict): A WSGI environment dictionary\n            start_response (callable): A WSGI helper function for setting\n                status and headers on a response.\n\n        ' #NEWLINE# req = self . _request_type ( env , options = self . req_options ) #NEWLINE# resp = self . _response_type ( ) #NEWLINE# resource = None #NEWLINE# middleware_stack = [ ] #NEWLINE# params = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . _call_req_mw ( middleware_stack , req , resp ) #NEWLINE# ( responder , params , resource ) = self . _get_responder ( req ) #NEWLINE# if ( resource is not None ) : #NEWLINE# #INDENT# self . _call_rsrc_mw ( middleware_stack , req , resp , resource , params ) #NEWLINE# #UNINDENT# responder ( req , resp , ** params ) #NEWLINE# self . _call_resp_mw ( middleware_stack , req , resp , resource ) #NEWLINE# #UNINDENT# except Exception as ex : #NEWLINE# #INDENT# for ( err_type , err_handler ) in self . _error_handlers : #NEWLINE# #INDENT# if isinstance ( ex , err_type ) : #NEWLINE# #INDENT# err_handler ( ex , req , resp , params ) #NEWLINE# self . _call_resp_mw ( middleware_stack , req , resp , resource ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . _call_resp_mw ( middleware_stack , req , resp , resource ) #NEWLINE# raise #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except HTTPStatus as ex : #NEWLINE# #INDENT# self . _compose_status_response ( req , resp , ex ) #NEWLINE# self . _call_resp_mw ( middleware_stack , req , resp , resource ) #NEWLINE# #UNINDENT# except HTTPError as ex : #NEWLINE# #INDENT# self . _compose_error_response ( req , resp , ex ) #NEWLINE# self . _call_resp_mw ( middleware_stack , req , resp , resource ) #NEWLINE# #UNINDENT# if ( ( req . method == 'HEAD' ) or ( resp . status in self . _BODILESS_STATUS_CODES ) ) : #NEWLINE# #INDENT# body = [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( body , length ) = self . _get_body ( resp , env . get ( 'wsgi.file_wrapper' ) ) #NEWLINE# if ( length is not None ) : #NEWLINE# #INDENT# resp . _headers [ 'content-length' ] = str ( length ) #NEWLINE# #UNINDENT# #UNINDENT# if ( resp . status in ( status . HTTP_204 , status . HTTP_304 ) ) : #NEWLINE# #INDENT# media_type = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# media_type = self . _media_type #NEWLINE# #UNINDENT# headers = resp . _wsgi_headers ( media_type ) #NEWLINE# start_response ( resp . status , headers ) #NEWLINE# return body