human
Complete this python program:
def forward(app, codes):
assistant
#Here is the Python program you requested.

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