#NEWLINE# def forward( app , codes ) : #NEWLINE# #INDENT# '\n    Intercepts a response with a particular status code and returns the\n    content from a specified URL instead.\n\n    The arguments are:\n\n    ``app``\n        The WSGI application or middleware chain.\n\n    ``codes``\n        A dictionary of integer status codes and the URL to be displayed\n        if the response uses that code.\n\n    For example, you might want to create a static file to display a\n    "File Not Found" message at the URL ``/error404.html`` and then use\n    ``forward`` middleware to catch all 404 status codes and display the page\n    you created. In this example ``app`` is your exisiting WSGI\n    applicaiton::\n\n        from paste.errordocument import forward\n        app = forward(app, codes={404:\'/error404.html\'})\n\n    ' #NEWLINE# for code in codes : #NEWLINE# #INDENT# if ( not isinstance ( code , int ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'All status codes should be type int. %s is not valid' % repr ( code ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# def error_codes_mapper( code , message , environ , global_conf , codes ) : #NEWLINE# #INDENT# if ( code in codes ) : #NEWLINE# #INDENT# return codes [ code ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# return RecursiveMiddleware ( StatusBasedForward ( app , error_codes_mapper , codes = codes ) )