#NEWLINE# def __call__( self , environ , start_response ) : #NEWLINE# #INDENT# url = [ ] #NEWLINE# def change_response( status , headers , exc_info = None ) : #NEWLINE# #INDENT# status_code = status . split ( ' ' ) #NEWLINE# try : #NEWLINE# #INDENT# code = int ( status_code [ 0 ] ) #NEWLINE# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# raise Exception ( ( 'StatusBasedForward middleware received an invalid status code %s' % repr ( status_code [ 0 ] ) ) ) #NEWLINE# #UNINDENT# message = ' ' . join ( status_code [ 1 : ] ) #NEWLINE# new_url = self . mapper ( code , message , environ , self . global_conf , ** self . params ) #NEWLINE# if ( not ( ( new_url == None ) or isinstance ( new_url , str ) ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'Expected the url to internally redirect to in the StatusBasedForward mapperto be a string or None, not %r' % new_url ) ) #NEWLINE# #UNINDENT# if new_url : #NEWLINE# #INDENT# url . append ( [ new_url , status , headers ] ) #NEWLINE# return [ ] . append #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return start_response ( status , headers , exc_info ) #NEWLINE# #UNINDENT# #UNINDENT# app_iter = self . application ( environ , change_response ) #NEWLINE# if url : #NEWLINE# #INDENT# if hasattr ( app_iter , 'close' ) : #NEWLINE# #INDENT# app_iter . close ( ) #NEWLINE# #UNINDENT# def factory( app ) : #NEWLINE# #INDENT# return StatusKeeper ( app , status = url [ 0 ] [ 1 ] , url = url [ 0 ] [ 0 ] , headers = url [ 0 ] [ 2 ] ) #NEWLINE# #UNINDENT# raise ForwardRequestException ( factory = factory ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return app_iter