{
    "file_diffs": [
        {
            "old_file_content": "\"\"\"wsgi server.\n\nTODO:\n  * proxy protocol\n  * x-forward security\n  * wsgi file support (os.sendfile)\n\"\"\"\n\nimport asyncio\nimport inspect\nimport io\nimport os\nimport sys\nfrom urllib.parse import urlsplit\n\nimport aiohttp\nfrom aiohttp import server, hdrs\n\n__all__ = ('WSGIServerHttpProtocol',)\n\n\nclass WSGIServerHttpProtocol(server.ServerHttpProtocol):\n    \"\"\"HTTP Server that implements the Python WSGI protocol.\n\n    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently\n    depends on 'readpayload' constructor parameter. If readpayload is set to\n    True, wsgi server reads all incoming data into BytesIO object and\n    sends it as 'wsgi.input' environ var. If readpayload is set to false\n    'wsgi.input' is a StreamReader and application should read incoming\n    data with \"yield from environ['wsgi.input'].read()\". It defaults to False.\n    \"\"\"\n\n    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')\n\n    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):\n        super().__init__(*args, **kw)\n\n        self.wsgi = app\n        self.is_ssl = is_ssl\n        self.readpayload = readpayload\n\n    def create_wsgi_response(self, message):\n        return WsgiResponse(self.writer, message)\n\n    def create_wsgi_environ(self, message, payload):\n        uri_parts = urlsplit(message.path)\n        url_scheme = 'https' if self.is_ssl else 'http'\n\n        environ = {\n            'wsgi.input': payload,\n            'wsgi.errors': sys.stderr,\n            'wsgi.version': (1, 0),\n            'wsgi.async': True,\n            'wsgi.multithread': False,\n            'wsgi.multiprocess': False,\n            'wsgi.run_once': False,\n            'wsgi.file_wrapper': FileWrapper,\n            'wsgi.url_scheme': url_scheme,\n            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,\n            'REQUEST_METHOD': message.method,\n            'QUERY_STRING': uri_parts.query or '',\n            'RAW_URI': message.path,\n            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version\n        }\n\n        script_name = self.SCRIPT_NAME\n\n        for hdr_name, hdr_value in message.headers.items():\n            if hdr_name == 'AUTHORIZATION':\n                continue\n            elif hdr_name == 'SCRIPT_NAME':\n                script_name = hdr_value\n            elif hdr_name == 'CONTENT-TYPE':\n                environ['CONTENT_TYPE'] = hdr_value\n                continue\n            elif hdr_name == 'CONTENT-LENGTH':\n                environ['CONTENT_LENGTH'] = hdr_value\n                continue\n\n            key = 'HTTP_%s' % hdr_name.replace('-', '_')\n            if key in environ:\n                hdr_value = '%s,%s' % (environ[key], hdr_value)\n\n            environ[key] = hdr_value\n\n        remote = self.transport.get_extra_info('peername')\n        environ['REMOTE_ADDR'] = remote[0]\n        environ['REMOTE_PORT'] = remote[1]\n        host = message.headers.get(\"HOST\", None)\n        if host:\n            host = host.split(\":\")\n        else:\n            host = self.transport.get_extra_info('sockname')\n        environ['SERVER_NAME'] = host[0]\n        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'\n\n        path_info = uri_parts.path\n        if script_name:\n            path_info = path_info.split(script_name, 1)[-1]\n\n        environ['PATH_INFO'] = path_info\n        environ['SCRIPT_NAME'] = script_name\n\n        environ['async.reader'] = self.reader\n        environ['async.writer'] = self.writer\n\n        return environ\n\n    @asyncio.coroutine\n    def handle_request(self, message, payload):\n        \"\"\"Handle a single HTTP request\"\"\"\n        now = self._loop.time()\n\n        if self.readpayload:\n            wsgiinput = io.BytesIO()\n            wsgiinput.write((yield from payload.read()))\n            wsgiinput.seek(0)\n            payload = wsgiinput\n\n        environ = self.create_wsgi_environ(message, payload)\n        response = self.create_wsgi_response(message)\n\n        riter = self.wsgi(environ, response.start_response)\n        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):\n            riter = yield from riter\n\n        resp = response.response\n        try:\n            for item in riter:\n                if isinstance(item, asyncio.Future):\n                    item = yield from item\n                yield from resp.write(item)\n\n            yield from resp.write_eof()\n        finally:\n            if hasattr(riter, 'close'):\n                riter.close()\n\n        if resp.keep_alive():\n            self.keep_alive(True)\n\n        self.log_access(\n            message, environ, response.response, self._loop.time() - now)\n\n\nclass FileWrapper:\n    \"\"\"Custom file wrapper.\"\"\"\n\n    def __init__(self, fobj, chunk_size=8192):\n        self.fobj = fobj\n        self.chunk_size = chunk_size\n        if hasattr(fobj, 'close'):\n            self.close = fobj.close\n\n    def __iter__(self):\n        return self\n\n    def __next__(self):\n        data = self.fobj.read(self.chunk_size)\n        if data:\n            return data\n        raise StopIteration\n\n\nclass WsgiResponse:\n    \"\"\"Implementation of start_response() callable as specified by PEP 3333\"\"\"\n\n    status = None\n\n    HOP_HEADERS = {\n        hdrs.CONNECTION,\n        hdrs.KEEP_ALIVE,\n        hdrs.PROXY_AUTHENTICATE,\n        hdrs.PROXY_AUTHORIZATION,\n        hdrs.TE,\n        hdrs.TRAILER,\n        hdrs.TRANSFER_ENCODING,\n        hdrs.UPGRADE,\n    }\n\n    def __init__(self, writer, message):\n        self.writer = writer\n        self.message = message\n\n    def start_response(self, status, headers, exc_info=None):\n        if exc_info:\n            try:\n                if self.status:\n                    raise exc_info[1]\n            finally:\n                exc_info = None\n\n        status_code = int(status.split(' ', 1)[0])\n\n        self.status = status\n        resp = self.response = aiohttp.Response(\n            self.writer, status_code,\n            self.message.version, self.message.should_close)\n        resp.HOP_HEADERS = self.HOP_HEADERS\n        resp.add_headers(*headers)\n\n        if resp.has_chunked_hdr:\n            resp.enable_chunked_encoding()\n\n        # send headers immediately for websocket connection\n        if status_code == 101 and resp.upgrade and resp.websocket:\n            resp.send_headers()\n        else:\n            resp._send_headers = True\n        return self.response.write\n",
            "new_file_content": "\"\"\"wsgi server.\n\nTODO:\n  * proxy protocol\n  * x-forward security\n  * wsgi file support (os.sendfile)\n\"\"\"\n\nimport asyncio\nimport inspect\nimport io\nimport os\nimport sys\nfrom urllib.parse import urlsplit\n\nimport aiohttp\nfrom aiohttp import server, hdrs\n\n__all__ = ('WSGIServerHttpProtocol',)\n\n\nclass WSGIServerHttpProtocol(server.ServerHttpProtocol):\n    \"\"\"HTTP Server that implements the Python WSGI protocol.\n\n    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently\n    depends on 'readpayload' constructor parameter. If readpayload is set to\n    True, wsgi server reads all incoming data into BytesIO object and\n    sends it as 'wsgi.input' environ var. If readpayload is set to false\n    'wsgi.input' is a StreamReader and application should read incoming\n    data with \"yield from environ['wsgi.input'].read()\". It defaults to False.\n    \"\"\"\n\n    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')\n\n    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):\n        super().__init__(*args, **kw)\n\n        self.wsgi = app\n        self.is_ssl = is_ssl\n        self.readpayload = readpayload\n\n    def create_wsgi_response(self, message):\n        return WsgiResponse(self.writer, message)\n\n    def create_wsgi_environ(self, message, payload):\n        uri_parts = urlsplit(message.path)\n        url_scheme = 'https' if self.is_ssl else 'http'\n\n        environ = {\n            'wsgi.input': payload,\n            'wsgi.errors': sys.stderr,\n            'wsgi.version': (1, 0),\n            'wsgi.async': True,\n            'wsgi.multithread': False,\n            'wsgi.multiprocess': False,\n            'wsgi.run_once': False,\n            'wsgi.file_wrapper': FileWrapper,\n            'wsgi.url_scheme': url_scheme,\n            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,\n            'REQUEST_METHOD': message.method,\n            'QUERY_STRING': uri_parts.query or '',\n            'RAW_URI': message.path,\n            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version\n        }\n\n        script_name = self.SCRIPT_NAME\n\n        for hdr_name, hdr_value in message.headers.items():\n            if hdr_name == 'AUTHORIZATION':\n                continue\n            elif hdr_name == 'SCRIPT_NAME':\n                script_name = hdr_value\n            elif hdr_name == 'CONTENT-TYPE':\n                environ['CONTENT_TYPE'] = hdr_value\n                continue\n            elif hdr_name == 'CONTENT-LENGTH':\n                environ['CONTENT_LENGTH'] = hdr_value\n                continue\n\n            key = 'HTTP_%s' % hdr_name.replace('-', '_')\n            if key in environ:\n                hdr_value = '%s,%s' % (environ[key], hdr_value)\n\n            environ[key] = hdr_value\n\n        # authors should be aware that REMOTE_HOST and REMOTE_ADDR\n        # may not qualify the remote addr\n        # also SERVER_PORT variable MUST be set to the TCP/IP port number on\n        # which this request is received from the client.\n        # http://www.ietf.org/rfc/rfc3875\n\n        remote = self.transport.get_extra_info('peername')\n        environ['REMOTE_ADDR'] = remote[0]\n        environ['REMOTE_PORT'] = remote[1]\n\n        sockname = self.transport.get_extra_info('sockname')\n        environ['SERVER_PORT'] = str(sockname[1])\n        host = message.headers.get(\"HOST\", None)\n        if host:\n            environ['SERVER_NAME'] = host.split(\":\")[0]\n        else:\n            environ['SERVER_NAME'] = sockname[0]\n\n        path_info = uri_parts.path\n        if script_name:\n            path_info = path_info.split(script_name, 1)[-1]\n\n        environ['PATH_INFO'] = path_info\n        environ['SCRIPT_NAME'] = script_name\n\n        environ['async.reader'] = self.reader\n        environ['async.writer'] = self.writer\n\n        return environ\n\n    @asyncio.coroutine\n    def handle_request(self, message, payload):\n        \"\"\"Handle a single HTTP request\"\"\"\n        now = self._loop.time()\n\n        if self.readpayload:\n            wsgiinput = io.BytesIO()\n            wsgiinput.write((yield from payload.read()))\n            wsgiinput.seek(0)\n            payload = wsgiinput\n\n        environ = self.create_wsgi_environ(message, payload)\n        response = self.create_wsgi_response(message)\n\n        riter = self.wsgi(environ, response.start_response)\n        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):\n            riter = yield from riter\n\n        resp = response.response\n        try:\n            for item in riter:\n                if isinstance(item, asyncio.Future):\n                    item = yield from item\n                yield from resp.write(item)\n\n            yield from resp.write_eof()\n        finally:\n            if hasattr(riter, 'close'):\n                riter.close()\n\n        if resp.keep_alive():\n            self.keep_alive(True)\n\n        self.log_access(\n            message, environ, response.response, self._loop.time() - now)\n\n\nclass FileWrapper:\n    \"\"\"Custom file wrapper.\"\"\"\n\n    def __init__(self, fobj, chunk_size=8192):\n        self.fobj = fobj\n        self.chunk_size = chunk_size\n        if hasattr(fobj, 'close'):\n            self.close = fobj.close\n\n    def __iter__(self):\n        return self\n\n    def __next__(self):\n        data = self.fobj.read(self.chunk_size)\n        if data:\n            return data\n        raise StopIteration\n\n\nclass WsgiResponse:\n    \"\"\"Implementation of start_response() callable as specified by PEP 3333\"\"\"\n\n    status = None\n\n    HOP_HEADERS = {\n        hdrs.CONNECTION,\n        hdrs.KEEP_ALIVE,\n        hdrs.PROXY_AUTHENTICATE,\n        hdrs.PROXY_AUTHORIZATION,\n        hdrs.TE,\n        hdrs.TRAILER,\n        hdrs.TRANSFER_ENCODING,\n        hdrs.UPGRADE,\n    }\n\n    def __init__(self, writer, message):\n        self.writer = writer\n        self.message = message\n\n    def start_response(self, status, headers, exc_info=None):\n        if exc_info:\n            try:\n                if self.status:\n                    raise exc_info[1]\n            finally:\n                exc_info = None\n\n        status_code = int(status.split(' ', 1)[0])\n\n        self.status = status\n        resp = self.response = aiohttp.Response(\n            self.writer, status_code,\n            self.message.version, self.message.should_close)\n        resp.HOP_HEADERS = self.HOP_HEADERS\n        resp.add_headers(*headers)\n\n        if resp.has_chunked_hdr:\n            resp.enable_chunked_encoding()\n\n        # send headers immediately for websocket connection\n        if status_code == 101 and resp.upgrade and resp.websocket:\n            resp.send_headers()\n        else:\n            resp._send_headers = True\n        return self.response.write\n",
            "header": {
                "file": {
                    "path": "aiohttp/wsgi.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "bd950d2f",
                "new_commit_hash": "7f172d32",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/aiohttp/wsgi.py"
            },
            "plus_file": {
                "path": "b/aiohttp/wsgi.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 83,
                            "length": 16
                        },
                        "new_range": {
                            "start": 83,
                            "length": 23
                        },
                        "section": "class WSGIServerHttpProtocol(server.ServerHttpProtocol):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "            environ[key] = hdr_value",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        # authors should be aware that REMOTE_HOST and REMOTE_ADDR",
                                "type": "added"
                            },
                            {
                                "content": "        # may not qualify the remote addr",
                                "type": "added"
                            },
                            {
                                "content": "        # also SERVER_PORT variable MUST be set to the TCP/IP port number on",
                                "type": "added"
                            },
                            {
                                "content": "        # which this request is received from the client.",
                                "type": "added"
                            },
                            {
                                "content": "        # http://www.ietf.org/rfc/rfc3875",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        remote = self.transport.get_extra_info('peername')",
                                "type": "context"
                            },
                            {
                                "content": "        environ['REMOTE_ADDR'] = remote[0]",
                                "type": "context"
                            },
                            {
                                "content": "        environ['REMOTE_PORT'] = remote[1]",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        sockname = self.transport.get_extra_info('sockname')",
                                "type": "added"
                            },
                            {
                                "content": "        environ['SERVER_PORT'] = str(sockname[1])",
                                "type": "added"
                            },
                            {
                                "content": "        host = message.headers.get(\"HOST\", None)",
                                "type": "context"
                            },
                            {
                                "content": "        if host:",
                                "type": "context"
                            },
                            {
                                "content": "            host = host.split(\":\")",
                                "type": "deleted"
                            },
                            {
                                "content": "            environ['SERVER_NAME'] = host.split(\":\")[0]",
                                "type": "added"
                            },
                            {
                                "content": "        else:",
                                "type": "context"
                            },
                            {
                                "content": "            host = self.transport.get_extra_info('sockname')",
                                "type": "deleted"
                            },
                            {
                                "content": "        environ['SERVER_NAME'] = host[0]",
                                "type": "deleted"
                            },
                            {
                                "content": "        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'",
                                "type": "deleted"
                            },
                            {
                                "content": "            environ['SERVER_NAME'] = sockname[0]",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        path_info = uri_parts.path",
                                "type": "context"
                            },
                            {
                                "content": "        if script_name:",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "aiohttp/wsgi.py",
                            "type": "method",
                            "name": "WSGIServerHttpProtocol.create_wsgi_environ",
                            "content": "class WSGIServerHttpProtocol(server.ServerHttpProtocol):\n    \"\"\"HTTP Server that implements the Python WSGI protocol.\n\n    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently\n    depends on 'readpayload' constructor parameter. If readpayload is set to\n    True, wsgi server reads all incoming data into BytesIO object and\n    sends it as 'wsgi.input' environ var. If readpayload is set to false\n    'wsgi.input' is a StreamReader and application should read incoming\n    data with \"yield from environ['wsgi.input'].read()\". It defaults to False.\n    \"\"\"\n\n    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')\n\n    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):\n        super().__init__(*args, **kw)\n\n        self.wsgi = app\n        self.is_ssl = is_ssl\n        self.readpayload = readpayload\n\n    def create_wsgi_response(self, message):\n        return WsgiResponse(self.writer, message)\n\n    def create_wsgi_environ(self, message, payload):\n        uri_parts = urlsplit(message.path)\n        url_scheme = 'https' if self.is_ssl else 'http'\n\n        environ = {\n            'wsgi.input': payload,\n            'wsgi.errors': sys.stderr,\n            'wsgi.version': (1, 0),\n            'wsgi.async': True,\n            'wsgi.multithread': False,\n            'wsgi.multiprocess': False,\n            'wsgi.run_once': False,\n            'wsgi.file_wrapper': FileWrapper,\n            'wsgi.url_scheme': url_scheme,\n            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,\n            'REQUEST_METHOD': message.method,\n            'QUERY_STRING': uri_parts.query or '',\n            'RAW_URI': message.path,\n            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version\n        }\n\n        script_name = self.SCRIPT_NAME\n\n        for hdr_name, hdr_value in message.headers.items():\n            if hdr_name == 'AUTHORIZATION':\n                continue\n            elif hdr_name == 'SCRIPT_NAME':\n                script_name = hdr_value\n            elif hdr_name == 'CONTENT-TYPE':\n                environ['CONTENT_TYPE'] = hdr_value\n                continue\n            elif hdr_name == 'CONTENT-LENGTH':\n                environ['CONTENT_LENGTH'] = hdr_value\n                continue\n\n            key = 'HTTP_%s' % hdr_name.replace('-', '_')\n            if key in environ:\n                hdr_value = '%s,%s' % (environ[key], hdr_value)\n\n            environ[key] = hdr_value\n\n        remote = self.transport.get_extra_info('peername')\n        environ['REMOTE_ADDR'] = remote[0]\n        environ['REMOTE_PORT'] = remote[1]\n        host = message.headers.get(\"HOST\", None)\n        if host:\n            host = host.split(\":\")\n        else:\n            host = self.transport.get_extra_info('sockname')\n        environ['SERVER_NAME'] = host[0]\n        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'\n\n        path_info = uri_parts.path\n        if script_name:\n            path_info = path_info.split(script_name, 1)[-1]\n\n        environ['PATH_INFO'] = path_info\n        environ['SCRIPT_NAME'] = script_name\n\n        environ['async.reader'] = self.reader\n        environ['async.writer'] = self.writer\n\n        return environ\n\n    @asyncio.coroutine\n    def handle_request(self, message, payload):\n        \"\"\"Handle a single HTTP request\"\"\"\n        now = self._loop.time()\n\n        if self.readpayload:\n            wsgiinput = io.BytesIO()\n            wsgiinput.write((yield from payload.read()))\n            wsgiinput.seek(0)\n            payload = wsgiinput\n\n        environ = self.create_wsgi_environ(message, payload)\n        response = self.create_wsgi_response(message)\n\n        riter = self.wsgi(environ, response.start_response)\n        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):\n            riter = yield from riter\n\n        resp = response.response\n        try:\n            for item in riter:\n                if isinstance(item, asyncio.Future):\n                    item = yield from item\n                yield from resp.write(item)\n\n            yield from resp.write_eof()\n        finally:\n            if hasattr(riter, 'close'):\n                riter.close()\n\n        if resp.keep_alive():\n            self.keep_alive(True)\n\n        self.log_access(\n            message, environ, response.response, self._loop.time() - now)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 45,
                            "end_lineno": 107,
                            "parent": {
                                "file_name": "aiohttp/wsgi.py",
                                "type": "class",
                                "name": "WSGIServerHttpProtocol",
                                "content": "class WSGIServerHttpProtocol(server.ServerHttpProtocol):\n    \"\"\"HTTP Server that implements the Python WSGI protocol.\n\n    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently\n    depends on 'readpayload' constructor parameter. If readpayload is set to\n    True, wsgi server reads all incoming data into BytesIO object and\n    sends it as 'wsgi.input' environ var. If readpayload is set to false\n    'wsgi.input' is a StreamReader and application should read incoming\n    data with \"yield from environ['wsgi.input'].read()\". It defaults to False.\n    \"\"\"\n\n    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')\n\n    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):\n        super().__init__(*args, **kw)\n\n        self.wsgi = app\n        self.is_ssl = is_ssl\n        self.readpayload = readpayload\n\n    def create_wsgi_response(self, message):\n        return WsgiResponse(self.writer, message)\n\n    def create_wsgi_environ(self, message, payload):\n        uri_parts = urlsplit(message.path)\n        url_scheme = 'https' if self.is_ssl else 'http'\n\n        environ = {\n            'wsgi.input': payload,\n            'wsgi.errors': sys.stderr,\n            'wsgi.version': (1, 0),\n            'wsgi.async': True,\n            'wsgi.multithread': False,\n            'wsgi.multiprocess': False,\n            'wsgi.run_once': False,\n            'wsgi.file_wrapper': FileWrapper,\n            'wsgi.url_scheme': url_scheme,\n            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,\n            'REQUEST_METHOD': message.method,\n            'QUERY_STRING': uri_parts.query or '',\n            'RAW_URI': message.path,\n            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version\n        }\n\n        script_name = self.SCRIPT_NAME\n\n        for hdr_name, hdr_value in message.headers.items():\n            if hdr_name == 'AUTHORIZATION':\n                continue\n            elif hdr_name == 'SCRIPT_NAME':\n                script_name = hdr_value\n            elif hdr_name == 'CONTENT-TYPE':\n                environ['CONTENT_TYPE'] = hdr_value\n                continue\n            elif hdr_name == 'CONTENT-LENGTH':\n                environ['CONTENT_LENGTH'] = hdr_value\n                continue\n\n            key = 'HTTP_%s' % hdr_name.replace('-', '_')\n            if key in environ:\n                hdr_value = '%s,%s' % (environ[key], hdr_value)\n\n            environ[key] = hdr_value\n\n        remote = self.transport.get_extra_info('peername')\n        environ['REMOTE_ADDR'] = remote[0]\n        environ['REMOTE_PORT'] = remote[1]\n        host = message.headers.get(\"HOST\", None)\n        if host:\n            host = host.split(\":\")\n        else:\n            host = self.transport.get_extra_info('sockname')\n        environ['SERVER_NAME'] = host[0]\n        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'\n\n        path_info = uri_parts.path\n        if script_name:\n            path_info = path_info.split(script_name, 1)[-1]\n\n        environ['PATH_INFO'] = path_info\n        environ['SCRIPT_NAME'] = script_name\n\n        environ['async.reader'] = self.reader\n        environ['async.writer'] = self.writer\n\n        return environ\n\n    @asyncio.coroutine\n    def handle_request(self, message, payload):\n        \"\"\"Handle a single HTTP request\"\"\"\n        now = self._loop.time()\n\n        if self.readpayload:\n            wsgiinput = io.BytesIO()\n            wsgiinput.write((yield from payload.read()))\n            wsgiinput.seek(0)\n            payload = wsgiinput\n\n        environ = self.create_wsgi_environ(message, payload)\n        response = self.create_wsgi_response(message)\n\n        riter = self.wsgi(environ, response.start_response)\n        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):\n            riter = yield from riter\n\n        resp = response.response\n        try:\n            for item in riter:\n                if isinstance(item, asyncio.Future):\n                    item = yield from item\n                yield from resp.write(item)\n\n            yield from resp.write_eof()\n        finally:\n            if hasattr(riter, 'close'):\n                riter.close()\n\n        if resp.keep_alive():\n            self.keep_alive(True)\n\n        self.log_access(\n            message, environ, response.response, self._loop.time() - now)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 22,
                                "end_lineno": 143,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "aiohttp/wsgi.py",
                            "type": "class",
                            "name": "WSGIServerHttpProtocol",
                            "content": "class WSGIServerHttpProtocol(server.ServerHttpProtocol):\n    \"\"\"HTTP Server that implements the Python WSGI protocol.\n\n    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently\n    depends on 'readpayload' constructor parameter. If readpayload is set to\n    True, wsgi server reads all incoming data into BytesIO object and\n    sends it as 'wsgi.input' environ var. If readpayload is set to false\n    'wsgi.input' is a StreamReader and application should read incoming\n    data with \"yield from environ['wsgi.input'].read()\". It defaults to False.\n    \"\"\"\n\n    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')\n\n    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):\n        super().__init__(*args, **kw)\n\n        self.wsgi = app\n        self.is_ssl = is_ssl\n        self.readpayload = readpayload\n\n    def create_wsgi_response(self, message):\n        return WsgiResponse(self.writer, message)\n\n    def create_wsgi_environ(self, message, payload):\n        uri_parts = urlsplit(message.path)\n        url_scheme = 'https' if self.is_ssl else 'http'\n\n        environ = {\n            'wsgi.input': payload,\n            'wsgi.errors': sys.stderr,\n            'wsgi.version': (1, 0),\n            'wsgi.async': True,\n            'wsgi.multithread': False,\n            'wsgi.multiprocess': False,\n            'wsgi.run_once': False,\n            'wsgi.file_wrapper': FileWrapper,\n            'wsgi.url_scheme': url_scheme,\n            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,\n            'REQUEST_METHOD': message.method,\n            'QUERY_STRING': uri_parts.query or '',\n            'RAW_URI': message.path,\n            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version\n        }\n\n        script_name = self.SCRIPT_NAME\n\n        for hdr_name, hdr_value in message.headers.items():\n            if hdr_name == 'AUTHORIZATION':\n                continue\n            elif hdr_name == 'SCRIPT_NAME':\n                script_name = hdr_value\n            elif hdr_name == 'CONTENT-TYPE':\n                environ['CONTENT_TYPE'] = hdr_value\n                continue\n            elif hdr_name == 'CONTENT-LENGTH':\n                environ['CONTENT_LENGTH'] = hdr_value\n                continue\n\n            key = 'HTTP_%s' % hdr_name.replace('-', '_')\n            if key in environ:\n                hdr_value = '%s,%s' % (environ[key], hdr_value)\n\n            environ[key] = hdr_value\n\n        remote = self.transport.get_extra_info('peername')\n        environ['REMOTE_ADDR'] = remote[0]\n        environ['REMOTE_PORT'] = remote[1]\n        host = message.headers.get(\"HOST\", None)\n        if host:\n            host = host.split(\":\")\n        else:\n            host = self.transport.get_extra_info('sockname')\n        environ['SERVER_NAME'] = host[0]\n        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'\n\n        path_info = uri_parts.path\n        if script_name:\n            path_info = path_info.split(script_name, 1)[-1]\n\n        environ['PATH_INFO'] = path_info\n        environ['SCRIPT_NAME'] = script_name\n\n        environ['async.reader'] = self.reader\n        environ['async.writer'] = self.writer\n\n        return environ\n\n    @asyncio.coroutine\n    def handle_request(self, message, payload):\n        \"\"\"Handle a single HTTP request\"\"\"\n        now = self._loop.time()\n\n        if self.readpayload:\n            wsgiinput = io.BytesIO()\n            wsgiinput.write((yield from payload.read()))\n            wsgiinput.seek(0)\n            payload = wsgiinput\n\n        environ = self.create_wsgi_environ(message, payload)\n        response = self.create_wsgi_response(message)\n\n        riter = self.wsgi(environ, response.start_response)\n        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):\n            riter = yield from riter\n\n        resp = response.response\n        try:\n            for item in riter:\n                if isinstance(item, asyncio.Future):\n                    item = yield from item\n                yield from resp.write(item)\n\n            yield from resp.write_eof()\n        finally:\n            if hasattr(riter, 'close'):\n                riter.close()\n\n        if resp.keep_alive():\n            self.keep_alive(True)\n\n        self.log_access(\n            message, environ, response.response, self._loop.time() - now)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 22,
                            "end_lineno": 143,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "\"\"\"Tests for http/wsgi.py\"\"\"\n\nimport io\nimport asyncio\nimport unittest\nimport unittest.mock\n\nimport aiohttp\nfrom aiohttp import multidict\nfrom aiohttp import wsgi\nfrom aiohttp import protocol\n\n\nclass TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')\n",
            "new_file_content": "\"\"\"Tests for http/wsgi.py\"\"\"\n\nimport io\nimport asyncio\nimport unittest\nimport unittest.mock\n\nimport aiohttp\nfrom aiohttp import multidict\nfrom aiohttp import wsgi\nfrom aiohttp import protocol\n\n\nclass TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),\n                                                     ('2.3.4.5', 80)]\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n        self.assertEqual(expected_calls, get_extra_info_calls)\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n",
            "header": {
                "file": {
                    "path": "tests/test_wsgi.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "1d2ad4c5",
                "new_commit_hash": "c2e95ad9",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/tests/test_wsgi.py"
            },
            "plus_file": {
                "path": "b/tests/test_wsgi.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 22,
                            "length": 7
                        },
                        "new_range": {
                            "start": 22,
                            "length": 8
                        },
                        "section": "class TestHttpWsgiServerProtocol(unittest.TestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self.writer = unittest.mock.Mock()",
                                "type": "context"
                            },
                            {
                                "content": "        self.writer.drain.return_value = ()",
                                "type": "context"
                            },
                            {
                                "content": "        self.transport = unittest.mock.Mock()",
                                "type": "context"
                            },
                            {
                                "content": "        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),",
                                "type": "added"
                            },
                            {
                                "content": "                                                     ('2.3.4.5', 80)]",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})",
                                "type": "context"
                            },
                            {
                                "content": "        self.message = protocol.RawRequestMessage(",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "class",
                            "name": "TestHttpWsgiServerProtocol",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 14,
                            "end_lineno": 273,
                            "parent": null
                        },
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.setUp",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 16,
                            "end_lineno": 33,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 273,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 68,
                            "length": 32
                        },
                        "new_range": {
                            "start": 69,
                            "length": 35
                        },
                        "section": "class TestHttpWsgiServerProtocol(unittest.TestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "             ('CONTENT-LENGTH', '209'),",
                                "type": "context"
                            },
                            {
                                "content": "             ('X_TEST', '123'),",
                                "type": "context"
                            },
                            {
                                "content": "             ('X_TEST', '456')))",
                                "type": "context"
                            },
                            {
                                "content": "        environ = self._make_one(is_ssl=True)",
                                "type": "deleted"
                            },
                            {
                                "content": "        environ = self._make_one()",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['CONTENT_LENGTH'], '209')",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['HTTP_X_TEST'], '123,456')",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['SCRIPT_NAME'], 'script')",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_NAME'], 'python.org')",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PORT'], '80')",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "deleted"
                            },
                            {
                                "content": "    def test_environ_host_header(self):",
                                "type": "deleted"
                            },
                            {
                                "content": "        environ = self._make_one()",
                                "type": "deleted"
                            },
                            {
                                "content": "",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['HTTP_HOST'], 'python.org')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_NAME'], 'python.org')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PORT'], '80')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')",
                                "type": "deleted"
                            },
                            {
                                "content": "",
                                "type": "deleted"
                            },
                            {
                                "content": "    def test_environ_host_port_header(self):",
                                "type": "deleted"
                            },
                            {
                                "content": "        headers = multidict.MultiDict({'HOST': 'python.org:443'})",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.message = protocol.RawRequestMessage(",
                                "type": "deleted"
                            },
                            {
                                "content": "            'GET', '/path', (1, 1), headers, True, 'deflate')",
                                "type": "deleted"
                            },
                            {
                                "content": "        get_extra_info_calls = self.transport.get_extra_info.mock_calls",
                                "type": "added"
                            },
                            {
                                "content": "        expected_calls = [",
                                "type": "added"
                            },
                            {
                                "content": "            unittest.mock.call('peername'),",
                                "type": "added"
                            },
                            {
                                "content": "            unittest.mock.call('sockname'),",
                                "type": "added"
                            },
                            {
                                "content": "        ]",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertEqual(expected_calls, get_extra_info_calls)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def test_environ_host_header_alternate_port(self):",
                                "type": "added"
                            },
                            {
                                "content": "        self.transport.get_extra_info = unittest.mock.Mock(",
                                "type": "added"
                            },
                            {
                                "content": "            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]",
                                "type": "added"
                            },
                            {
                                "content": "        )",
                                "type": "added"
                            },
                            {
                                "content": "        self.headers.update({'HOST': 'example.com:9999'})",
                                "type": "added"
                            },
                            {
                                "content": "        environ = self._make_one()",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PORT'], '82')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_NAME'], 'python.org')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PORT'], '443')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')",
                                "type": "deleted"
                            },
                            {
                                "content": "    def test_environ_host_header_alternate_port_ssl(self):",
                                "type": "added"
                            },
                            {
                                "content": "        self.transport.get_extra_info = unittest.mock.Mock(",
                                "type": "added"
                            },
                            {
                                "content": "            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]",
                                "type": "added"
                            },
                            {
                                "content": "        )",
                                "type": "added"
                            },
                            {
                                "content": "        self.headers.update({'HOST': 'example.com:9999'})",
                                "type": "added"
                            },
                            {
                                "content": "        environ = self._make_one(is_ssl=True)",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PORT'], '82')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_wsgi_response(self):",
                                "type": "context"
                            },
                            {
                                "content": "        srv = self._make_srv()",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "class",
                            "name": "TestHttpWsgiServerProtocol",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 14,
                            "end_lineno": 273,
                            "parent": null
                        },
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.test_environ_headers",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 64,
                            "end_lineno": 77,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 273,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.test_environ_host_header_alternate_port",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),\n                                                     ('2.3.4.5', 80)]\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n        self.assertEqual(expected_calls, get_extra_info_calls)\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')\n        self.assertEqual(environ['SERVER_PORT'], '80')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 86,
                            "end_lineno": 92,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),\n                                                     ('2.3.4.5', 80)]\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n        self.assertEqual(expected_calls, get_extra_info_calls)\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')\n        self.assertEqual(environ['SERVER_PORT'], '80')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 276,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.test_environ_host_header_alternate_port_ssl",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),\n                                                     ('2.3.4.5', 80)]\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n        self.assertEqual(expected_calls, get_extra_info_calls)\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')\n        self.assertEqual(environ['SERVER_PORT'], '80')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 94,
                            "end_lineno": 100,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),\n                                                     ('2.3.4.5', 80)]\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n        self.assertEqual(expected_calls, get_extra_info_calls)\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')\n        self.assertEqual(environ['SERVER_PORT'], '80')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 276,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": [
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.test_environ_host_port_header",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 87,
                            "end_lineno": 96,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 273,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.test_environ_host_header",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 79,
                            "end_lineno": 85,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 273,
                                "parent": null
                            }
                        }
                    ]
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 268,
                            "length": 6
                        },
                        "new_range": {
                            "start": 272,
                            "length": 5
                        },
                        "section": "class TestHttpWsgiServerProtocol(unittest.TestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self.message = protocol.RawRequestMessage(",
                                "type": "context"
                            },
                            {
                                "content": "            'GET', '/', (1, 0), headers, True, 'deflate')",
                                "type": "context"
                            },
                            {
                                "content": "        environ = self._make_one()",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual('8080', environ['SERVER_PORT'])",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.transport.get_extra_info.assert_called_with('sockname')",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertEqual(environ['SERVER_PORT'], '80')",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "method",
                            "name": "TestHttpWsgiServerProtocol.test_http_1_0_no_host",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 266,
                            "end_lineno": 273,
                            "parent": {
                                "file_name": "tests/test_wsgi.py",
                                "type": "class",
                                "name": "TestHttpWsgiServerProtocol",
                                "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 14,
                                "end_lineno": 273,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "tests/test_wsgi.py",
                            "type": "class",
                            "name": "TestHttpWsgiServerProtocol",
                            "content": "class TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.return_value = ('1.2.3.4', 8080)\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n\n    def test_environ_host_header(self):\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.0')\n\n    def test_environ_host_port_header(self):\n        headers = multidict.MultiDict({'HOST': 'python.org:443'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), headers, True, 'deflate')\n        environ = self._make_one()\n\n        self.assertEqual(environ['HTTP_HOST'], 'python.org:443')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '443')\n        self.assertEqual(environ['SERVER_PROTOCOL'], 'HTTP/1.1')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('1.2.3.4', environ['SERVER_NAME'])\n        self.assertEqual('8080', environ['SERVER_PORT'])\n        self.transport.get_extra_info.assert_called_with('sockname')",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 14,
                            "end_lineno": 273,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "eb54e6c010f55c02e49a36cb2e74b077f8aa77e4^",
    "new_commit_hash": "eb54e6c010f55c02e49a36cb2e74b077f8aa77e4",
    "commit_message": "Fix SERVER_PORT in wsgi headers\n\nAccording to CGI 1.1 server port should be set to the TCP/IP port\nnumber on which this request is received from the client.\n\nAlso add comment about REMOTE_HOST, REMOTE_ADDR and SERVER_PORT.\n\nAlso added new and removed some redundant tests.",
    "commit_date": "2015-10-21T01:47:27+03:00",
    "metadata": {}
}
{
    "repo_name": "aiohttp",
    "new_commit_hash": "eb54e6c010f55c02e49a36cb2e74b077f8aa77e4",
    "test_file_codes": [
        "\"\"\"Tests for http/wsgi.py\"\"\"\n\nimport io\nimport asyncio\nimport unittest\nimport unittest.mock\n\nimport aiohttp\nfrom aiohttp import multidict\nfrom aiohttp import wsgi\nfrom aiohttp import protocol\n\n\nclass TestHttpWsgiServerProtocol(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.wsgi = unittest.mock.Mock()\n        self.reader = unittest.mock.Mock()\n        self.writer = unittest.mock.Mock()\n        self.writer.drain.return_value = ()\n        self.transport = unittest.mock.Mock()\n        self.transport.get_extra_info.side_effect = [('1.2.3.4', 1234),\n                                                     ('2.3.4.5', 80)]\n\n        self.headers = multidict.MultiDict({\"HOST\": \"python.org\"})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 0), self.headers, True, 'deflate')\n        self.payload = aiohttp.FlowControlDataQueue(self.reader)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_data(b'data', 4)\n        self.payload.feed_eof()\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_ctor(self):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop)\n        self.assertIs(srv.wsgi, self.wsgi)\n        self.assertFalse(srv.readpayload)\n\n    def _make_one(self, **kw):\n        srv = wsgi.WSGIServerHttpProtocol(self.wsgi, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv.create_wsgi_environ(self.message, self.payload)\n\n    def _make_srv(self, app=None, **kw):\n        if app is None:\n            app = self.wsgi\n        srv = wsgi.WSGIServerHttpProtocol(app, loop=self.loop, **kw)\n        srv.reader = self.reader\n        srv.writer = self.writer\n        srv.transport = self.transport\n        return srv\n\n    def test_environ(self):\n        environ = self._make_one()\n        self.assertEqual(environ['RAW_URI'], '/path')\n        self.assertEqual(environ['wsgi.async'], True)\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n        self.assertEqual(expected_calls, get_extra_info_calls)\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n        self.assertEqual(environ['SERVER_PORT'], '82')\n\n    def test_wsgi_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        self.assertIsInstance(resp, wsgi.WsgiResponse)\n\n    def test_wsgi_response_start_response(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '200 OK', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n        self.assertEqual(resp.status, '200 OK')\n        self.assertIsInstance(resp.response, protocol.Response)\n\n    def test_wsgi_response_start_response_exc_status(self):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response('200 OK', [('CONTENT-TYPE', 'text/plain')])\n\n        self.assertRaises(\n            ValueError,\n            resp.start_response,\n            '500 Err', [('CONTENT-TYPE', 'text/plain')], ['', ValueError()])\n\n    @unittest.mock.patch('aiohttp.wsgi.aiohttp')\n    def test_wsgi_response_101_upgrade_to_websocket(self, m_asyncio):\n        srv = self._make_srv()\n        resp = srv.create_wsgi_response(self.message)\n        resp.start_response(\n            '101 Switching Protocols', (('UPGRADE', 'websocket'),\n                                        ('CONNECTION', 'upgrade')))\n        self.assertEqual(resp.status, '101 Switching Protocols')\n        self.assertTrue(m_asyncio.Response.return_value.send_headers.called)\n\n    def test_file_wrapper(self):\n        fobj = io.BytesIO(b'data')\n        wrapper = wsgi.FileWrapper(fobj, 2)\n        self.assertIs(wrapper, iter(wrapper))\n        self.assertTrue(hasattr(wrapper, 'close'))\n\n        self.assertEqual(next(wrapper), b'da')\n        self.assertEqual(next(wrapper), b'ta')\n        self.assertRaises(StopIteration, next, wrapper)\n\n        wrapper = wsgi.FileWrapper(b'data', 2)\n        self.assertFalse(hasattr(wrapper, 'close'))\n\n    def test_handle_request_futures(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            f1 = asyncio.Future(loop=self.loop)\n            f1.set_result(b'data')\n            fut = asyncio.Future(loop=self.loop)\n            fut.set_result([f1])\n            return fut\n\n        srv = self._make_srv(wsgi_app)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_simple(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, True, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertFalse(srv._keep_alive)\n\n    def test_handle_request_io(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return io.BytesIO(b'data')\n\n        srv = self._make_srv(wsgi_app)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_handle_request_keep_alive(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [b'data']\n\n        stream = asyncio.StreamReader(loop=self.loop)\n        stream.feed_data(b'data')\n        stream.feed_eof()\n\n        self.message = protocol.RawRequestMessage(\n            'GET', '/path', (1, 1), self.headers, False, 'deflate')\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.1 200 OK'))\n        self.assertTrue(content.endswith(b'data\\r\\n0\\r\\n\\r\\n'))\n        self.assertTrue(srv._keep_alive)\n\n    def test_handle_request_readpayload(self):\n\n        def wsgi_app(env, start):\n            start('200 OK', [('Content-Type', 'text/plain')])\n            return [env['wsgi.input'].read()]\n\n        srv = self._make_srv(wsgi_app, readpayload=True)\n\n        self.loop.run_until_complete(\n            srv.handle_request(self.message, self.payload))\n\n        content = b''.join(\n            [c[1][0] for c in self.writer.write.mock_calls])\n        self.assertTrue(content.startswith(b'HTTP/1.0 200 OK'))\n        self.assertTrue(content.endswith(b'data'))\n\n    def test_dont_unquote_environ_path_info(self):\n        path = '/path/some%20text'\n        self.message = protocol.RawRequestMessage(\n            'GET', path, (1, 0), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['PATH_INFO'], path)\n\n    def test_not_add_authorization(self):\n        self.headers.extend({'AUTHORIZATION': 'spam',\n                             'X-CUSTOM-HEADER': 'eggs'})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 1), self.headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual('eggs', environ['HTTP_X_CUSTOM_HEADER'])\n        self.assertFalse('AUTHORIZATION' in environ)\n\n    def test_http_1_0_no_host(self):\n        headers = multidict.MultiDict({})\n        self.message = protocol.RawRequestMessage(\n            'GET', '/', (1, 0), headers, True, 'deflate')\n        environ = self._make_one()\n        self.assertEqual(environ['SERVER_NAME'], '2.3.4.5')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n",
        "import asyncio\nimport aiohttp\nimport collections\nimport gc\nimport logging\nimport pytest\nimport re\nimport socket\nimport sys\nimport warnings\n\nfrom aiohttp import web\n\n\nclass _AssertWarnsContext:\n    \"\"\"A context manager used to implement TestCase.assertWarns* methods.\"\"\"\n\n    def __init__(self, expected, expected_regex=None):\n        self.expected = expected\n        if expected_regex is not None:\n            expected_regex = re.compile(expected_regex)\n        self.expected_regex = expected_regex\n        self.obj_name = None\n\n    def __enter__(self):\n        # The __warningregistry__'s need to be in a pristine state for tests\n        # to work properly.\n        for v in sys.modules.values():\n            if getattr(v, '__warningregistry__', None):\n                v.__warningregistry__ = {}\n        self.warnings_manager = warnings.catch_warnings(record=True)\n        self.warnings = self.warnings_manager.__enter__()\n        warnings.simplefilter(\"always\", self.expected)\n        return self\n\n    def __exit__(self, exc_type, exc_value, tb):\n        self.warnings_manager.__exit__(exc_type, exc_value, tb)\n        if exc_type is not None:\n            # let unexpected exceptions pass through\n            return\n        try:\n            exc_name = self.expected.__name__\n        except AttributeError:\n            exc_name = str(self.expected)\n        first_matching = None\n        for m in self.warnings:\n            w = m.message\n            if not isinstance(w, self.expected):\n                continue\n            if first_matching is None:\n                first_matching = w\n            if (self.expected_regex is not None and\n                    not self.expected_regex.search(str(w))):\n                continue\n            # store warning for later retrieval\n            self.warning = w\n            self.filename = m.filename\n            self.lineno = m.lineno\n            return\n        # Now we simply try to choose a helpful failure message\n        if first_matching is not None:\n            __tracebackhide__ = True\n            assert 0, '\"{}\" does not match \"{}\"'.format(\n                self.expected_regex.pattern, str(first_matching))\n        if self.obj_name:\n            __tracebackhide__ = True\n            assert 0, \"{} not triggered by {}\".format(exc_name,\n                                                      self.obj_name)\n        else:\n            __tracebackhide__ = True\n            assert 0, \"{} not triggered\".format(exc_name)\n\n\n_LoggingWatcher = collections.namedtuple(\"_LoggingWatcher\",\n                                         [\"records\", \"output\"])\n\n\nclass _CapturingHandler(logging.Handler):\n    \"\"\"\n    A logging handler capturing all (raw and formatted) logging output.\n    \"\"\"\n\n    def __init__(self):\n        logging.Handler.__init__(self)\n        self.watcher = _LoggingWatcher([], [])\n\n    def flush(self):\n        pass\n\n    def emit(self, record):\n        self.watcher.records.append(record)\n        msg = self.format(record)\n        self.watcher.output.append(msg)\n\n\nclass _AssertLogsContext:\n    \"\"\"A context manager used to implement TestCase.assertLogs().\"\"\"\n\n    LOGGING_FORMAT = \"%(levelname)s:%(name)s:%(message)s\"\n\n    def __init__(self, logger_name=None, level=None):\n        self.logger_name = logger_name\n        if level:\n            self.level = logging._nameToLevel.get(level, level)\n        else:\n            self.level = logging.INFO\n        self.msg = None\n\n    def __enter__(self):\n        if isinstance(self.logger_name, logging.Logger):\n            logger = self.logger = self.logger_name\n        else:\n            logger = self.logger = logging.getLogger(self.logger_name)\n        formatter = logging.Formatter(self.LOGGING_FORMAT)\n        handler = _CapturingHandler()\n        handler.setFormatter(formatter)\n        self.watcher = handler.watcher\n        self.old_handlers = logger.handlers[:]\n        self.old_level = logger.level\n        self.old_propagate = logger.propagate\n        logger.handlers = [handler]\n        logger.setLevel(self.level)\n        logger.propagate = False\n        return handler.watcher\n\n    def __exit__(self, exc_type, exc_value, tb):\n        self.logger.handlers = self.old_handlers\n        self.logger.propagate = self.old_propagate\n        self.logger.setLevel(self.old_level)\n        if exc_type is not None:\n            # let unexpected exceptions pass through\n            return False\n        if len(self.watcher.records) == 0:\n            __tracebackhide__ = True\n            assert 0, (\"no logs of level {} or higher triggered on {}\"\n                       .format(logging.getLevelName(self.level),\n                               self.logger.name))\n\n\n@pytest.yield_fixture\ndef warning():\n    yield _AssertWarnsContext\n\n\n@pytest.yield_fixture\ndef log():\n    yield _AssertLogsContext\n\n\n@pytest.fixture\ndef unused_port():\n    def f():\n        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:\n            s.bind(('127.0.0.1', 0))\n            return s.getsockname()[1]\n    return f\n\n\n@pytest.yield_fixture\ndef loop(request):\n    loop = asyncio.new_event_loop()\n    asyncio.set_event_loop(None)\n\n    yield loop\n\n    loop.stop()\n    loop.run_forever()\n    loop.close()\n    gc.collect()\n    asyncio.set_event_loop(None)\n\n\n@pytest.yield_fixture\ndef create_server(loop, unused_port):\n    app = handler = srv = None\n\n    @asyncio.coroutine\n    def create(*, debug=False, ssl_ctx=None):\n        nonlocal app, handler, srv\n        app = web.Application(loop=loop)\n        port = unused_port()\n        handler = app.make_handler(debug=debug, keep_alive_on=False)\n        srv = yield from loop.create_server(handler, '127.0.0.1', port,\n                                            ssl=ssl_ctx)\n        proto = \"https\" if ssl_ctx else \"http\"\n        url = \"{}://127.0.0.1:{}\".format(proto, port)\n        return app, url\n\n    yield create\n\n    @asyncio.coroutine\n    def finish():\n        yield from handler.finish_connections()\n        yield from app.finish()\n        srv.close()\n        yield from srv.wait_closed()\n\n    loop.run_until_complete(finish())\n\n\nclass Client:\n    def __init__(self, session, url):\n        self._session = session\n        if not url.endswith('/'):\n            url += '/'\n        self._url = url\n\n    def close(self):\n        self._session.close()\n\n    def get(self, path, **kwargs):\n        while path.startswith('/'):\n            path = path[1:]\n        url = self._url + path\n        return self._session.get(url, **kwargs)\n\n    def post(self, path, **kwargs):\n        while path.startswith('/'):\n            path = path[1:]\n        url = self._url + path\n        return self._session.post(url, **kwargs)\n\n\n@pytest.yield_fixture\ndef create_app_and_client(create_server, loop):\n    client = None\n\n    @asyncio.coroutine\n    def maker(*, server_params=None, client_params=None):\n        nonlocal client\n        if server_params is None:\n            server_params = {}\n        server_params.setdefault('debug', False)\n        server_params.setdefault('ssl_ctx', None)\n        app, url = yield from create_server(**server_params)\n        if client_params is None:\n            client_params = {}\n        client = Client(aiohttp.ClientSession(loop=loop, **client_params), url)\n        return app, client\n\n    yield maker\n    client.close()\n\n\n@pytest.mark.tryfirst\ndef pytest_pycollect_makeitem(collector, name, obj):\n    if collector.funcnamefilter(name):\n        if not callable(obj):\n            return\n        item = pytest.Function(name, parent=collector)\n        if 'run_loop' in item.keywords:\n            return list(collector._genfunctions(name, obj))\n\n\n@pytest.mark.tryfirst\ndef pytest_pyfunc_call(pyfuncitem):\n    \"\"\"\n    Run asyncio marked test functions in an event loop instead of a normal\n    function call.\n    \"\"\"\n    if 'run_loop' in pyfuncitem.keywords:\n        funcargs = pyfuncitem.funcargs\n        loop = funcargs['loop']\n        testargs = {arg: funcargs[arg]\n                    for arg in pyfuncitem._fixtureinfo.argnames}\n        loop.run_until_complete(pyfuncitem.obj(**testargs))\n        return True\n\n\ndef pytest_runtest_setup(item):\n    if 'run_loop' in item.keywords and 'loop' not in item.fixturenames:\n        # inject an event loop fixture for all async tests\n        item.fixturenames.append('loop')\n\n\ndef pytest_ignore_collect(path, config):\n    if 'test_py35' in str(path):\n        if sys.version_info < (3, 5, 0):\n            return True\n"
    ],
    "test_file_names": [
        "test_1.py",
        "conftest.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "uv pip install -U -r requirements-dev.txt\nTransforming aiohttp/worker.py\nTransforming aiohttp/client_reqrep.py\nTransforming aiohttp/server.py\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 68 packages in 839ms\n  × Failed to build `aiohttp @ file:///home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_eb54e6c010f55c02e49a36cb2e74b077f8aa77e4`\n  ├─▶ The build backend returned an error\n  ╰─▶ Call to `setuptools.build_meta:__legacy__.build_editable` failed (exit status: 1)\n\n      [stdout]\n      running editable_wheel\n      creating /home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info\n      writing /home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/PKG-INFO\n      writing dependency_links to /home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/dependency_links.txt\n      writing requirements to /home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/requires.txt\n      writing top-level names to /home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/top_level.txt\n      writing manifest file '/home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/SOURCES.txt'\n      reading manifest file '/home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/SOURCES.txt'\n      reading manifest template 'MANIFEST.in'\n      adding license file 'LICENSE.txt'\n      writing manifest file '/home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info/SOURCES.txt'\n      creating '/home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp-0.18.0a0.dist-info'\n      creating /home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp-0.18.0a0.dist-info/WHEEL\n      running build_py\n      running build_ext\n      building 'aiohttp._multidict' extension\n      creating /tmp/tmpj7fbp5y6.build-temp/aiohttp\n      cc -pthread -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -fPIC\n      -I/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/include -I/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/include/python3.9 -c\n      aiohttp/_multidict.c -o /tmp/tmpj7fbp5y6.build-temp/aiohttp/_multidict.o\n      ************************************************************\n      Cannot compile C accelerator module, use pure python version\n      ************************************************************\n      running editable_wheel\n\n      [stderr]\n      <string>:9: SetuptoolsDeprecationWarning: The test command is disabled and references to it are deprecated.\n      !!\n\n              ********************************************************************************\n              Please remove any references to `setuptools.command.test` in all supported versions of the affected package.\n\n              This deprecation is overdue, please update your project and remove deprecated\n              calls to avoid build errors in the future.\n              ********************************************************************************\n\n      !!\n      /home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/dist.py:261: UserWarning: Unknown distribution option:\n      'tests_require'\n        warnings.warn(msg)\n      warning: no previously-included files matching '*.pyc' found anywhere in distribution\n      warning: no previously-included files found matching 'aiohttp/_multidict.html'\n      warning: no previously-included files found matching 'aiohttp/_multidict.*.so'\n      warning: no previously-included files found matching 'aiohttp/_multidict.pyd'\n      warning: no previously-included files found matching 'aiohttp/_multidict.*.pyd'\n      warning: no previously-included files found matching 'aiohttp/_websocket.html'\n      warning: no previously-included files found matching 'aiohttp/_websocket.*.so'\n      warning: no previously-included files found matching 'aiohttp/_websocket.pyd'\n      warning: no previously-included files found matching 'aiohttp/_websocket.*.pyd'\n      no previously-included directories found matching 'docs/_build'\n      cc1: fatal error: aiohttp/_multidict.c: No such file or directory\n      compilation terminated.\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/spawn.py\", line 70, in spawn\n          subprocess.check_call(cmd, env=_inject_macos_ver(env))\n        File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/subprocess.py\", line 373, in check_call\n          raise CalledProcessError(retcode, cmd)\n      subprocess.CalledProcessError: Command '['/usr/bin/cc', '-pthread', '-Wno-unused-result', '-Wsign-compare', '-Wunreachable-code',\n      '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall', '-fPIC', '-fPIC', '-I/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/include',\n      '-I/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/include/python3.9', '-c', 'aiohttp/_multidict.c', '-o',\n      '/tmp/tmpj7fbp5y6.build-temp/aiohttp/_multidict.o']' returned non-zero exit status 1.\n\n      The above exception was the direct cause of the following exception:\n\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py\", line 200, in _compile\n          self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py\", line 1045, in spawn\n          spawn(cmd, dry_run=self.dry_run, **kwargs)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/spawn.py\", line 76, in spawn\n          raise DistutilsExecError(\n      distutils.errors.DistutilsExecError: command '/usr/bin/cc' failed with exit code 1\n\n      During handling of the above exception, another exception occurred:\n\n      Traceback (most recent call last):\n        File \"<string>\", line 43, in build_extension\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 557, in build_extension\n          objects = self.compiler.compile(\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py\", line 606, in compile\n          self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py\", line 202, in _compile\n          raise CompileError(msg)\n      distutils.errors.CompileError: command '/usr/bin/cc' failed with exit code 1\n\n      During handling of the above exception, another exception occurred:\n\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 139, in run\n          self._create_wheel_file(bdist_wheel)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 340, in _create_wheel_file\n          files, mapping = self._run_build_commands(dist_name, unpacked, lib, tmp)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 263, in _run_build_commands\n          self._run_build_subcommands()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 290, in _run_build_subcommands\n          self.run_command(name)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/cmd.py\", line 316, in run_command\n          self.distribution.run_command(command)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/dist.py\", line 995, in run_command\n          super().run_command(command)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/dist.py\", line 973, in run_command\n          cmd_obj.run()\n        File \"<string>\", line 37, in run\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 359, in run\n          self.build_extensions()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 476, in build_extensions\n          self._build_extensions_serial()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 502, in\n      _build_extensions_serial\n          self.build_extension(ext)\n        File \"<string>\", line 46, in build_extension\n      BuildFailed\n      /home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/dist.py:973: _DebuggingTips: Problem in editable installation.\n      !!\n\n              ********************************************************************************\n              An error happened while installing `aiohttp` in editable mode.\n\n              The following steps are recommended to help debug this problem:\n\n              - Try to install the project normally, without using the editable mode.\n                Does the error still persist?\n                (If it does, try fixing the problem before attempting the editable mode).\n              - If you are using binary extensions, make sure you have all OS-level\n                dependencies installed (e.g. compilers, toolchains, binary libraries, ...).\n              - Try the latest version of setuptools (maybe the error was already fixed).\n              - If you (or your project dependencies) are using any setuptools extension\n                or customization, make sure they support the editable mode.\n\n              After following the steps above, if the problem still persists and\n              you think this is related to how setuptools handles editable installations,\n              please submit a reproducible example\n              (see https://stackoverflow.com/help/minimal-reproducible-example) to:\n\n                  https://github.com/pypa/setuptools/issues\n\n              See https://setuptools.pypa.io/en/latest/userguide/development_mode.html for details.\n              ********************************************************************************\n\n      !!\n        cmd_obj.run()\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/spawn.py\", line 70, in spawn\n          subprocess.check_call(cmd, env=_inject_macos_ver(env))\n        File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/subprocess.py\", line 373, in check_call\n          raise CalledProcessError(retcode, cmd)\n      subprocess.CalledProcessError: Command '['/usr/bin/cc', '-pthread', '-Wno-unused-result', '-Wsign-compare', '-Wunreachable-code',\n      '-DNDEBUG', '-g', '-fwrapv', '-O3', '-Wall', '-fPIC', '-fPIC', '-I/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/include',\n      '-I/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/include/python3.9', '-c', 'aiohttp/_multidict.c', '-o',\n      '/tmp/tmpj7fbp5y6.build-temp/aiohttp/_multidict.o']' returned non-zero exit status 1.\n\n      The above exception was the direct cause of the following exception:\n\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py\", line 200, in _compile\n          self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py\", line 1045, in spawn\n          spawn(cmd, dry_run=self.dry_run, **kwargs)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/spawn.py\", line 76, in spawn\n          raise DistutilsExecError(\n      distutils.errors.DistutilsExecError: command '/usr/bin/cc' failed with exit code 1\n\n      During handling of the above exception, another exception occurred:\n\n      Traceback (most recent call last):\n        File \"<string>\", line 43, in build_extension\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 557, in build_extension\n          objects = self.compiler.compile(\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py\", line 606, in compile\n          self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py\", line 202, in _compile\n          raise CompileError(msg)\n      distutils.errors.CompileError: command '/usr/bin/cc' failed with exit code 1\n\n      During handling of the above exception, another exception occurred:\n\n      Traceback (most recent call last):\n        File \"<string>\", line 107, in <module>\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/__init__.py\", line 117, in setup\n          return distutils.core.setup(**attrs)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/core.py\", line 183, in setup\n          return run_commands(dist)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/core.py\", line 199, in run_commands\n          dist.run_commands()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/dist.py\", line 954, in run_commands\n          self.run_command(cmd)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/dist.py\", line 995, in run_command\n          super().run_command(command)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/dist.py\", line 973, in run_command\n          cmd_obj.run()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 139, in run\n          self._create_wheel_file(bdist_wheel)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 340, in _create_wheel_file\n          files, mapping = self._run_build_commands(dist_name, unpacked, lib, tmp)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 263, in _run_build_commands\n          self._run_build_subcommands()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 290, in _run_build_subcommands\n          self.run_command(name)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/cmd.py\", line 316, in run_command\n          self.distribution.run_command(command)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/dist.py\", line 995, in run_command\n          super().run_command(command)\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/dist.py\", line 973, in run_command\n          cmd_obj.run()\n        File \"<string>\", line 37, in run\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 359, in run\n          self.build_extensions()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 476, in build_extensions\n          self._build_extensions_serial()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py\", line 502, in\n      _build_extensions_serial\n          self.build_extension(ext)\n        File \"<string>\", line 46, in build_extension\n      BuildFailed\n\n      During handling of the above exception, another exception occurred:\n\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/egg_info.py\", line 300, in run\n          os.utime(self.egg_info, None)\n      FileNotFoundError: [Errno 2] No such file or directory\n\n      The above exception was the direct cause of the following exception:\n\n      Traceback (most recent call last):\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 132, in run\n          self._ensure_dist_info()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/editable_wheel.py\", line 151, in _ensure_dist_info\n          dist_info.run()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/dist_info.py\", line 94, in run\n          self.egg_info.run()\n        File \"/home/gcpuser/.cache/uv/builds-v0/.tmpsRncQt/lib/python3.9/site-packages/setuptools/command/egg_info.py\", line 303, in run\n          raise distutils.errors.DistutilsFileError(msg) from e\n      distutils.errors.DistutilsFileError: Cannot update time stamp of directory '/home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info'\n      error: Cannot update time stamp of directory '/home/gcpuser/.cache/uv/builds-v0/.tmpe1rQWW/.tmp-p40kwia8/aiohttp.egg-info'\n\n      hint: This usually indicates a problem with the package or the build environment.\nmake: *** [Makefile:4: .install-deps] Error 1\nResolved 26 packages in 32ms\nInstalled 26 packages in 38ms\n + async-generator==1.10\n + async-timeout==5.0.1\n + brotlipy==0.7.0\n + cffi==1.17.1\n + chardet==5.2.0\n + coverage==7.6.10\n + cryptography==44.0.0\n + cython==3.0.11\n + exceptiongroup==1.2.2\n + gunicorn==23.0.0\n + idna==3.10\n + iniconfig==2.0.0\n + multdict==0.0.5\n + multidict==6.1.0\n + packaging==24.2\n + pluggy==1.5.0\n + propcache==0.2.1\n + pycparser==2.22\n + pytest==8.3.4\n + pytest-asyncio==0.25.1\n + pytest-cov==6.0.0\n + pytest-mock==3.14.0\n + tomli==2.2.1\n + trustme==1.2.1\n + typing-extensions==4.12.2\n + yarl==1.18.3\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_eb54e6c010f55c02e49a36cb2e74b077f8aa77e4\nplugins: mock-3.14.0, asyncio-0.25.1, cov-6.0.0\nasyncio: mode=strict, asyncio_default_fixture_loop_scope=None\ncollected 19 items\n\nr2e_tests/test_1.py ...................                                  [100%]\n\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_ctor\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_dont_unquote_environ_path_info\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ_headers\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ_host_header_alternate_port\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ_host_header_alternate_port_ssl\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_file_wrapper\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_futures\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_io\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_keep_alive\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_readpayload\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_simple\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_http_1_0_no_host\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_not_add_authorization\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_101_upgrade_to_websocket\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_start_response\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_start_response_exc\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_start_response_exc_status\n============================== 19 passed in 0.05s ==============================\n",
    "new_commit_res_stderr": "/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_eb54e6c010f55c02e49a36cb2e74b077f8aa77e4/.venv/lib/python3.9/site-packages/pytest_asyncio/plugin.py:207: PytestDeprecationWarning: The configuration option \"asyncio_default_fixture_loop_scope\" is unset.\nThe event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: \"function\", \"class\", \"module\", \"package\", \"session\"\n\n  warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))\n",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_eb54e6c010f55c02e49a36cb2e74b077f8aa77e4\nplugins: mock-3.14.0, asyncio-0.25.1, cov-6.0.0\nasyncio: mode=strict, asyncio_default_fixture_loop_scope=None\ncollected 19 items\n\nr2e_tests/test_1.py ...FFF.............                                  [100%]\n\n=================================== FAILURES ===================================\n_______________ TestHttpWsgiServerProtocol.test_environ_headers ________________\n\nself = <r2e_tests.test_1.TestHttpWsgiServerProtocol testMethod=test_environ_headers>\n\n    def test_environ_headers(self):\n        self.headers.extend(\n            (('SCRIPT_NAME', 'script'),\n             ('CONTENT-TYPE', 'text/plain'),\n             ('CONTENT-LENGTH', '209'),\n             ('X_TEST', '123'),\n             ('X_TEST', '456')))\n        environ = self._make_one()\n        self.assertEqual(environ['CONTENT_TYPE'], 'text/plain')\n        self.assertEqual(environ['CONTENT_LENGTH'], '209')\n        self.assertEqual(environ['HTTP_X_TEST'], '123,456')\n        self.assertEqual(environ['SCRIPT_NAME'], 'script')\n        self.assertEqual(environ['SERVER_NAME'], 'python.org')\n        self.assertEqual(environ['SERVER_PORT'], '80')\n        get_extra_info_calls = self.transport.get_extra_info.mock_calls\n        expected_calls = [\n            unittest.mock.call('peername'),\n            unittest.mock.call('sockname'),\n        ]\n>       self.assertEqual(expected_calls, get_extra_info_calls)\nE       AssertionError: [call('peername'), call('sockname')] != [call('peername')]\n\nr2e_tests/test_1.py:84: AssertionError\n______ TestHttpWsgiServerProtocol.test_environ_host_header_alternate_port ______\n\nself = <r2e_tests.test_1.TestHttpWsgiServerProtocol testMethod=test_environ_host_header_alternate_port>\n\n    def test_environ_host_header_alternate_port(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one()\n>       self.assertEqual(environ['SERVER_PORT'], '82')\nE       AssertionError: '9999' != '82'\nE       - 9999\nE       + 82\n\nr2e_tests/test_1.py:92: AssertionError\n____ TestHttpWsgiServerProtocol.test_environ_host_header_alternate_port_ssl ____\n\nself = <r2e_tests.test_1.TestHttpWsgiServerProtocol testMethod=test_environ_host_header_alternate_port_ssl>\n\n    def test_environ_host_header_alternate_port_ssl(self):\n        self.transport.get_extra_info = unittest.mock.Mock(\n            side_effect=[('1.2.3.4', 1234), ('3.4.5.6', 82)]\n        )\n        self.headers.update({'HOST': 'example.com:9999'})\n        environ = self._make_one(is_ssl=True)\n>       self.assertEqual(environ['SERVER_PORT'], '82')\nE       AssertionError: '9999' != '82'\nE       - 9999\nE       + 82\n\nr2e_tests/test_1.py:100: AssertionError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_ctor\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_dont_unquote_environ_path_info\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_file_wrapper\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_futures\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_io\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_keep_alive\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_readpayload\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_handle_request_simple\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_http_1_0_no_host\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_not_add_authorization\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_101_upgrade_to_websocket\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_start_response\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_start_response_exc\nPASSED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_wsgi_response_start_response_exc_status\nFAILED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ_headers\nFAILED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ_host_header_alternate_port\nFAILED r2e_tests/test_1.py::TestHttpWsgiServerProtocol::test_environ_host_header_alternate_port_ssl\n========================= 3 failed, 16 passed in 0.09s =========================\n",
    "old_commit_res_stderr": "/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_eb54e6c010f55c02e49a36cb2e74b077f8aa77e4/.venv/lib/python3.9/site-packages/pytest_asyncio/plugin.py:207: PytestDeprecationWarning: The configuration option \"asyncio_default_fixture_loop_scope\" is unset.\nThe event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: \"function\", \"class\", \"module\", \"package\", \"session\"\n\n  warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))\n"
}
aiohttp/wsgi.py tests/test_wsgi.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]

**Title:** Incorrect `SERVER_PORT` in WSGI Environ Causes Test Failures

**Description:**
The `SERVER_PORT` variable in the WSGI environ is not correctly set to the TCP/IP port number on which the request is received from the client. Instead, it incorrectly uses the port specified in the `HOST` header, leading to inconsistencies.

For instance, when the `HOST` header includes a different port than the one the server is listening on, `SERVER_PORT` should reflect the actual listening port. However, the current implementation assigns `SERVER_PORT` based on the `HOST` header, causing discrepancies.

**Example Buggy Code:**
```python
def test_server_port():
    transport.get_extra_info.side_effect = [('1.2.3.4', 9999), ('3.4.5.6', 82)]
    headers.update({'HOST': 'example.com:9999'})
    environ = create_wsgi_environ()
    print(environ['SERVER_PORT'])  # Expected: '82'
```

**Expected Behavior:**
`SERVER_PORT` should be set to the actual TCP/IP port number on which the request is received (`82` in this case), regardless of the port specified in the `HOST` header.

**Actual Behavior:**
`SERVER_PORT` is incorrectly set to `'9999'`, the port from the `HOST` header, instead of the actual listening port `'82'`. This causes tests expecting the correct port to fail.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### aiohttp/wsgi.py
"""wsgi server.

TODO:
  * proxy protocol
  * x-forward security
  * wsgi file support (os.sendfile)
"""

import asyncio
import inspect
import io
import os
import sys
from urllib.parse import urlsplit

import aiohttp
from aiohttp import server, hdrs

__all__ = ('WSGIServerHttpProtocol',)


class WSGIServerHttpProtocol(server.ServerHttpProtocol):
    """HTTP Server that implements the Python WSGI protocol.

    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently
    depends on 'readpayload' constructor parameter. If readpayload is set to
    True, wsgi server reads all incoming data into BytesIO object and
    sends it as 'wsgi.input' environ var. If readpayload is set to false
    'wsgi.input' is a StreamReader and application should read incoming
    data with "yield from environ['wsgi.input'].read()". It defaults to False.
    """

    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')

    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):
        super().__init__(*args, **kw)

        self.wsgi = app
        self.is_ssl = is_ssl
        self.readpayload = readpayload

    def create_wsgi_response(self, message):
        return WsgiResponse(self.writer, message)

    def create_wsgi_environ(self, message, payload):
        uri_parts = urlsplit(message.path)
        url_scheme = 'https' if self.is_ssl else 'http'

        environ = {
            'wsgi.input': payload,
            'wsgi.errors': sys.stderr,
            'wsgi.version': (1, 0),
            'wsgi.async': True,
            'wsgi.multithread': False,
            'wsgi.multiprocess': False,
            'wsgi.run_once': False,
            'wsgi.file_wrapper': FileWrapper,
            'wsgi.url_scheme': url_scheme,
            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,
            'REQUEST_METHOD': message.method,
            'QUERY_STRING': uri_parts.query or '',
            'RAW_URI': message.path,
            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version
        }

        script_name = self.SCRIPT_NAME

        for hdr_name, hdr_value in message.headers.items():
            if hdr_name == 'AUTHORIZATION':
                continue
            elif hdr_name == 'SCRIPT_NAME':
                script_name = hdr_value
            elif hdr_name == 'CONTENT-TYPE':
                environ['CONTENT_TYPE'] = hdr_value
                continue
            elif hdr_name == 'CONTENT-LENGTH':
                environ['CONTENT_LENGTH'] = hdr_value
                continue

            key = 'HTTP_%s' % hdr_name.replace('-', '_')
            if key in environ:
                hdr_value = '%s,%s' % (environ[key], hdr_value)

            environ[key] = hdr_value

        remote = self.transport.get_extra_info('peername')
        environ['REMOTE_ADDR'] = remote[0]
        environ['REMOTE_PORT'] = remote[1]
        host = message.headers.get("HOST", None)
        if host:
            host = host.split(":")
        else:
            host = self.transport.get_extra_info('sockname')
        environ['SERVER_NAME'] = host[0]
        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'

        path_info = uri_parts.path
        if script_name:
            path_info = path_info.split(script_name, 1)[-1]

        environ['PATH_INFO'] = path_info
        environ['SCRIPT_NAME'] = script_name

        environ['async.reader'] = self.reader
        environ['async.writer'] = self.writer

        return environ

    @asyncio.coroutine
    def handle_request(self, message, payload):
        """Handle a single HTTP request"""
        now = self._loop.time()

        if self.readpayload:
            wsgiinput = io.BytesIO()
            wsgiinput.write((yield from payload.read()))
            wsgiinput.seek(0)
            payload = wsgiinput

        environ = self.create_wsgi_environ(message, payload)
        response = self.create_wsgi_response(message)

        riter = self.wsgi(environ, response.start_response)
        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):
            riter = yield from riter

        resp = response.response
        try:
            for item in riter:
                if isinstance(item, asyncio.Future):
                    item = yield from item
                yield from resp.write(item)

            yield from resp.write_eof()
        finally:
            if hasattr(riter, 'close'):
                riter.close()

        if resp.keep_alive():
            self.keep_alive(True)

        self.log_access(
            message, environ, response.response, self._loop.time() - now)


class FileWrapper:
    """Custom file wrapper."""

    def __init__(self, fobj, chunk_size=8192):
        self.fobj = fobj
        self.chunk_size = chunk_size
        if hasattr(fobj, 'close'):
            self.close = fobj.close

    def __iter__(self):
        return self

    def __next__(self):
        data = self.fobj.read(self.chunk_size)
        if data:
            return data
        raise StopIteration


class WsgiResponse:
    """Implementation of start_response() callable as specified by PEP 3333"""

    status = None

    HOP_HEADERS = {
        hdrs.CONNECTION,
        hdrs.KEEP_ALIVE,
        hdrs.PROXY_AUTHENTICATE,
        hdrs.PROXY_AUTHORIZATION,
        hdrs.TE,
        hdrs.TRAILER,
        hdrs.TRANSFER_ENCODING,
        hdrs.UPGRADE,
    }

    def __init__(self, writer, message):
        self.writer = writer
        self.message = message

    def start_response(self, status, headers, exc_info=None):
        if exc_info:
            try:
                if self.status:
                    raise exc_info[1]
            finally:
                exc_info = None

        status_code = int(status.split(' ', 1)[0])

        self.status = status
        resp = self.response = aiohttp.Response(
            self.writer, status_code,
            self.message.version, self.message.should_close)
        resp.HOP_HEADERS = self.HOP_HEADERS
        resp.add_headers(*headers)

        if resp.has_chunked_hdr:
            resp.enable_chunked_encoding()

        # send headers immediately for websocket connection
        if status_code == 101 and resp.upgrade and resp.websocket:
            resp.send_headers()
        else:
            resp._send_headers = True
        return self.response.write

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]

**Title:** Incorrect `SERVER_PORT` in WSGI Environ Causes Test Failures

**Description:**
The `SERVER_PORT` variable in the WSGI environ is not correctly set to the TCP/IP port number on which the request is received from the client. Instead, it incorrectly uses the port specified in the `HOST` header, leading to inconsistencies.

For instance, when the `HOST` header includes a different port than the one the server is listening on, `SERVER_PORT` should reflect the actual listening port. However, the current implementation assigns `SERVER_PORT` based on the `HOST` header, causing discrepancies.

**Example Buggy Code:**
```python
def test_server_port():
    transport.get_extra_info.side_effect = [('1.2.3.4', 9999), ('3.4.5.6', 82)]
    headers.update({'HOST': 'example.com:9999'})
    environ = create_wsgi_environ()
    print(environ['SERVER_PORT'])  # Expected: '82'
```

**Expected Behavior:**
`SERVER_PORT` should be set to the actual TCP/IP port number on which the request is received (`82` in this case), regardless of the port specified in the `HOST` header.

**Actual Behavior:**
`SERVER_PORT` is incorrectly set to `'9999'`, the port from the `HOST` header, instead of the actual listening port `'82'`. This causes tests expecting the correct port to fail.

[/ISSUE]
{
    "TestHttpWsgiServerProtocol.test_ctor": "PASSED",
    "TestHttpWsgiServerProtocol.test_dont_unquote_environ_path_info": "PASSED",
    "TestHttpWsgiServerProtocol.test_environ": "PASSED",
    "TestHttpWsgiServerProtocol.test_environ_headers": "PASSED",
    "TestHttpWsgiServerProtocol.test_environ_host_header_alternate_port": "PASSED",
    "TestHttpWsgiServerProtocol.test_environ_host_header_alternate_port_ssl": "PASSED",
    "TestHttpWsgiServerProtocol.test_file_wrapper": "PASSED",
    "TestHttpWsgiServerProtocol.test_handle_request_futures": "PASSED",
    "TestHttpWsgiServerProtocol.test_handle_request_io": "PASSED",
    "TestHttpWsgiServerProtocol.test_handle_request_keep_alive": "PASSED",
    "TestHttpWsgiServerProtocol.test_handle_request_readpayload": "PASSED",
    "TestHttpWsgiServerProtocol.test_handle_request_simple": "PASSED",
    "TestHttpWsgiServerProtocol.test_http_1_0_no_host": "PASSED",
    "TestHttpWsgiServerProtocol.test_not_add_authorization": "PASSED",
    "TestHttpWsgiServerProtocol.test_wsgi_response": "PASSED",
    "TestHttpWsgiServerProtocol.test_wsgi_response_101_upgrade_to_websocket": "PASSED",
    "TestHttpWsgiServerProtocol.test_wsgi_response_start_response": "PASSED",
    "TestHttpWsgiServerProtocol.test_wsgi_response_start_response_exc": "PASSED",
    "TestHttpWsgiServerProtocol.test_wsgi_response_start_response_exc_status": "PASSED"
}
diff --git a/aiohttp/wsgi.py b/aiohttp/wsgi.py
index bd950d2f..7f172d32 100644
--- a/aiohttp/wsgi.py
+++ b/aiohttp/wsgi.py
@@ -83,16 +83,23 @@ class WSGIServerHttpProtocol(server.ServerHttpProtocol):
 
             environ[key] = hdr_value
 
+        # authors should be aware that REMOTE_HOST and REMOTE_ADDR
+        # may not qualify the remote addr
+        # also SERVER_PORT variable MUST be set to the TCP/IP port number on
+        # which this request is received from the client.
+        # http://www.ietf.org/rfc/rfc3875
+
         remote = self.transport.get_extra_info('peername')
         environ['REMOTE_ADDR'] = remote[0]
         environ['REMOTE_PORT'] = remote[1]
+
+        sockname = self.transport.get_extra_info('sockname')
+        environ['SERVER_PORT'] = str(sockname[1])
         host = message.headers.get("HOST", None)
         if host:
-            host = host.split(":")
+            environ['SERVER_NAME'] = host.split(":")[0]
         else:
-            host = self.transport.get_extra_info('sockname')
-        environ['SERVER_NAME'] = host[0]
-        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'
+            environ['SERVER_NAME'] = sockname[0]
 
         path_info = uri_parts.path
         if script_name:

{"aiohttp/wsgi.py": "\"\"\"wsgi server.\n\nTODO:\n  * proxy protocol\n  * x-forward security\n  * wsgi file support (os.sendfile)\n\"\"\"\n\nimport asyncio\nimport inspect\nimport io\nimport os\nimport sys\nfrom urllib.parse import urlsplit\n\nimport aiohttp\nfrom aiohttp import server, hdrs\n\n__all__ = ('WSGIServerHttpProtocol',)\n\n\nclass WSGIServerHttpProtocol(server.ServerHttpProtocol):\n    \"\"\"HTTP Server that implements the Python WSGI protocol.\n\n    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently\n    depends on 'readpayload' constructor parameter. If readpayload is set to\n    True, wsgi server reads all incoming data into BytesIO object and\n    sends it as 'wsgi.input' environ var. If readpayload is set to false\n    'wsgi.input' is a StreamReader and application should read incoming\n    data with \"yield from environ['wsgi.input'].read()\". It defaults to False.\n    \"\"\"\n\n    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')\n\n    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):\n        super().__init__(*args, **kw)\n\n        self.wsgi = app\n        self.is_ssl = is_ssl\n        self.readpayload = readpayload\n\n    def create_wsgi_response(self, message):\n        return WsgiResponse(self.writer, message)\n\n    def create_wsgi_environ(self, message, payload):\n        uri_parts = urlsplit(message.path)\n        url_scheme = 'https' if self.is_ssl else 'http'\n\n        environ = {\n            'wsgi.input': payload,\n            'wsgi.errors': sys.stderr,\n            'wsgi.version': (1, 0),\n            'wsgi.async': True,\n            'wsgi.multithread': False,\n            'wsgi.multiprocess': False,\n            'wsgi.run_once': False,\n            'wsgi.file_wrapper': FileWrapper,\n            'wsgi.url_scheme': url_scheme,\n            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,\n            'REQUEST_METHOD': message.method,\n            'QUERY_STRING': uri_parts.query or '',\n            'RAW_URI': message.path,\n            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version\n        }\n\n        script_name = self.SCRIPT_NAME\n\n        for hdr_name, hdr_value in message.headers.items():\n            if hdr_name == 'AUTHORIZATION':\n                continue\n            elif hdr_name == 'SCRIPT_NAME':\n                script_name = hdr_value\n            elif hdr_name == 'CONTENT-TYPE':\n                environ['CONTENT_TYPE'] = hdr_value\n                continue\n            elif hdr_name == 'CONTENT-LENGTH':\n                environ['CONTENT_LENGTH'] = hdr_value\n                continue\n\n            key = 'HTTP_%s' % hdr_name.replace('-', '_')\n            if key in environ:\n                hdr_value = '%s,%s' % (environ[key], hdr_value)\n\n            environ[key] = hdr_value\n\n        remote = self.transport.get_extra_info('peername')\n        environ['REMOTE_ADDR'] = remote[0]\n        environ['REMOTE_PORT'] = remote[1]\n        host = message.headers.get(\"HOST\", None)\n        if host:\n            host = host.split(\":\")\n        else:\n            host = self.transport.get_extra_info('sockname')\n        environ['SERVER_NAME'] = host[0]\n        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'\n\n        path_info = uri_parts.path\n        if script_name:\n            path_info = path_info.split(script_name, 1)[-1]\n\n        environ['PATH_INFO'] = path_info\n        environ['SCRIPT_NAME'] = script_name\n\n        environ['async.reader'] = self.reader\n        environ['async.writer'] = self.writer\n\n        return environ\n\n    @asyncio.coroutine\n    def handle_request(self, message, payload):\n        \"\"\"Handle a single HTTP request\"\"\"\n        now = self._loop.time()\n\n        if self.readpayload:\n            wsgiinput = io.BytesIO()\n            wsgiinput.write((yield from payload.read()))\n            wsgiinput.seek(0)\n            payload = wsgiinput\n\n        environ = self.create_wsgi_environ(message, payload)\n        response = self.create_wsgi_response(message)\n\n        riter = self.wsgi(environ, response.start_response)\n        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):\n            riter = yield from riter\n\n        resp = response.response\n        try:\n            for item in riter:\n                if isinstance(item, asyncio.Future):\n                    item = yield from item\n                yield from resp.write(item)\n\n            yield from resp.write_eof()\n        finally:\n            if hasattr(riter, 'close'):\n                riter.close()\n\n        if resp.keep_alive():\n            self.keep_alive(True)\n\n        self.log_access(\n            message, environ, response.response, self._loop.time() - now)\n\n\nclass FileWrapper:\n    \"\"\"Custom file wrapper.\"\"\"\n\n    def __init__(self, fobj, chunk_size=8192):\n        self.fobj = fobj\n        self.chunk_size = chunk_size\n        if hasattr(fobj, 'close'):\n            self.close = fobj.close\n\n    def __iter__(self):\n        return self\n\n    def __next__(self):\n        data = self.fobj.read(self.chunk_size)\n        if data:\n            return data\n        raise StopIteration\n\n\nclass WsgiResponse:\n    \"\"\"Implementation of start_response() callable as specified by PEP 3333\"\"\"\n\n    status = None\n\n    HOP_HEADERS = {\n        hdrs.CONNECTION,\n        hdrs.KEEP_ALIVE,\n        hdrs.PROXY_AUTHENTICATE,\n        hdrs.PROXY_AUTHORIZATION,\n        hdrs.TE,\n        hdrs.TRAILER,\n        hdrs.TRANSFER_ENCODING,\n        hdrs.UPGRADE,\n    }\n\n    def __init__(self, writer, message):\n        self.writer = writer\n        self.message = message\n\n    def start_response(self, status, headers, exc_info=None):\n        if exc_info:\n            try:\n                if self.status:\n                    raise exc_info[1]\n            finally:\n                exc_info = None\n\n        status_code = int(status.split(' ', 1)[0])\n\n        self.status = status\n        resp = self.response = aiohttp.Response(\n            self.writer, status_code,\n            self.message.version, self.message.should_close)\n        resp.HOP_HEADERS = self.HOP_HEADERS\n        resp.add_headers(*headers)\n\n        if resp.has_chunked_hdr:\n            resp.enable_chunked_encoding()\n\n        # send headers immediately for websocket connection\n        if status_code == 101 and resp.upgrade and resp.websocket:\n            resp.send_headers()\n        else:\n            resp._send_headers = True\n        return self.response.write\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]

**Title:** Incorrect `SERVER_PORT` in WSGI Environ Causes Test Failures

**Description:**
The `SERVER_PORT` variable in the WSGI environ is not correctly set to the TCP/IP port number on which the request is received from the client. Instead, it incorrectly uses the port specified in the `HOST` header, leading to inconsistencies.

For instance, when the `HOST` header includes a different port than the one the server is listening on, `SERVER_PORT` should reflect the actual listening port. However, the current implementation assigns `SERVER_PORT` based on the `HOST` header, causing discrepancies.

**Example Buggy Code:**
```python
def test_server_port():
    transport.get_extra_info.side_effect = [('1.2.3.4', 9999), ('3.4.5.6', 82)]
    headers.update({'HOST': 'example.com:9999'})
    environ = create_wsgi_environ()
    print(environ['SERVER_PORT'])  # Expected: '82'
```

**Expected Behavior:**
`SERVER_PORT` should be set to the actual TCP/IP port number on which the request is received (`82` in this case), regardless of the port specified in the `HOST` header.

**Actual Behavior:**
`SERVER_PORT` is incorrectly set to `'9999'`, the port from the `HOST` header, instead of the actual listening port `'82'`. This causes tests expecting the correct port to fail.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### aiohttp/wsgi.py
"""wsgi server.

TODO:
  * proxy protocol
  * x-forward security
  * wsgi file support (os.sendfile)
"""

import asyncio
import inspect
import io
import os
import sys
from urllib.parse import urlsplit

import aiohttp
from aiohttp import server, hdrs

__all__ = ('WSGIServerHttpProtocol',)


class WSGIServerHttpProtocol(server.ServerHttpProtocol):
    """HTTP Server that implements the Python WSGI protocol.

    It uses 'wsgi.async' of 'True'. 'wsgi.input' can behave differently
    depends on 'readpayload' constructor parameter. If readpayload is set to
    True, wsgi server reads all incoming data into BytesIO object and
    sends it as 'wsgi.input' environ var. If readpayload is set to false
    'wsgi.input' is a StreamReader and application should read incoming
    data with "yield from environ['wsgi.input'].read()". It defaults to False.
    """

    SCRIPT_NAME = os.environ.get('SCRIPT_NAME', '')

    def __init__(self, app, readpayload=False, is_ssl=False, *args, **kw):
        super().__init__(*args, **kw)

        self.wsgi = app
        self.is_ssl = is_ssl
        self.readpayload = readpayload

    def create_wsgi_response(self, message):
        return WsgiResponse(self.writer, message)

    def create_wsgi_environ(self, message, payload):
        uri_parts = urlsplit(message.path)
        url_scheme = 'https' if self.is_ssl else 'http'

        environ = {
            'wsgi.input': payload,
            'wsgi.errors': sys.stderr,
            'wsgi.version': (1, 0),
            'wsgi.async': True,
            'wsgi.multithread': False,
            'wsgi.multiprocess': False,
            'wsgi.run_once': False,
            'wsgi.file_wrapper': FileWrapper,
            'wsgi.url_scheme': url_scheme,
            'SERVER_SOFTWARE': aiohttp.HttpMessage.SERVER_SOFTWARE,
            'REQUEST_METHOD': message.method,
            'QUERY_STRING': uri_parts.query or '',
            'RAW_URI': message.path,
            'SERVER_PROTOCOL': 'HTTP/%s.%s' % message.version
        }

        script_name = self.SCRIPT_NAME

        for hdr_name, hdr_value in message.headers.items():
            if hdr_name == 'AUTHORIZATION':
                continue
            elif hdr_name == 'SCRIPT_NAME':
                script_name = hdr_value
            elif hdr_name == 'CONTENT-TYPE':
                environ['CONTENT_TYPE'] = hdr_value
                continue
            elif hdr_name == 'CONTENT-LENGTH':
                environ['CONTENT_LENGTH'] = hdr_value
                continue

            key = 'HTTP_%s' % hdr_name.replace('-', '_')
            if key in environ:
                hdr_value = '%s,%s' % (environ[key], hdr_value)

            environ[key] = hdr_value

        remote = self.transport.get_extra_info('peername')
        environ['REMOTE_ADDR'] = remote[0]
        environ['REMOTE_PORT'] = remote[1]
        host = message.headers.get("HOST", None)
        if host:
            host = host.split(":")
        else:
            host = self.transport.get_extra_info('sockname')
        environ['SERVER_NAME'] = host[0]
        environ['SERVER_PORT'] = str(host[1]) if len(host) > 1 else '80'

        path_info = uri_parts.path
        if script_name:
            path_info = path_info.split(script_name, 1)[-1]

        environ['PATH_INFO'] = path_info
        environ['SCRIPT_NAME'] = script_name

        environ['async.reader'] = self.reader
        environ['async.writer'] = self.writer

        return environ

    @asyncio.coroutine
    def handle_request(self, message, payload):
        """Handle a single HTTP request"""
        now = self._loop.time()

        if self.readpayload:
            wsgiinput = io.BytesIO()
            wsgiinput.write((yield from payload.read()))
            wsgiinput.seek(0)
            payload = wsgiinput

        environ = self.create_wsgi_environ(message, payload)
        response = self.create_wsgi_response(message)

        riter = self.wsgi(environ, response.start_response)
        if isinstance(riter, asyncio.Future) or inspect.isgenerator(riter):
            riter = yield from riter

        resp = response.response
        try:
            for item in riter:
                if isinstance(item, asyncio.Future):
                    item = yield from item
                yield from resp.write(item)

            yield from resp.write_eof()
        finally:
            if hasattr(riter, 'close'):
                riter.close()

        if resp.keep_alive():
            self.keep_alive(True)

        self.log_access(
            message, environ, response.response, self._loop.time() - now)


class FileWrapper:
    """Custom file wrapper."""

    def __init__(self, fobj, chunk_size=8192):
        self.fobj = fobj
        self.chunk_size = chunk_size
        if hasattr(fobj, 'close'):
            self.close = fobj.close

    def __iter__(self):
        return self

    def __next__(self):
        data = self.fobj.read(self.chunk_size)
        if data:
            return data
        raise StopIteration


class WsgiResponse:
    """Implementation of start_response() callable as specified by PEP 3333"""

    status = None

    HOP_HEADERS = {
        hdrs.CONNECTION,
        hdrs.KEEP_ALIVE,
        hdrs.PROXY_AUTHENTICATE,
        hdrs.PROXY_AUTHORIZATION,
        hdrs.TE,
        hdrs.TRAILER,
        hdrs.TRANSFER_ENCODING,
        hdrs.UPGRADE,
    }

    def __init__(self, writer, message):
        self.writer = writer
        self.message = message

    def start_response(self, status, headers, exc_info=None):
        if exc_info:
            try:
                if self.status:
                    raise exc_info[1]
            finally:
                exc_info = None

        status_code = int(status.split(' ', 1)[0])

        self.status = status
        resp = self.response = aiohttp.Response(
            self.writer, status_code,
            self.message.version, self.message.should_close)
        resp.HOP_HEADERS = self.HOP_HEADERS
        resp.add_headers(*headers)

        if resp.has_chunked_hdr:
            resp.enable_chunked_encoding()

        # send headers immediately for websocket connection
        if status_code == 101 and resp.upgrade and resp.websocket:
            resp.send_headers()
        else:
            resp._send_headers = True
        return self.response.write

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user