'WSGI `app` method.
Makes instances of API callable from a WSGI server. May be used to
host an API or called directly in order to simulate requests when
testing the API.
(See also: PEP 3333)
Args:
env (dict): A WSGI environment dictionary
start_response (callable): A WSGI helper function for setting
status and headers on a response.'

def __call__(self, env, start_response):

    req = self._request_type(env, options=self.req_options)
    resp = self._response_type(options=self.resp_options)
    resource = None
    params = {}
    dependent_mw_resp_stack = []
    (mw_req_stack, mw_rsrc_stack, mw_resp_stack) = self._middleware
    req_succeeded = False
    try:
        if self._independent_middleware:
            for process_request in mw_req_stack:
                process_request(req, resp)
        else:
            for (process_request, process_response) in mw_req_stack:
                if process_request:
                    process_request(req, resp)
                if process_response:
                    dependent_mw_resp_stack.insert(0, process_response)
        (responder, params, resource, req.uri_template) = self._get_responder(req)
    except Exception as ex:
        if (not self._handle_exception(ex, req, resp, params)):
            raise
    else:
        try:
            if (resource is not None):
                for process_resource in mw_rsrc_stack:
                    process_resource(req, resp, resource, params)
            responder(req, resp, **params)
            req_succeeded = True
        except Exception as ex:
            if (not self._handle_exception(ex, req, resp, params)):
                raise
    finally:
        for process_response in (mw_resp_stack or dependent_mw_resp_stack):
            try:
                process_response(req, resp, resource, req_succeeded)
            except Exception as ex:
                if (not self._handle_exception(ex, req, resp, params)):
                    raise
                req_succeeded = False
    resp_status = (str(resp.status) if six.PY2 else resp.status)
    if ((req.method == 'HEAD') or (resp_status in self._BODILESS_STATUS_CODES)):
        body = []
    else:
        (body, length) = self._get_body(resp, env.get('wsgi.file_wrapper'))
        if (length is not None):
            resp._headers['content-length'] = str(length)
    if (resp_status in (status.HTTP_204, status.HTTP_304)):
        media_type = None
    else:
        media_type = self._media_type
    headers = resp._wsgi_headers(media_type)
    start_response(resp_status, headers)
    return body
