'Prepare a L{Request} which, when a request is received, captures the
C{environ} and C{start_response} callable passed to a WSGI app.
@param application: An optional WSGI application callable that accepts
the familiar C{environ} and C{start_response} args and returns an
iterable of body content. If not supplied, C{start_response} will
be called with a "200 OK" status and no headers, and no content
will be yielded.
@return: A two-tuple of (C{request}, C{deferred}). The former is a
Twisted L{Request}. The latter is a L{Deferred} which will be
called back with a two-tuple of the arguments passed to a WSGI
application (i.e. the C{environ} and C{start_response} callable),
or will errback with any error arising within the WSGI app.'

def prepareRequest(self, application=None):

    result = Deferred()
    def outerApplication(environ, startResponse):
        try:
            if (application is None):
                startResponse('200    OK', [])
                content = iter(())
            else:
                content = application(environ, startResponse)
        except:
            result.errback()
            startResponse('500    Error', [])
            return iter(())
        else:
            result.callback((environ, startResponse))
            return content
    resource = WSGIResource(self.reactor, self.threadpool, outerApplication)
    root = Resource()
    root.putChild('res', resource)
    channel = self.channelFactory()
    channel.site = Site(root)
    class CannedRequest(Request, ):
        "\n                                                Convenient    L{Request}    derivative    which    has    canned    values    for    all\n                                                of    C{requestReceived}'s    arguments.\n                                                "
        def requestReceived(self, command='GET', path='/res', version='1.1'):
            return Request.requestReceived(self, command=command, path=path, version=version)
    request = CannedRequest(channel, queued=False)
    request.gotLength(0)
    return (request, result)
