{
    "file_diffs": [
        {
            "old_file_content": "__all__ = ['BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector']\n\nimport asyncio\nimport aiohttp\nimport functools\nimport http.cookies\nimport time\nimport ssl\nimport socket\nimport weakref\n\nfrom .client import ClientRequest\nfrom .errors import ServerDisconnectedError\nfrom .errors import HttpProxyError, ProxyConnectionError\nfrom .errors import ClientOSError, ClientTimeoutError\nfrom .helpers import BasicAuth\n\n\nclass Connection(object):\n\n    def __init__(self, connector, key, request, transport, protocol, loop):\n        self._key = key\n        self._connector = connector\n        self._request = request\n        self._transport = transport\n        self._protocol = protocol\n        self._loop = loop\n        self.reader = protocol.reader\n        self.writer = protocol.writer\n        self._wr = weakref.ref(self, lambda wr, tr=self._transport: tr.close())\n\n    @property\n    def loop(self):\n        return self._loop\n\n    def close(self):\n        if self._transport is not None:\n            self._connector._release(\n                self._key, self._request, self._transport, self._protocol,\n                should_close=True)\n            self._transport = None\n            self._wr = None\n\n    def release(self):\n        if self._transport:\n            self._connector._release(\n                self._key, self._request, self._transport, self._protocol)\n            self._transport = None\n            self._wr = None\n\n    def share_cookies(self, cookies):\n        if self._connector._share_cookies:  # XXX\n            self._connector.update_cookies(cookies)\n\n\nclass BaseConnector(object):\n    \"\"\"Base connector class.\n\n    :param conn_timeout: (optional) Connect timeout.\n    :param keepalive_timeout: (optional) Keep-alive timeout.\n    :param bool share_cookies: Set to True to keep cookies between requests.\n    :param bool force_close: Set to True to froce close and do reconnect\n        after each request (and between redirects).\n    :param loop: Optional event loop.\n    \"\"\"\n\n    def __init__(self, *, conn_timeout=None, keepalive_timeout=30,\n                 share_cookies=False, force_close=False, loop=None):\n        self._conns = {}\n        self._conn_timeout = conn_timeout\n        self._keepalive_timeout = keepalive_timeout\n        self._share_cookies = share_cookies\n        self._cleanup_handle = None\n        self._force_close = force_close\n\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n        self._factory = functools.partial(\n            aiohttp.StreamProtocol, loop=loop,\n            disconnect_error=ServerDisconnectedError)\n\n        self.cookies = http.cookies.SimpleCookie()\n        self._wr = weakref.ref(\n            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))\n\n    def _cleanup(self):\n        \"\"\"Cleanup unused transports.\"\"\"\n        if self._cleanup_handle:\n            self._cleanup_handle.cancel()\n            self._cleanup_handle = None\n\n        now = time.time()\n\n        connections = {}\n        for key, conns in self._conns.items():\n            alive = []\n            for transport, proto, t0 in conns:\n                if transport is not None:\n                    if proto and not proto.is_connected():\n                        transport = None\n                    elif (now - t0) > self._keepalive_timeout:\n                        transport.close()\n                        transport = None\n\n                if transport:\n                    alive.append((transport, proto, t0))\n            if alive:\n                connections[key] = alive\n\n        if connections:\n            self._cleanup_handle = self._loop.call_later(\n                self._keepalive_timeout, self._cleanup)\n\n        self._conns = connections\n        self._wr = weakref.ref(\n            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))\n\n    def _start_cleanup_task(self):\n        if self._cleanup_handle is None:\n            self._cleanup_handle = self._loop.call_later(\n                self._keepalive_timeout, self._cleanup)\n\n    def close(self):\n        \"\"\"Close all opened transports.\"\"\"\n        self._do_close(self._conns)\n\n    @staticmethod\n    def _do_close(conns):\n        for key, data in conns.items():\n            for transport, proto, td in data:\n                transport.close()\n\n        conns.clear()\n\n    def update_cookies(self, cookies):\n        \"\"\"Update shared cookies.\"\"\"\n        if isinstance(cookies, dict):\n            cookies = cookies.items()\n\n        for name, value in cookies:\n            if isinstance(value, http.cookies.Morsel):\n                # use dict method because SimpleCookie class modifies value\n                dict.__setitem__(self.cookies, name, value)\n            else:\n                self.cookies[name] = value\n\n    @asyncio.coroutine\n    def connect(self, req):\n        \"\"\"Get from pool or create new connection.\"\"\"\n        key = (req.host, req.port, req.ssl)\n\n        if self._share_cookies:\n            req.update_cookies(self.cookies.items())\n\n        transport, proto = self._get(key)\n        if transport is None:\n            try:\n                if self._conn_timeout:\n                    transport, proto = yield from asyncio.wait_for(\n                        self._create_connection(req),\n                        self._conn_timeout, loop=self._loop)\n                else:\n                    transport, proto = yield from self._create_connection(req)\n            except asyncio.TimeoutError as exc:\n                raise ClientTimeoutError() from exc\n            except OSError as exc:\n                raise ClientOSError() from exc\n\n        return Connection(self, key, req, transport, proto, self._loop)\n\n    def _get(self, key):\n        conns = self._conns.get(key)\n        while conns:\n            transport, proto, t0 = conns.pop()\n            if transport is not None and proto.is_connected():\n                if (time.time() - t0) > self._keepalive_timeout:\n                    transport.close()\n                    transport = None\n                else:\n                    return transport, proto\n\n        return None, None\n\n    def _release(self, key, req, transport, protocol, *, should_close=False):\n        resp = req.response\n\n        if not should_close:\n            if resp is not None:\n                if resp.message is None:\n                    should_close = True\n                else:\n                    should_close = resp.message.should_close\n\n            if self._force_close:\n                should_close = True\n\n        reader = protocol.reader\n        if should_close or (reader.output and not reader.output.at_eof()):\n            self._conns.pop(key, None)\n            transport.close()\n        else:\n            conns = self._conns.get(key)\n            if conns is None:\n                conns = self._conns[key] = []\n            conns.append((transport, protocol, time.time()))\n            reader.unset_parser()\n\n            self._start_cleanup_task()\n\n    def _create_connection(self, req, *args, **kwargs):\n        raise NotImplementedError()\n\n\nclass TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc\n\n\nclass ProxyConnector(TCPConnector):\n    \"\"\"Http Proxy connector.\n\n    :param str proxy: Proxy URL address. Only http proxy supported.\n    :param proxy_auth: (optional) Proxy HTTP Basic Auth\n    :type proxy_auth: aiohttp.helpers.BasicAuth\n    :param args: see :class:`TCPConnector`\n    :param kwargs: see :class:`TCPConnector`\n\n    Usage:\n\n    >>> conn = ProxyConnector(proxy=\"http://some.proxy.com\")\n    >>> resp = yield from request('GET', 'http://python.org', connector=conn)\n\n    \"\"\"\n\n    def __init__(self, proxy, *args, proxy_auth=None, **kwargs):\n        super().__init__(*args, **kwargs)\n        self._proxy = proxy\n        self._proxy_auth = proxy_auth\n        assert proxy.startswith('http://'), (\n            \"Only http proxy supported\", proxy)\n        assert proxy_auth is None or isinstance(proxy_auth, BasicAuth), (\n            \"proxy_auth must be None or BasicAuth() tuple\", proxy_auth)\n\n    @property\n    def proxy(self):\n        \"\"\"Proxy URL.\"\"\"\n        return self._proxy\n\n    @asyncio.coroutine\n    def _create_connection(self, req, **kwargs):\n        proxy_req = ClientRequest(\n            'GET', self._proxy,\n            headers={'Host': req.host},\n            auth=self._proxy_auth,\n            loop=self._loop)\n        try:\n            transport, proto = yield from super()._create_connection(proxy_req)\n        except OSError as exc:\n            raise ProxyConnectionError(*exc.args) from exc\n\n        req.path = '{scheme}://{host}{path}'.format(scheme=req.scheme,\n                                                    host=req.netloc,\n                                                    path=req.path)\n        if 'AUTHORIZATION' in proxy_req.headers:\n            auth = proxy_req.headers['AUTHORIZATION']\n            del proxy_req.headers['AUTHORIZATION']\n            req.headers['PROXY-AUTHORIZATION'] = auth\n\n        if req.ssl:\n            # For HTTPS requests over HTTP proxy\n            # we must notify proxy to tunnel connection\n            # so we send CONNECT command:\n            #   CONNECT www.python.org:443 HTTP/1.1\n            #   Host: www.python.org\n            #\n            # next we must do TLS handshake and so on\n            # to do this we must wrap raw socket into secure one\n            # asyncio handles this perfectly\n            proxy_req.method = 'CONNECT'\n            proxy_req.path = '{}:{}'.format(req.host, req.port)\n            key = (req.host, req.port, req.ssl)\n            conn = Connection(self, key, proxy_req,\n                              transport, proto, self._loop)\n            proxy_resp = proxy_req.send(conn.writer, conn.reader)\n            try:\n                resp = yield from proxy_resp.start(conn, True)\n            except:\n                proxy_resp.close()\n                conn.close()\n                raise\n            else:\n                if resp.status != 200:\n                    raise HttpProxyError(code=resp.status, message=resp.reason)\n                rawsock = transport.get_extra_info('socket', default=None)\n                if rawsock is None:\n                    raise RuntimeError(\n                        \"Transport does not expose socket instance\")\n                transport.pause_reading()\n                transport, proto = yield from self._loop.create_connection(\n                    self._factory, ssl=True, sock=rawsock,\n                    server_hostname=req.host, **kwargs)\n\n        return transport, proto\n\n\nclass UnixConnector(BaseConnector):\n    \"\"\"Unix socket connector.\n\n    :param str path: Unix socket path.\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n\n    Usage:\n\n    >>> conn = UnixConnector(path='/path/to/socket')\n    >>> resp = yield from request('GET', 'http://python.org', connector=conn)\n\n    \"\"\"\n\n    def __init__(self, path, *args, **kw):\n        super().__init__(*args, **kw)\n        self._path = path\n\n    @property\n    def path(self):\n        \"\"\"Path to unix socket.\"\"\"\n        return self._path\n\n    @asyncio.coroutine\n    def _create_connection(self, req, **kwargs):\n        return (yield from self._loop.create_unix_connection(\n            self._factory, self._path, **kwargs))\n",
            "new_file_content": "__all__ = ['BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector']\n\nimport asyncio\nimport aiohttp\nimport functools\nimport http.cookies\nimport time\nimport ssl\nimport socket\nimport weakref\n\nfrom .client import ClientRequest\nfrom .errors import ServerDisconnectedError\nfrom .errors import HttpProxyError, ProxyConnectionError\nfrom .errors import ClientOSError, ClientTimeoutError\nfrom .helpers import BasicAuth\n\n\nclass Connection(object):\n\n    def __init__(self, connector, key, request, transport, protocol, loop):\n        self._key = key\n        self._connector = connector\n        self._request = request\n        self._transport = transport\n        self._protocol = protocol\n        self._loop = loop\n        self.reader = protocol.reader\n        self.writer = protocol.writer\n        self._wr = weakref.ref(self, lambda wr, tr=self._transport: tr.close())\n\n    @property\n    def loop(self):\n        return self._loop\n\n    def close(self):\n        if self._transport is not None:\n            self._connector._release(\n                self._key, self._request, self._transport, self._protocol,\n                should_close=True)\n            self._transport = None\n            self._wr = None\n\n    def release(self):\n        if self._transport:\n            self._connector._release(\n                self._key, self._request, self._transport, self._protocol)\n            self._transport = None\n            self._wr = None\n\n    def share_cookies(self, cookies):\n        if self._connector._share_cookies:  # XXX\n            self._connector.update_cookies(cookies)\n\n\nclass BaseConnector(object):\n    \"\"\"Base connector class.\n\n    :param conn_timeout: (optional) Connect timeout.\n    :param keepalive_timeout: (optional) Keep-alive timeout.\n    :param bool share_cookies: Set to True to keep cookies between requests.\n    :param bool force_close: Set to True to froce close and do reconnect\n        after each request (and between redirects).\n    :param loop: Optional event loop.\n    \"\"\"\n\n    def __init__(self, *, conn_timeout=None, keepalive_timeout=30,\n                 share_cookies=False, force_close=False, loop=None):\n        self._conns = {}\n        self._conn_timeout = conn_timeout\n        self._keepalive_timeout = keepalive_timeout\n        self._share_cookies = share_cookies\n        self._cleanup_handle = None\n        self._force_close = force_close\n\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n        self._factory = functools.partial(\n            aiohttp.StreamProtocol, loop=loop,\n            disconnect_error=ServerDisconnectedError)\n\n        self.cookies = http.cookies.SimpleCookie()\n        self._wr = weakref.ref(\n            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))\n\n    def _cleanup(self):\n        \"\"\"Cleanup unused transports.\"\"\"\n        if self._cleanup_handle:\n            self._cleanup_handle.cancel()\n            self._cleanup_handle = None\n\n        now = time.time()\n\n        connections = {}\n        for key, conns in self._conns.items():\n            alive = []\n            for transport, proto, t0 in conns:\n                if transport is not None:\n                    if proto and not proto.is_connected():\n                        transport = None\n                    elif (now - t0) > self._keepalive_timeout:\n                        transport.close()\n                        transport = None\n\n                if transport:\n                    alive.append((transport, proto, t0))\n            if alive:\n                connections[key] = alive\n\n        if connections:\n            self._cleanup_handle = self._loop.call_later(\n                self._keepalive_timeout, self._cleanup)\n\n        self._conns = connections\n        self._wr = weakref.ref(\n            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))\n\n    def _start_cleanup_task(self):\n        if self._cleanup_handle is None:\n            self._cleanup_handle = self._loop.call_later(\n                self._keepalive_timeout, self._cleanup)\n\n    def close(self):\n        \"\"\"Close all opened transports.\"\"\"\n        self._do_close(self._conns)\n\n    @staticmethod\n    def _do_close(conns):\n        for key, data in conns.items():\n            for transport, proto, td in data:\n                transport.close()\n\n        conns.clear()\n\n    def update_cookies(self, cookies):\n        \"\"\"Update shared cookies.\"\"\"\n        if isinstance(cookies, dict):\n            cookies = cookies.items()\n\n        for name, value in cookies:\n            if isinstance(value, http.cookies.Morsel):\n                # use dict method because SimpleCookie class modifies value\n                dict.__setitem__(self.cookies, name, value)\n            else:\n                self.cookies[name] = value\n\n    @asyncio.coroutine\n    def connect(self, req):\n        \"\"\"Get from pool or create new connection.\"\"\"\n        key = (req.host, req.port, req.ssl)\n\n        if self._share_cookies:\n            req.update_cookies(self.cookies.items())\n\n        transport, proto = self._get(key)\n        if transport is None:\n            try:\n                if self._conn_timeout:\n                    transport, proto = yield from asyncio.wait_for(\n                        self._create_connection(req),\n                        self._conn_timeout, loop=self._loop)\n                else:\n                    transport, proto = yield from self._create_connection(req)\n            except asyncio.TimeoutError as exc:\n                raise ClientTimeoutError() from exc\n            except OSError as exc:\n                raise ClientOSError() from exc\n\n        return Connection(self, key, req, transport, proto, self._loop)\n\n    def _get(self, key):\n        conns = self._conns.get(key)\n        while conns:\n            transport, proto, t0 = conns.pop()\n            if transport is not None and proto.is_connected():\n                if (time.time() - t0) > self._keepalive_timeout:\n                    transport.close()\n                    transport = None\n                else:\n                    return transport, proto\n\n        return None, None\n\n    def _release(self, key, req, transport, protocol, *, should_close=False):\n        resp = req.response\n\n        if not should_close:\n            if resp is not None:\n                if resp.message is None:\n                    should_close = True\n                else:\n                    should_close = resp.message.should_close\n\n            if self._force_close:\n                should_close = True\n\n        reader = protocol.reader\n        if should_close or (reader.output and not reader.output.at_eof()):\n            self._conns.pop(key, None)\n            transport.close()\n        else:\n            conns = self._conns.get(key)\n            if conns is None:\n                conns = self._conns[key] = []\n            conns.append((transport, protocol, time.time()))\n            reader.unset_parser()\n\n            self._start_cleanup_task()\n\n    def _create_connection(self, req, *args, **kwargs):\n        raise NotImplementedError()\n\n\nclass TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, ssl_context=None,\n                 **kwargs):\n        if not verify_ssl and ssl_context is not None:\n            raise ValueError(\n                \"Either disable ssl certificate validation by \"\n                \"verify_ssl=False or specify ssl_context, not both.\")\n\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._ssl_context = ssl_context\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def ssl_context(self):\n        \"\"\"SSLContext instance for https requests.\n\n        Lazy property, creates context on demand.\n        \"\"\"\n        if self._ssl_context is None:\n            if not self._verify_ssl:\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n            elif hasattr(ssl, 'create_default_context'):\n                # Python 3.4+\n                sslcontext = ssl.create_default_context()\n            else:  # pragma: no cover\n                # Fallback for Python 3.3.\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n                sslcontext.verify_mode = ssl.CERT_REQUIRED\n            self._ssl_context = sslcontext\n        return self._ssl_context\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        if req.ssl:\n            sslcontext = self.ssl_context\n        else:\n            sslcontext = None\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc\n\n\nclass ProxyConnector(TCPConnector):\n    \"\"\"Http Proxy connector.\n\n    :param str proxy: Proxy URL address. Only http proxy supported.\n    :param proxy_auth: (optional) Proxy HTTP Basic Auth\n    :type proxy_auth: aiohttp.helpers.BasicAuth\n    :param args: see :class:`TCPConnector`\n    :param kwargs: see :class:`TCPConnector`\n\n    Usage:\n\n    >>> conn = ProxyConnector(proxy=\"http://some.proxy.com\")\n    >>> resp = yield from request('GET', 'http://python.org', connector=conn)\n\n    \"\"\"\n\n    def __init__(self, proxy, *args, proxy_auth=None, **kwargs):\n        super().__init__(*args, **kwargs)\n        self._proxy = proxy\n        self._proxy_auth = proxy_auth\n        assert proxy.startswith('http://'), (\n            \"Only http proxy supported\", proxy)\n        assert proxy_auth is None or isinstance(proxy_auth, BasicAuth), (\n            \"proxy_auth must be None or BasicAuth() tuple\", proxy_auth)\n\n    @property\n    def proxy(self):\n        \"\"\"Proxy URL.\"\"\"\n        return self._proxy\n\n    @asyncio.coroutine\n    def _create_connection(self, req, **kwargs):\n        proxy_req = ClientRequest(\n            'GET', self._proxy,\n            headers={'Host': req.host},\n            auth=self._proxy_auth,\n            loop=self._loop)\n        try:\n            transport, proto = yield from super()._create_connection(proxy_req)\n        except OSError as exc:\n            raise ProxyConnectionError(*exc.args) from exc\n\n        req.path = '{scheme}://{host}{path}'.format(scheme=req.scheme,\n                                                    host=req.netloc,\n                                                    path=req.path)\n        if 'AUTHORIZATION' in proxy_req.headers:\n            auth = proxy_req.headers['AUTHORIZATION']\n            del proxy_req.headers['AUTHORIZATION']\n            req.headers['PROXY-AUTHORIZATION'] = auth\n\n        if req.ssl:\n            # For HTTPS requests over HTTP proxy\n            # we must notify proxy to tunnel connection\n            # so we send CONNECT command:\n            #   CONNECT www.python.org:443 HTTP/1.1\n            #   Host: www.python.org\n            #\n            # next we must do TLS handshake and so on\n            # to do this we must wrap raw socket into secure one\n            # asyncio handles this perfectly\n            proxy_req.method = 'CONNECT'\n            proxy_req.path = '{}:{}'.format(req.host, req.port)\n            key = (req.host, req.port, req.ssl)\n            conn = Connection(self, key, proxy_req,\n                              transport, proto, self._loop)\n            proxy_resp = proxy_req.send(conn.writer, conn.reader)\n            try:\n                resp = yield from proxy_resp.start(conn, True)\n            except:\n                proxy_resp.close()\n                conn.close()\n                raise\n            else:\n                if resp.status != 200:\n                    raise HttpProxyError(code=resp.status, message=resp.reason)\n                rawsock = transport.get_extra_info('socket', default=None)\n                if rawsock is None:\n                    raise RuntimeError(\n                        \"Transport does not expose socket instance\")\n                transport.pause_reading()\n                transport, proto = yield from self._loop.create_connection(\n                    self._factory, ssl=True, sock=rawsock,\n                    server_hostname=req.host, **kwargs)\n\n        return transport, proto\n\n\nclass UnixConnector(BaseConnector):\n    \"\"\"Unix socket connector.\n\n    :param str path: Unix socket path.\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n\n    Usage:\n\n    >>> conn = UnixConnector(path='/path/to/socket')\n    >>> resp = yield from request('GET', 'http://python.org', connector=conn)\n\n    \"\"\"\n\n    def __init__(self, path, *args, **kw):\n        super().__init__(*args, **kw)\n        self._path = path\n\n    @property\n    def path(self):\n        \"\"\"Path to unix socket.\"\"\"\n        return self._path\n\n    @asyncio.coroutine\n    def _create_connection(self, req, **kwargs):\n        return (yield from self._loop.create_unix_connection(\n            self._factory, self._path, **kwargs))\n",
            "header": {
                "file": {
                    "path": "aiohttp/connector.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "7937b92c",
                "new_commit_hash": "ce0801aa",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/aiohttp/connector.py"
            },
            "plus_file": {
                "path": "b/aiohttp/connector.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 223,
                            "length": 10
                        },
                        "new_range": {
                            "start": 223,
                            "length": 17
                        },
                        "section": "class TCPConnector(BaseConnector):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    \"\"\"",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def __init__(self, *args, verify_ssl=True,",
                                "type": "context"
                            },
                            {
                                "content": "                 resolve=False, family=socket.AF_INET, **kwargs):",
                                "type": "deleted"
                            },
                            {
                                "content": "                 resolve=False, family=socket.AF_INET, ssl_context=None,",
                                "type": "added"
                            },
                            {
                                "content": "                 **kwargs):",
                                "type": "added"
                            },
                            {
                                "content": "        if not verify_ssl and ssl_context is not None:",
                                "type": "added"
                            },
                            {
                                "content": "            raise ValueError(",
                                "type": "added"
                            },
                            {
                                "content": "                \"Either disable ssl certificate validation by \"",
                                "type": "added"
                            },
                            {
                                "content": "                \"verify_ssl=False or specify ssl_context, not both.\")",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        super().__init__(*args, **kwargs)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        self._verify_ssl = verify_ssl",
                                "type": "context"
                            },
                            {
                                "content": "        self._ssl_context = ssl_context",
                                "type": "added"
                            },
                            {
                                "content": "        self._family = family",
                                "type": "context"
                            },
                            {
                                "content": "        self._resolve = resolve",
                                "type": "context"
                            },
                            {
                                "content": "        self._resolved_hosts = {}",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "aiohttp/connector.py",
                            "type": "class",
                            "name": "TCPConnector",
                            "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 215,
                            "end_lineno": 311,
                            "parent": null
                        },
                        {
                            "file_name": "aiohttp/connector.py",
                            "type": "method",
                            "name": "TCPConnector.__init__",
                            "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 225,
                            "end_lineno": 232,
                            "parent": {
                                "file_name": "aiohttp/connector.py",
                                "type": "class",
                                "name": "TCPConnector",
                                "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 215,
                                "end_lineno": 311,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 236,
                            "length": 6
                        },
                        "new_range": {
                            "start": 243,
                            "length": 33
                        },
                        "section": "class TCPConnector(BaseConnector):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        \"\"\"Do check for ssl certifications?\"\"\"",
                                "type": "context"
                            },
                            {
                                "content": "        return self._verify_ssl",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    @property",
                                "type": "added"
                            },
                            {
                                "content": "    def ssl_context(self):",
                                "type": "added"
                            },
                            {
                                "content": "        \"\"\"SSLContext instance for https requests.",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        Lazy property, creates context on demand.",
                                "type": "added"
                            },
                            {
                                "content": "        \"\"\"",
                                "type": "added"
                            },
                            {
                                "content": "        if self._ssl_context is None:",
                                "type": "added"
                            },
                            {
                                "content": "            if not self._verify_ssl:",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.options |= ssl.OP_NO_SSLv2",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.options |= ssl.OP_NO_SSLv3",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.set_default_verify_paths()",
                                "type": "added"
                            },
                            {
                                "content": "            elif hasattr(ssl, 'create_default_context'):",
                                "type": "added"
                            },
                            {
                                "content": "                # Python 3.4+",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext = ssl.create_default_context()",
                                "type": "added"
                            },
                            {
                                "content": "            else:  # pragma: no cover",
                                "type": "added"
                            },
                            {
                                "content": "                # Fallback for Python 3.3.",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.options |= ssl.OP_NO_SSLv2",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.options |= ssl.OP_NO_SSLv3",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.set_default_verify_paths()",
                                "type": "added"
                            },
                            {
                                "content": "                sslcontext.verify_mode = ssl.CERT_REQUIRED",
                                "type": "added"
                            },
                            {
                                "content": "            self._ssl_context = sslcontext",
                                "type": "added"
                            },
                            {
                                "content": "        return self._ssl_context",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    @property",
                                "type": "context"
                            },
                            {
                                "content": "    def family(self):",
                                "type": "context"
                            },
                            {
                                "content": "        \"\"\"Socket family like AF_INET.\"\"\"",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "aiohttp/connector.py",
                            "type": "class",
                            "name": "TCPConnector",
                            "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, ssl_context=None,\n                 **kwargs):\n        if not verify_ssl and ssl_context is not None:\n            raise ValueError(\n                \"Either disable ssl certificate validation by \"\n                \"verify_ssl=False or specify ssl_context, not both.\")\n\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._ssl_context = ssl_context\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def ssl_context(self):\n        \"\"\"SSLContext instance for https requests.\n\n        Lazy property, creates context on demand.\n        \"\"\"\n        if self._ssl_context is None:\n            if not self._verify_ssl:\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n            elif hasattr(ssl, 'create_default_context'):\n                # Python 3.4+\n                sslcontext = ssl.create_default_context()\n            else:  # pragma: no cover\n                # Fallback for Python 3.3.\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n                sslcontext.verify_mode = ssl.CERT_REQUIRED\n            self._ssl_context = sslcontext\n        return self._ssl_context\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        if req.ssl:\n            sslcontext = self.ssl_context\n        else:\n            sslcontext = None\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 215,
                            "end_lineno": 344,
                            "parent": null
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "aiohttp/connector.py",
                            "type": "method",
                            "name": "TCPConnector.ssl_context",
                            "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, ssl_context=None,\n                 **kwargs):\n        if not verify_ssl and ssl_context is not None:\n            raise ValueError(\n                \"Either disable ssl certificate validation by \"\n                \"verify_ssl=False or specify ssl_context, not both.\")\n\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._ssl_context = ssl_context\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def ssl_context(self):\n        \"\"\"SSLContext instance for https requests.\n\n        Lazy property, creates context on demand.\n        \"\"\"\n        if self._ssl_context is None:\n            if not self._verify_ssl:\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n            elif hasattr(ssl, 'create_default_context'):\n                # Python 3.4+\n                sslcontext = ssl.create_default_context()\n            else:  # pragma: no cover\n                # Fallback for Python 3.3.\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n                sslcontext.verify_mode = ssl.CERT_REQUIRED\n            self._ssl_context = sslcontext\n        return self._ssl_context\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        if req.ssl:\n            sslcontext = self.ssl_context\n        else:\n            sslcontext = None\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 247,
                            "end_lineno": 271,
                            "parent": {
                                "file_name": "aiohttp/connector.py",
                                "type": "class",
                                "name": "TCPConnector",
                                "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, ssl_context=None,\n                 **kwargs):\n        if not verify_ssl and ssl_context is not None:\n            raise ValueError(\n                \"Either disable ssl certificate validation by \"\n                \"verify_ssl=False or specify ssl_context, not both.\")\n\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._ssl_context = ssl_context\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def ssl_context(self):\n        \"\"\"SSLContext instance for https requests.\n\n        Lazy property, creates context on demand.\n        \"\"\"\n        if self._ssl_context is None:\n            if not self._verify_ssl:\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n            elif hasattr(ssl, 'create_default_context'):\n                # Python 3.4+\n                sslcontext = ssl.create_default_context()\n            else:  # pragma: no cover\n                # Fallback for Python 3.3.\n                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n                sslcontext.options |= ssl.OP_NO_SSLv2\n                sslcontext.options |= ssl.OP_NO_SSLv3\n                sslcontext.options |= getattr(ssl, \"OP_NO_COMPRESSION\", 0)\n                sslcontext.set_default_verify_paths()\n                sslcontext.verify_mode = ssl.CERT_REQUIRED\n            self._ssl_context = sslcontext\n        return self._ssl_context\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        if req.ssl:\n            sslcontext = self.ssl_context\n        else:\n            sslcontext = None\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 215,
                                "end_lineno": 344,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 288,
                            "length": 11
                        },
                        "new_range": {
                            "start": 322,
                            "length": 10
                        },
                        "section": "class TCPConnector(BaseConnector):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        Has same keyword arguments as BaseEventLoop.create_connection.",
                                "type": "context"
                            },
                            {
                                "content": "        \"\"\"",
                                "type": "context"
                            },
                            {
                                "content": "        sslcontext = req.ssl",
                                "type": "deleted"
                            },
                            {
                                "content": "        if req.ssl and not self._verify_ssl:",
                                "type": "deleted"
                            },
                            {
                                "content": "            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)",
                                "type": "deleted"
                            },
                            {
                                "content": "            sslcontext.options |= ssl.OP_NO_SSLv2",
                                "type": "deleted"
                            },
                            {
                                "content": "            sslcontext.set_default_verify_paths()",
                                "type": "deleted"
                            },
                            {
                                "content": "        if req.ssl:",
                                "type": "added"
                            },
                            {
                                "content": "            sslcontext = self.ssl_context",
                                "type": "added"
                            },
                            {
                                "content": "        else:",
                                "type": "added"
                            },
                            {
                                "content": "            sslcontext = None",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        hosts = yield from self._resolve_host(req.host, req.port)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "aiohttp/connector.py",
                            "type": "class",
                            "name": "TCPConnector",
                            "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 215,
                            "end_lineno": 311,
                            "parent": null
                        },
                        {
                            "file_name": "aiohttp/connector.py",
                            "type": "method",
                            "name": "TCPConnector._create_connection",
                            "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 286,
                            "end_lineno": 311,
                            "parent": {
                                "file_name": "aiohttp/connector.py",
                                "type": "class",
                                "name": "TCPConnector",
                                "content": "class TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 215,
                                "end_lineno": 311,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "\"\"\"Tests of http client with custom Connector\"\"\"\n\nimport asyncio\nimport http.cookies\nimport gc\nimport time\nimport socket\nimport unittest\nfrom unittest import mock\n\nimport aiohttp\nfrom aiohttp import client\nfrom aiohttp import test_utils\nfrom aiohttp.client import ClientResponse, ClientRequest\nfrom aiohttp.connector import Connection\n\nfrom tests.test_client_functional import Functional\n\n\nclass HttpConnectionTests(unittest.TestCase):\n\n    def setUp(self):\n        self.key = object()\n        self.connector = mock.Mock()\n        self.request = mock.Mock()\n        self.transport = mock.Mock()\n        self.protocol = mock.Mock()\n        self.loop = mock.Mock()\n\n    def test_del(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        del conn\n        self.assertTrue(self.transport.close.called)\n\n    def test_close(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.close()\n        self.assertIsNone(conn._transport)\n        self.connector._release.assert_called_with(\n            self.key, self.request, self.transport, self.protocol,\n            should_close=True)\n\n    def test_release(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.release()\n        self.assertFalse(self.transport.close.called)\n        self.assertIsNone(conn._transport)\n        self.connector._release.assert_called_with(\n            self.key, self.request, self.transport, self.protocol)\n\n    def test_release_released(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.release()\n        self.connector._release.reset_mock()\n        conn.release()\n        self.assertFalse(self.transport.close.called)\n        self.assertIsNone(conn._transport)\n        self.assertFalse(self.connector._release.called)\n\n    def test_no_share_cookies(self):\n        connector = aiohttp.BaseConnector(share_cookies=False, loop=self.loop)\n\n        conn = Connection(\n            connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        self.assertEqual(connector.cookies, {})\n        conn.share_cookies({'c1': 'cookie1'})\n        self.assertEqual(connector.cookies, {})\n\n    def test_share_cookies(self):\n        connector = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n\n        conn = Connection(\n            connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        self.assertEqual(connector.cookies, {})\n        conn.share_cookies({'c1': 'cookie1'})\n        self.assertEqual(connector.cookies,\n                         http.cookies.SimpleCookie({'c1': 'cookie1'}))\n\n\nclass BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n\nclass HttpClientConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n    def tearDown(self):\n        # just in case if we have transport close callbacks\n        test_utils.run_briefly(self.loop)\n\n        self.loop.close()\n        gc.collect()\n\n    def test_tcp_connector(self):\n        with test_utils.run_server(self.loop, router=Functional) as httpd:\n            r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=aiohttp.TCPConnector(loop=self.loop),\n                    loop=self.loop))\n            content = self.loop.run_until_complete(r.content.read())\n            content = content.decode()\n            self.assertEqual(r.status, 200)\n            r.close()\n\n    @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix')\n    def test_unix_connector(self):\n        path = '/tmp/aiohttp_unix.sock'\n\n        connector = aiohttp.UnixConnector(path, loop=self.loop)\n        self.assertEqual(path, connector.path)\n\n        with test_utils.run_server(\n                self.loop, listen_addr=path, router=Functional) as httpd:\n            r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=connector,\n                    loop=self.loop))\n            content = self.loop.run_until_complete(r.content.read())\n            content = content.decode()\n            self.assertEqual(r.status, 200)\n            r.close()\n\n\nclass ProxyConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n    def tearDown(self):\n        # just in case if we have transport close callbacks\n        test_utils.run_briefly(self.loop)\n\n        self.loop.close()\n        gc.collect()\n\n    def _fake_coroutine(self, mock, return_value):\n\n        def coro(*args, **kw):\n            if isinstance(return_value, Exception):\n                raise return_value\n            return return_value\n            yield\n        mock.side_effect = coro\n\n    def test_ctor(self):\n        with self.assertRaises(AssertionError):\n            aiohttp.ProxyConnector('https://localhost:8118', loop=self.loop)\n\n    def test_ctor2(self):\n        connector = aiohttp.ProxyConnector('http://localhost:8118',\n                                           loop=self.loop)\n\n        self.assertEqual('http://localhost:8118', connector.proxy)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_connect(self, ClientRequestMock):\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertEqual(req.path, '/')\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=loop_mock)\n        self.assertIs(loop_mock, connector._loop)\n\n        resolve_host = unittest.mock.Mock()\n        self._fake_coroutine(resolve_host, [unittest.mock.MagicMock()])\n        connector._resolve_host = resolve_host\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n        conn = self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertIs(conn._transport, tr)\n        self.assertIs(conn._protocol, proto)\n\n        # resolve_host.assert_called_once_with('proxy.example.com', 80)\n        self.assertEqual(tr.mock_calls, [])\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://proxy.example.com',\n            auth=None,\n            headers={'Host': 'www.python.org'},\n            loop=loop_mock)\n\n    def test_proxy_auth(self):\n        with self.assertRaises(AssertionError) as ctx:\n            aiohttp.ProxyConnector('http://proxy.example.com',\n                                   proxy_auth=('user', 'pass'),\n                                   loop=unittest.mock.Mock())\n        self.assertEqual(ctx.exception.args[0],\n                         (\"proxy_auth must be None or BasicAuth() tuple\",\n                          ('user', 'pass')))\n\n    def test_proxy_connection_error(self):\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=self.loop)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, OSError('dont take it serious'))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        expected_headers = dict(req.headers)\n        with self.assertRaises(aiohttp.ProxyConnectionError):\n            self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.path, '/')\n        self.assertEqual(dict(req.headers), expected_headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  auth=aiohttp.helpers.BasicAuth('user',\n                                                                 'pass'))\n        ClientRequestMock.return_value = proxy_req\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock,\n            proxy_auth=aiohttp.helpers.BasicAuth('user', 'pass'))\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, [unittest.mock.MagicMock()])\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', req.headers)\n        self.loop.run_until_complete(connector.connect(req))\n\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertIn('PROXY-AUTHORIZATION', req.headers)\n        self.assertNotIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://proxy.example.com',\n            auth=aiohttp.helpers.BasicAuth('user', 'pass'),\n            loop=unittest.mock.ANY, headers=unittest.mock.ANY)\n\n    def test_auth_utf8(self):\n        proxy_req = ClientRequest(\n            'GET', 'http://proxy.example.com',\n            auth=aiohttp.helpers.BasicAuth('юзер', 'пасс', 'utf-8'))\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth_from_url(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://user:pass@proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://user:pass@proxy.example.com', loop=loop_mock)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, [unittest.mock.MagicMock()])\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', req.headers)\n        self.loop.run_until_complete(connector.connect(req))\n\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertIn('PROXY-AUTHORIZATION', req.headers)\n        self.assertNotIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://user:pass@proxy.example.com',\n            auth=None, loop=unittest.mock.ANY, headers=unittest.mock.ANY)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth__not_modifying_request(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://user:pass@proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n        proxy_req_headers = dict(proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://user:pass@proxy.example.com', loop=loop_mock)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, OSError('nothing personal'))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        req_headers = dict(req.headers)\n        with self.assertRaises(aiohttp.ProxyConnectionError):\n            self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.headers, req_headers)\n        self.assertEqual(req.path, '/')\n        self.assertEqual(proxy_req.headers, proxy_req_headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        self.loop.run_until_complete(connector._create_connection(req))\n\n        self.assertEqual(proxy_req.method, 'CONNECT')\n        self.assertEqual(proxy_req.path, 'www.python.org:443')\n        tr.pause_reading.assert_called_once_with()\n        tr.get_extra_info.assert_called_once_with('socket', default=None)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_runtime_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(\n                RuntimeError, \"Transport does not expose socket instance\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_http_proxy_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(\n            start_mock, unittest.mock.Mock(status=400, reason='bad request'))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(\n                aiohttp.HttpProxyError, \"400, message='bad request'\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_resp_start_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, OSError(\"error message\"))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(OSError, \"error message\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_request_port(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://localhost:1234/path')\n        self.loop.run_until_complete(connector._create_connection(req))\n        self.assertEqual(req.path, 'http://localhost:1234/path')\n",
            "new_file_content": "\"\"\"Tests of http client with custom Connector\"\"\"\n\nimport asyncio\nimport http.cookies\nimport gc\nimport time\nimport socket\nimport unittest\nimport ssl\nfrom unittest import mock\n\nimport aiohttp\nfrom aiohttp import client\nfrom aiohttp import test_utils\nfrom aiohttp.client import ClientResponse, ClientRequest\nfrom aiohttp.connector import Connection\n\nfrom tests.test_client_functional import Functional\n\n\nclass HttpConnectionTests(unittest.TestCase):\n\n    def setUp(self):\n        self.key = object()\n        self.connector = mock.Mock()\n        self.request = mock.Mock()\n        self.transport = mock.Mock()\n        self.protocol = mock.Mock()\n        self.loop = mock.Mock()\n\n    def test_del(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        del conn\n        self.assertTrue(self.transport.close.called)\n\n    def test_close(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.close()\n        self.assertIsNone(conn._transport)\n        self.connector._release.assert_called_with(\n            self.key, self.request, self.transport, self.protocol,\n            should_close=True)\n\n    def test_release(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.release()\n        self.assertFalse(self.transport.close.called)\n        self.assertIsNone(conn._transport)\n        self.connector._release.assert_called_with(\n            self.key, self.request, self.transport, self.protocol)\n\n    def test_release_released(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.release()\n        self.connector._release.reset_mock()\n        conn.release()\n        self.assertFalse(self.transport.close.called)\n        self.assertIsNone(conn._transport)\n        self.assertFalse(self.connector._release.called)\n\n    def test_no_share_cookies(self):\n        connector = aiohttp.BaseConnector(share_cookies=False, loop=self.loop)\n\n        conn = Connection(\n            connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        self.assertEqual(connector.cookies, {})\n        conn.share_cookies({'c1': 'cookie1'})\n        self.assertEqual(connector.cookies, {})\n\n    def test_share_cookies(self):\n        connector = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n\n        conn = Connection(\n            connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        self.assertEqual(connector.cookies, {})\n        conn.share_cookies({'c1': 'cookie1'})\n        self.assertEqual(connector.cookies,\n                         http.cookies.SimpleCookie({'c1': 'cookie1'}))\n\n\nclass BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)\n\n\nclass HttpClientConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n    def tearDown(self):\n        # just in case if we have transport close callbacks\n        test_utils.run_briefly(self.loop)\n\n        self.loop.close()\n        gc.collect()\n\n    def test_tcp_connector(self):\n        with test_utils.run_server(self.loop, router=Functional) as httpd:\n            r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=aiohttp.TCPConnector(loop=self.loop),\n                    loop=self.loop))\n            content = self.loop.run_until_complete(r.content.read())\n            content = content.decode()\n            self.assertEqual(r.status, 200)\n            r.close()\n\n    @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix')\n    def test_unix_connector(self):\n        path = '/tmp/aiohttp_unix.sock'\n\n        connector = aiohttp.UnixConnector(path, loop=self.loop)\n        self.assertEqual(path, connector.path)\n\n        with test_utils.run_server(\n                self.loop, listen_addr=path, router=Functional) as httpd:\n            r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=connector,\n                    loop=self.loop))\n            content = self.loop.run_until_complete(r.content.read())\n            content = content.decode()\n            self.assertEqual(r.status, 200)\n            r.close()\n\n\nclass ProxyConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n    def tearDown(self):\n        # just in case if we have transport close callbacks\n        test_utils.run_briefly(self.loop)\n\n        self.loop.close()\n        gc.collect()\n\n    def _fake_coroutine(self, mock, return_value):\n\n        def coro(*args, **kw):\n            if isinstance(return_value, Exception):\n                raise return_value\n            return return_value\n            yield\n        mock.side_effect = coro\n\n    def test_ctor(self):\n        with self.assertRaises(AssertionError):\n            aiohttp.ProxyConnector('https://localhost:8118', loop=self.loop)\n\n    def test_ctor2(self):\n        connector = aiohttp.ProxyConnector('http://localhost:8118',\n                                           loop=self.loop)\n\n        self.assertEqual('http://localhost:8118', connector.proxy)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_connect(self, ClientRequestMock):\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertEqual(req.path, '/')\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=loop_mock)\n        self.assertIs(loop_mock, connector._loop)\n\n        resolve_host = unittest.mock.Mock()\n        self._fake_coroutine(resolve_host, [unittest.mock.MagicMock()])\n        connector._resolve_host = resolve_host\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n        conn = self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertIs(conn._transport, tr)\n        self.assertIs(conn._protocol, proto)\n\n        # resolve_host.assert_called_once_with('proxy.example.com', 80)\n        self.assertEqual(tr.mock_calls, [])\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://proxy.example.com',\n            auth=None,\n            headers={'Host': 'www.python.org'},\n            loop=loop_mock)\n\n    def test_proxy_auth(self):\n        with self.assertRaises(AssertionError) as ctx:\n            aiohttp.ProxyConnector('http://proxy.example.com',\n                                   proxy_auth=('user', 'pass'),\n                                   loop=unittest.mock.Mock())\n        self.assertEqual(ctx.exception.args[0],\n                         (\"proxy_auth must be None or BasicAuth() tuple\",\n                          ('user', 'pass')))\n\n    def test_proxy_connection_error(self):\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=self.loop)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, OSError('dont take it serious'))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        expected_headers = dict(req.headers)\n        with self.assertRaises(aiohttp.ProxyConnectionError):\n            self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.path, '/')\n        self.assertEqual(dict(req.headers), expected_headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  auth=aiohttp.helpers.BasicAuth('user',\n                                                                 'pass'))\n        ClientRequestMock.return_value = proxy_req\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock,\n            proxy_auth=aiohttp.helpers.BasicAuth('user', 'pass'))\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, [unittest.mock.MagicMock()])\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', req.headers)\n        self.loop.run_until_complete(connector.connect(req))\n\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertIn('PROXY-AUTHORIZATION', req.headers)\n        self.assertNotIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://proxy.example.com',\n            auth=aiohttp.helpers.BasicAuth('user', 'pass'),\n            loop=unittest.mock.ANY, headers=unittest.mock.ANY)\n\n    def test_auth_utf8(self):\n        proxy_req = ClientRequest(\n            'GET', 'http://proxy.example.com',\n            auth=aiohttp.helpers.BasicAuth('юзер', 'пасс', 'utf-8'))\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth_from_url(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://user:pass@proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://user:pass@proxy.example.com', loop=loop_mock)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, [unittest.mock.MagicMock()])\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', req.headers)\n        self.loop.run_until_complete(connector.connect(req))\n\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertIn('PROXY-AUTHORIZATION', req.headers)\n        self.assertNotIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://user:pass@proxy.example.com',\n            auth=None, loop=unittest.mock.ANY, headers=unittest.mock.ANY)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth__not_modifying_request(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://user:pass@proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n        proxy_req_headers = dict(proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://user:pass@proxy.example.com', loop=loop_mock)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, OSError('nothing personal'))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        req_headers = dict(req.headers)\n        with self.assertRaises(aiohttp.ProxyConnectionError):\n            self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.headers, req_headers)\n        self.assertEqual(req.path, '/')\n        self.assertEqual(proxy_req.headers, proxy_req_headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        self.loop.run_until_complete(connector._create_connection(req))\n\n        self.assertEqual(proxy_req.method, 'CONNECT')\n        self.assertEqual(proxy_req.path, 'www.python.org:443')\n        tr.pause_reading.assert_called_once_with()\n        tr.get_extra_info.assert_called_once_with('socket', default=None)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_runtime_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(\n                RuntimeError, \"Transport does not expose socket instance\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_http_proxy_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(\n            start_mock, unittest.mock.Mock(status=400, reason='bad request'))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(\n                aiohttp.HttpProxyError, \"400, message='bad request'\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_resp_start_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, OSError(\"error message\"))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(OSError, \"error message\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_request_port(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://localhost:1234/path')\n        self.loop.run_until_complete(connector._create_connection(req))\n        self.assertEqual(req.path, 'http://localhost:1234/path')\n",
            "header": {
                "file": {
                    "path": "tests/test_connector.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "c69ce447",
                "new_commit_hash": "67ae83c0",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/tests/test_connector.py"
            },
            "plus_file": {
                "path": "b/tests/test_connector.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 6,
                            "length": 6
                        },
                        "new_range": {
                            "start": 6,
                            "length": 7
                        },
                        "section": "import gc"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "import time",
                                "type": "context"
                            },
                            {
                                "content": "import socket",
                                "type": "context"
                            },
                            {
                                "content": "import unittest",
                                "type": "context"
                            },
                            {
                                "content": "import ssl",
                                "type": "added"
                            },
                            {
                                "content": "from unittest import mock",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "import aiohttp",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [
                        {
                            "file_name": "tests/test_connector.py",
                            "type": "import",
                            "name": "ssl",
                            "content": "import ssl",
                            "ast_type_str": "Import",
                            "start_lineno": 9,
                            "end_lineno": 9,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 312,
                            "length": 6
                        },
                        "new_range": {
                            "start": 313,
                            "length": 22
                        },
                        "section": "class BaseConnectorTests(unittest.TestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        conn.clear_resolved_hosts()",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(conn.resolved_hosts, {})",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_ambigous_verify_ssl_and_ssl_context(self):",
                                "type": "added"
                            },
                            {
                                "content": "        with self.assertRaises(ValueError):",
                                "type": "added"
                            },
                            {
                                "content": "            aiohttp.TCPConnector(",
                                "type": "added"
                            },
                            {
                                "content": "                verify_ssl=False,",
                                "type": "added"
                            },
                            {
                                "content": "                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def test_dont_recreate_ssl_context(self):",
                                "type": "added"
                            },
                            {
                                "content": "        conn = aiohttp.TCPConnector(loop=self.loop)",
                                "type": "added"
                            },
                            {
                                "content": "        ctx = conn.ssl_context",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertIs(ctx, conn.ssl_context)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    def test_respect_precreated_ssl_context(self):",
                                "type": "added"
                            },
                            {
                                "content": "        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)",
                                "type": "added"
                            },
                            {
                                "content": "        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertIs(ctx, conn.ssl_context)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "class HttpClientConnectorTests(unittest.TestCase):",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "tests/test_connector.py",
                            "type": "class",
                            "name": "BaseConnectorTests",
                            "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 91,
                            "end_lineno": 330,
                            "parent": null
                        }
                    ],
                    "added_entities": [
                        {
                            "file_name": "tests/test_connector.py",
                            "type": "method",
                            "name": "BaseConnectorTests.test_respect_precreated_ssl_context",
                            "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 327,
                            "end_lineno": 330,
                            "parent": {
                                "file_name": "tests/test_connector.py",
                                "type": "class",
                                "name": "BaseConnectorTests",
                                "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 91,
                                "end_lineno": 330,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "tests/test_connector.py",
                            "type": "method",
                            "name": "BaseConnectorTests.test_dont_recreate_ssl_context",
                            "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 322,
                            "end_lineno": 325,
                            "parent": {
                                "file_name": "tests/test_connector.py",
                                "type": "class",
                                "name": "BaseConnectorTests",
                                "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 91,
                                "end_lineno": 330,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "tests/test_connector.py",
                            "type": "method",
                            "name": "BaseConnectorTests.test_ambigous_verify_ssl_and_ssl_context",
                            "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 316,
                            "end_lineno": 320,
                            "parent": {
                                "file_name": "tests/test_connector.py",
                                "type": "class",
                                "name": "BaseConnectorTests",
                                "content": "class BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 91,
                                "end_lineno": 330,
                                "parent": null
                            }
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "980c0d0bd3636a79b29b28b5bdde7dcd796736b1^",
    "new_commit_hash": "980c0d0bd3636a79b29b28b5bdde7dcd796736b1",
    "commit_message": "Merge pull request #211 from KeepSafe/Issue_206_ssl_context\n\nAdd ssl_context to TCPConnector",
    "commit_date": "2014-12-29T20:14:14+02:00",
    "metadata": {}
}
{
    "repo_name": "aiohttp",
    "new_commit_hash": "980c0d0bd3636a79b29b28b5bdde7dcd796736b1",
    "test_file_codes": [
        "\"\"\"Tests of http client with custom Connector\"\"\"\n\nimport asyncio\nimport http.cookies\nimport gc\nimport time\nimport socket\nimport unittest\nimport ssl\nfrom unittest import mock\n\nimport aiohttp\nfrom aiohttp import client\nfrom aiohttp import test_utils\nfrom aiohttp.client import ClientResponse, ClientRequest\nfrom aiohttp.connector import Connection\n\nfrom tests.test_client_functional import Functional\n\n\nclass HttpConnectionTests(unittest.TestCase):\n\n    def setUp(self):\n        self.key = object()\n        self.connector = mock.Mock()\n        self.request = mock.Mock()\n        self.transport = mock.Mock()\n        self.protocol = mock.Mock()\n        self.loop = mock.Mock()\n\n    def test_del(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        del conn\n        self.assertTrue(self.transport.close.called)\n\n    def test_close(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.close()\n        self.assertIsNone(conn._transport)\n        self.connector._release.assert_called_with(\n            self.key, self.request, self.transport, self.protocol,\n            should_close=True)\n\n    def test_release(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.release()\n        self.assertFalse(self.transport.close.called)\n        self.assertIsNone(conn._transport)\n        self.connector._release.assert_called_with(\n            self.key, self.request, self.transport, self.protocol)\n\n    def test_release_released(self):\n        conn = Connection(\n            self.connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        conn.release()\n        self.connector._release.reset_mock()\n        conn.release()\n        self.assertFalse(self.transport.close.called)\n        self.assertIsNone(conn._transport)\n        self.assertFalse(self.connector._release.called)\n\n    def test_no_share_cookies(self):\n        connector = aiohttp.BaseConnector(share_cookies=False, loop=self.loop)\n\n        conn = Connection(\n            connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        self.assertEqual(connector.cookies, {})\n        conn.share_cookies({'c1': 'cookie1'})\n        self.assertEqual(connector.cookies, {})\n\n    def test_share_cookies(self):\n        connector = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n\n        conn = Connection(\n            connector, self.key, self.request,\n            self.transport, self.protocol, self.loop)\n        self.assertEqual(connector.cookies, {})\n        conn.share_cookies({'c1': 'cookie1'})\n        self.assertEqual(connector.cookies,\n                         http.cookies.SimpleCookie({'c1': 'cookie1'}))\n\n\nclass BaseConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n        self.transport = unittest.mock.Mock()\n        self.stream = aiohttp.StreamParser()\n        self.response = ClientResponse('get', 'http://python.org')\n\n    def tearDown(self):\n        self.loop.close()\n\n    def test_del(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        transp = unittest.mock.Mock()\n        conn._conns['a'] = [(transp, 'proto', 123)]\n\n        conns_impl = conn._conns\n        del conn\n        self.assertFalse(conns_impl)\n        transp.close.assert_called_with()\n\n    def test_create_conn(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertRaises(\n            NotImplementedError, conn._create_connection, object())\n\n    @unittest.mock.patch('aiohttp.connector.asyncio')\n    def test_ctor_loop(self, asyncio):\n        session = aiohttp.BaseConnector()\n        self.assertIs(session._loop, asyncio.get_event_loop.return_value)\n\n    def test_close(self):\n        tr = unittest.mock.Mock()\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._conns[1] = [(tr, object(), object())]\n        conn.close()\n\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    def test_get(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time())]\n        self.assertEqual(conn._get(1), (tr, proto))\n\n    def test_get_expired(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        self.assertEqual(conn._get(1), (None, None))\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._conns[1] = [(tr, proto, time.time() - 1000)]\n        self.assertEqual(conn._get(1), (None, None))\n        self.assertEqual(conn._conns[1], [])\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        conn._start_cleanup_task = unittest.mock.Mock()\n        req = unittest.mock.Mock()\n        resp = req.response = unittest.mock.Mock()\n        resp.message.should_close = False\n\n        # cookies = resp.cookies = http.cookies.SimpleCookie()\n        # cookies['c1'] = 'cookie1'\n        # cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns[1][0], (tr, proto, 10))\n        # self.assertEqual(conn.cookies, dict(cookies.items()))\n        self.assertTrue(conn._start_cleanup_task.called)\n\n    def test_release_close(self):\n        conn = aiohttp.BaseConnector(share_cookies=True, loop=self.loop)\n        req = unittest.mock.Mock()\n        resp = unittest.mock.Mock()\n        resp.message.should_close = True\n        req.response = resp\n\n        cookies = resp.cookies = http.cookies.SimpleCookie()\n        cookies['c1'] = 'cookie1'\n        cookies['c2'] = 'cookie2'\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertFalse(conn._conns)\n        self.assertTrue(tr.close.called)\n\n    @mock.patch('aiohttp.connector.time')\n    def test_release_not_started(self, m_time):\n        m_time.time.return_value = 10\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertEqual(conn._conns, {1: [(tr, proto, 10)]})\n        self.assertFalse(tr.close.called)\n\n    def test_release_not_opened(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        req = unittest.mock.Mock()\n        req.response = unittest.mock.Mock()\n        req.response.message = None\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        conn._release(1, req, tr, proto)\n        self.assertTrue(tr.close.called)\n\n    def test_connect(self):\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        proto.is_connected.return_value = True\n\n        class Req:\n            host = 'host'\n            port = 80\n            ssl = False\n\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        key = ('host', 80, False)\n        conn._conns[key] = [(tr, proto, time.time())]\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_result((tr, proto))\n\n        connection = self.loop.run_until_complete(conn.connect(Req()))\n        self.assertFalse(conn._create_connection.called)\n        self.assertEqual(connection._transport, tr)\n        self.assertEqual(connection._protocol, proto)\n        self.assertIsInstance(connection, Connection)\n\n    def test_connect_timeout(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(\n            asyncio.TimeoutError())\n\n        with self.assertRaises(aiohttp.ClientTimeoutError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_connect_oserr(self):\n        conn = aiohttp.BaseConnector(loop=self.loop)\n        conn._create_connection = unittest.mock.Mock()\n        conn._create_connection.return_value = asyncio.Future(loop=self.loop)\n        conn._create_connection.return_value.set_exception(OSError())\n\n        with self.assertRaises(aiohttp.ClientOSError):\n            req = unittest.mock.Mock()\n            self.loop.run_until_complete(conn.connect(req))\n\n    def test_start_cleanup_task(self):\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        self.assertIsNone(conn._cleanup_handle)\n\n        conn._start_cleanup_task()\n        self.assertIsNotNone(conn._cleanup_handle)\n        loop.call_later.assert_called_with(\n            conn._keepalive_timeout, conn._cleanup)\n\n    @unittest.mock.patch('aiohttp.connector.time')\n    def test_cleanup(self, time):\n        time.time.return_value = 300\n\n        testset = {\n            1: [(unittest.mock.Mock(), unittest.mock.Mock(), 10),\n                (unittest.mock.Mock(), unittest.mock.Mock(), 300),\n                (None, unittest.mock.Mock(), 300)],\n        }\n        testset[1][0][1].is_connected.return_value = True\n        testset[1][1][1].is_connected.return_value = False\n\n        loop = unittest.mock.Mock()\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        existing_handle = conn._cleanup_handle = unittest.mock.Mock()\n\n        conn._cleanup()\n        self.assertTrue(existing_handle.cancel.called)\n        self.assertEqual(conn._conns, {})\n        self.assertIsNone(conn._cleanup_handle)\n\n        testset = {1: [(unittest.mock.Mock(), unittest.mock.Mock(), 300)]}\n        testset[1][0][1].is_connected.return_value = True\n\n        conn = aiohttp.BaseConnector(loop=loop)\n        conn._conns = testset\n        conn._cleanup()\n        self.assertEqual(conn._conns, testset)\n\n        self.assertIsNotNone(conn._cleanup_handle)\n\n    def test_tcp_connector_ctor(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        self.assertTrue(conn.verify_ssl)\n        self.assertFalse(conn.resolve)\n        self.assertEqual(conn.family, socket.AF_INET)\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_tcp_connector_clear_resolved_hosts(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        info = object()\n        conn._resolved_hosts[('localhost', 123)] = info\n        conn._resolved_hosts[('localhost', 124)] = info\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts('localhost', 123)\n        self.assertEqual(\n            conn.resolved_hosts, {('localhost', 124): info})\n        conn.clear_resolved_hosts()\n        self.assertEqual(conn.resolved_hosts, {})\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n            aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n        ctx = conn.ssl_context\n        self.assertIs(ctx, conn.ssl_context)\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n        conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n        self.assertIs(ctx, conn.ssl_context)\n\n\nclass HttpClientConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n    def tearDown(self):\n        # just in case if we have transport close callbacks\n        test_utils.run_briefly(self.loop)\n\n        self.loop.close()\n        gc.collect()\n\n    def test_tcp_connector(self):\n        with test_utils.run_server(self.loop, router=Functional) as httpd:\n            r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=aiohttp.TCPConnector(loop=self.loop),\n                    loop=self.loop))\n            content = self.loop.run_until_complete(r.content.read())\n            content = content.decode()\n            self.assertEqual(r.status, 200)\n            r.close()\n\n    @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix')\n    def test_unix_connector(self):\n        path = '/tmp/aiohttp_unix.sock'\n\n        connector = aiohttp.UnixConnector(path, loop=self.loop)\n        self.assertEqual(path, connector.path)\n\n        with test_utils.run_server(\n                self.loop, listen_addr=path, router=Functional) as httpd:\n            r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=connector,\n                    loop=self.loop))\n            content = self.loop.run_until_complete(r.content.read())\n            content = content.decode()\n            self.assertEqual(r.status, 200)\n            r.close()\n\n\nclass ProxyConnectorTests(unittest.TestCase):\n\n    def setUp(self):\n        self.loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(None)\n\n    def tearDown(self):\n        # just in case if we have transport close callbacks\n        test_utils.run_briefly(self.loop)\n\n        self.loop.close()\n        gc.collect()\n\n    def _fake_coroutine(self, mock, return_value):\n\n        def coro(*args, **kw):\n            if isinstance(return_value, Exception):\n                raise return_value\n            return return_value\n            yield\n        mock.side_effect = coro\n\n    def test_ctor(self):\n        with self.assertRaises(AssertionError):\n            aiohttp.ProxyConnector('https://localhost:8118', loop=self.loop)\n\n    def test_ctor2(self):\n        connector = aiohttp.ProxyConnector('http://localhost:8118',\n                                           loop=self.loop)\n\n        self.assertEqual('http://localhost:8118', connector.proxy)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_connect(self, ClientRequestMock):\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertEqual(req.path, '/')\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=loop_mock)\n        self.assertIs(loop_mock, connector._loop)\n\n        resolve_host = unittest.mock.Mock()\n        self._fake_coroutine(resolve_host, [unittest.mock.MagicMock()])\n        connector._resolve_host = resolve_host\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n        conn = self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertIs(conn._transport, tr)\n        self.assertIs(conn._protocol, proto)\n\n        # resolve_host.assert_called_once_with('proxy.example.com', 80)\n        self.assertEqual(tr.mock_calls, [])\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://proxy.example.com',\n            auth=None,\n            headers={'Host': 'www.python.org'},\n            loop=loop_mock)\n\n    def test_proxy_auth(self):\n        with self.assertRaises(AssertionError) as ctx:\n            aiohttp.ProxyConnector('http://proxy.example.com',\n                                   proxy_auth=('user', 'pass'),\n                                   loop=unittest.mock.Mock())\n        self.assertEqual(ctx.exception.args[0],\n                         (\"proxy_auth must be None or BasicAuth() tuple\",\n                          ('user', 'pass')))\n\n    def test_proxy_connection_error(self):\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=self.loop)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, OSError('dont take it serious'))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        expected_headers = dict(req.headers)\n        with self.assertRaises(aiohttp.ProxyConnectionError):\n            self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.path, '/')\n        self.assertEqual(dict(req.headers), expected_headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  auth=aiohttp.helpers.BasicAuth('user',\n                                                                 'pass'))\n        ClientRequestMock.return_value = proxy_req\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock,\n            proxy_auth=aiohttp.helpers.BasicAuth('user', 'pass'))\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, [unittest.mock.MagicMock()])\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', req.headers)\n        self.loop.run_until_complete(connector.connect(req))\n\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertIn('PROXY-AUTHORIZATION', req.headers)\n        self.assertNotIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://proxy.example.com',\n            auth=aiohttp.helpers.BasicAuth('user', 'pass'),\n            loop=unittest.mock.ANY, headers=unittest.mock.ANY)\n\n    def test_auth_utf8(self):\n        proxy_req = ClientRequest(\n            'GET', 'http://proxy.example.com',\n            auth=aiohttp.helpers.BasicAuth('юзер', 'пасс', 'utf-8'))\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth_from_url(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://user:pass@proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n        self.assertIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://user:pass@proxy.example.com', loop=loop_mock)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, [unittest.mock.MagicMock()])\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', req.headers)\n        self.loop.run_until_complete(connector.connect(req))\n\n        self.assertEqual(req.path, 'http://www.python.org/')\n        self.assertNotIn('AUTHORIZATION', req.headers)\n        self.assertIn('PROXY-AUTHORIZATION', req.headers)\n        self.assertNotIn('AUTHORIZATION', proxy_req.headers)\n        self.assertNotIn('PROXY-AUTHORIZATION', proxy_req.headers)\n\n        ClientRequestMock.assert_called_with(\n            'GET', 'http://user:pass@proxy.example.com',\n            auth=None, loop=unittest.mock.ANY, headers=unittest.mock.ANY)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_auth__not_modifying_request(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://user:pass@proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n        proxy_req_headers = dict(proxy_req.headers)\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector(\n            'http://user:pass@proxy.example.com', loop=loop_mock)\n        connector._resolve_host = resolve_mock = unittest.mock.Mock()\n        self._fake_coroutine(resolve_mock, OSError('nothing personal'))\n\n        req = ClientRequest('GET', 'http://www.python.org')\n        req_headers = dict(req.headers)\n        with self.assertRaises(aiohttp.ProxyConnectionError):\n            self.loop.run_until_complete(connector.connect(req))\n        self.assertEqual(req.headers, req_headers)\n        self.assertEqual(req.path, '/')\n        self.assertEqual(proxy_req.headers, proxy_req_headers)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        self.loop.run_until_complete(connector._create_connection(req))\n\n        self.assertEqual(proxy_req.method, 'CONNECT')\n        self.assertEqual(proxy_req.path, 'www.python.org:443')\n        tr.pause_reading.assert_called_once_with()\n        tr.get_extra_info.assert_called_once_with('socket', default=None)\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_runtime_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(\n                RuntimeError, \"Transport does not expose socket instance\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_http_proxy_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(\n            start_mock, unittest.mock.Mock(status=400, reason='bad request'))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(\n                aiohttp.HttpProxyError, \"400, message='bad request'\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_https_connect_resp_start_error(self, ClientRequestMock):\n        loop_mock = unittest.mock.Mock()\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com',\n                                  loop=loop_mock)\n        ClientRequestMock.return_value = proxy_req\n\n        proxy_resp = ClientResponse('get', 'http://proxy.example.com')\n        proxy_req.send = send_mock = unittest.mock.Mock()\n        send_mock.return_value = proxy_resp\n        proxy_resp.start = start_mock = unittest.mock.Mock()\n        self._fake_coroutine(start_mock, OSError(\"error message\"))\n\n        connector = aiohttp.ProxyConnector(\n            'http://proxy.example.com', loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'https://www.python.org')\n        with self.assertRaisesRegex(OSError, \"error message\"):\n            self.loop.run_until_complete(connector._create_connection(req))\n\n    @unittest.mock.patch('aiohttp.connector.ClientRequest')\n    def test_request_port(self, ClientRequestMock):\n        proxy_req = ClientRequest('GET', 'http://proxy.example.com')\n        ClientRequestMock.return_value = proxy_req\n\n        loop_mock = unittest.mock.Mock()\n        connector = aiohttp.ProxyConnector('http://proxy.example.com',\n                                           loop=loop_mock)\n\n        tr, proto = unittest.mock.Mock(), unittest.mock.Mock()\n        tr.get_extra_info.return_value = None\n        self._fake_coroutine(loop_mock.create_connection, (tr, proto))\n\n        req = ClientRequest('GET', 'http://localhost:1234/path')\n        self.loop.run_until_complete(connector._create_connection(req))\n        self.assertEqual(req.path, 'http://localhost:1234/path')\n"
    ],
    "test_file_names": [
        "test_1.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Transforming aiohttp/worker.py\nTransforming aiohttp/server.py\nTransforming aiohttp/client.py\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nmake: *** No rule to make target '.develop'.  Stop.\nResolved 26 packages in 23ms\nInstalled 26 packages in 57ms\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.0\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": 1,
    "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_980c0d0bd3636a79b29b28b5bdde7dcd796736b1\nplugins: asyncio-0.25.0, mock-3.14.0, cov-6.0.0\nasyncio: mode=strict, asyncio_default_fixture_loop_scope=None\ncollected 42 items\n\nr2e_tests/test_1.py ..........................FF..............           [100%]\n\n=================================== FAILURES ===================================\n_________________ HttpClientConnectorTests.test_tcp_connector __________________\n\nself = <r2e_tests.test_1.HttpClientConnectorTests testMethod=test_tcp_connector>\n\n    def test_tcp_connector(self):\n        with test_utils.run_server(self.loop, router=Functional) as httpd:\n>           r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=aiohttp.TCPConnector(loop=self.loop),\n                    loop=self.loop))\n\nr2e_tests/test_1.py:348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n../../../../.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/asyncio/base_events.py:647: in run_until_complete\n    return future.result()\naiohttp/client.py:104: in request\n    conn = yield from connector.connect(req)\naiohttp/connector.py:164: in connect\n    transport, proto = yield from self._create_connection(req)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <aiohttp.connector.TCPConnector object at 0x7f71bb9342b0>\nreq = <aiohttp.client.ClientRequest object at 0x7f71bb934700>, kwargs = {}\nsslcontext = None, hosts = []\nhinfo = {'family': <AddressFamily.AF_INET: 2>, 'flags': 0, 'host': '127.0.0.1', 'hostname': '127.0.0.1', ...}\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n    \n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        if req.ssl:\n            sslcontext = self.ssl_context\n        else:\n            sslcontext = None\n    \n        hosts = yield from self._resolve_host(req.host, req.port)\n    \n        while hosts:\n            hinfo = hosts.pop()\n            try:\n>               return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\nE                   TypeError: cannot 'yield from' a coroutine object in a non-coroutine generator\n\naiohttp/connector.py:335: TypeError\n_________________ HttpClientConnectorTests.test_unix_connector _________________\n\nself = <r2e_tests.test_1.HttpClientConnectorTests testMethod=test_unix_connector>\n\n    @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix')\n    def test_unix_connector(self):\n        path = '/tmp/aiohttp_unix.sock'\n    \n        connector = aiohttp.UnixConnector(path, loop=self.loop)\n        self.assertEqual(path, connector.path)\n    \n        with test_utils.run_server(\n                self.loop, listen_addr=path, router=Functional) as httpd:\n>           r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=connector,\n                    loop=self.loop))\n\nr2e_tests/test_1.py:367: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n../../../../.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/asyncio/base_events.py:647: in run_until_complete\n    return future.result()\naiohttp/client.py:106: in request\n    resp = req.send(conn.writer, conn.reader)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <aiohttp.client.ClientRequest object at 0x7f71bc4d13d0>\nwriter = <[AttributeError(\"'StreamParser' object has no attribute '_waiter'\") raised in repr()] StreamWriter object at 0x7f71bc4d1220>\nreader = <[AttributeError(\"'StreamParser' object has no attribute '_waiter'\") raised in repr()] StreamParser object at 0x7f71bc4d1370>\n\n    def send(self, writer, reader):\n        request = aiohttp.Request(writer, self.method, self.path, self.version)\n    \n        if self.compress:\n            request.add_compression_filter(self.compress)\n    \n        if self.chunked is not None:\n            request.add_chunking_filter(self.chunked)\n    \n        request.add_headers(\n            *((k, v)\n              for k, v in ((k, value)\n                           for k, value in self.headers.items(getall=True))))\n        request.send_headers()\n    \n>       self._writer = asyncio.create_task(\n            self.write_bytes(request, reader), loop=self.loop)\nE       TypeError: create_task() got an unexpected keyword argument 'loop'\n\naiohttp/client.py:546: TypeError\n------------------------------ Captured log call -------------------------------\nERROR    asyncio:base_events.py:1753 Exception in callback run_server.<locals>.TestHttpServer.connection_made(<_SelectorSoc...e, bufsize=0>>)\nhandle: <Handle run_server.<locals>.TestHttpServer.connection_made(<_SelectorSoc...e, bufsize=0>>)>\nTraceback (most recent call last):\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/asyncio/events.py\", line 80, in _run\n    self._context.run(self._callback, *self._args)\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_980c0d0bd3636a79b29b28b5bdde7dcd796736b1/aiohttp/test_utils.py\", line 68, in connection_made\n    super().connection_made(transport)\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_980c0d0bd3636a79b29b28b5bdde7dcd796736b1/aiohttp/server.py\", line 131, in connection_made\n    self._request_handler = asyncio.create_task(self.start(), loop=self._loop)\nTypeError: create_task() got an unexpected keyword argument 'loop'\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_close\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_del\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_no_share_cookies\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_release\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_release_released\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_share_cookies\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_ambigous_verify_ssl_and_ssl_context\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_cleanup\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_close\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_connect\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_connect_oserr\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_connect_timeout\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_create_conn\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_ctor_loop\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_del\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_dont_recreate_ssl_context\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_get\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_get_expired\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release_close\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release_not_opened\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release_not_started\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_respect_precreated_ssl_context\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_start_cleanup_task\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_tcp_connector_clear_resolved_hosts\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_tcp_connector_ctor\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth__not_modifying_request\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth_from_url\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth_utf8\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_connect\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_ctor\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_ctor2\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect_http_proxy_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect_resp_start_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect_runtime_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_proxy_auth\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_proxy_connection_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_request_port\nFAILED r2e_tests/test_1.py::HttpClientConnectorTests::test_tcp_connector - Ty...\nFAILED r2e_tests/test_1.py::HttpClientConnectorTests::test_unix_connector - T...\n========================= 2 failed, 40 passed in 1.21s =========================\n",
    "new_commit_res_stderr": "/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_980c0d0bd3636a79b29b28b5bdde7dcd796736b1/.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_980c0d0bd3636a79b29b28b5bdde7dcd796736b1\nplugins: asyncio-0.25.0, mock-3.14.0, cov-6.0.0\nasyncio: mode=strict, asyncio_default_fixture_loop_scope=None\ncollected 42 items\n\nr2e_tests/test_1.py ......F........F......F...FF..............           [100%]\n\n=================================== FAILURES ===================================\n_________ BaseConnectorTests.test_ambigous_verify_ssl_and_ssl_context __________\n\nself = <r2e_tests.test_1.BaseConnectorTests testMethod=test_ambigous_verify_ssl_and_ssl_context>\n\n    def test_ambigous_verify_ssl_and_ssl_context(self):\n        with self.assertRaises(ValueError):\n>           aiohttp.TCPConnector(\n                verify_ssl=False,\n                ssl_context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))\n\nr2e_tests/test_1.py:318: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n>       super().__init__(*args, **kwargs)\nE       TypeError: __init__() got an unexpected keyword argument 'ssl_context'\n\naiohttp/connector.py:227: TypeError\n______________ BaseConnectorTests.test_dont_recreate_ssl_context _______________\n\nself = <r2e_tests.test_1.BaseConnectorTests testMethod=test_dont_recreate_ssl_context>\n\n    def test_dont_recreate_ssl_context(self):\n        conn = aiohttp.TCPConnector(loop=self.loop)\n>       ctx = conn.ssl_context\nE       AttributeError: 'TCPConnector' object has no attribute 'ssl_context'\n\nr2e_tests/test_1.py:324: AttributeError\n____________ BaseConnectorTests.test_respect_precreated_ssl_context ____________\n\nself = <r2e_tests.test_1.BaseConnectorTests testMethod=test_respect_precreated_ssl_context>\n\n    def test_respect_precreated_ssl_context(self):\n        ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n>       conn = aiohttp.TCPConnector(loop=self.loop, ssl_context=ctx)\n\nr2e_tests/test_1.py:329: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <aiohttp.connector.TCPConnector object at 0x7424cbab3a60>\nverify_ssl = True, resolve = False, family = <AddressFamily.AF_INET: 2>\nargs = ()\nkwargs = {'loop': <_UnixSelectorEventLoop running=False closed=True debug=False>, 'ssl_context': <ssl.SSLContext object at 0x7424caf47cc0>}\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n>       super().__init__(*args, **kwargs)\nE       TypeError: __init__() got an unexpected keyword argument 'ssl_context'\n\naiohttp/connector.py:227: TypeError\n_________________ HttpClientConnectorTests.test_tcp_connector __________________\n\nself = <r2e_tests.test_1.HttpClientConnectorTests testMethod=test_tcp_connector>\n\n    def test_tcp_connector(self):\n        with test_utils.run_server(self.loop, router=Functional) as httpd:\n>           r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=aiohttp.TCPConnector(loop=self.loop),\n                    loop=self.loop))\n\nr2e_tests/test_1.py:348: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n../../../../.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/asyncio/base_events.py:647: in run_until_complete\n    return future.result()\naiohttp/client.py:104: in request\n    conn = yield from connector.connect(req)\naiohttp/connector.py:164: in connect\n    transport, proto = yield from self._create_connection(req)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <aiohttp.connector.TCPConnector object at 0x7424caf08820>\nreq = <aiohttp.client.ClientRequest object at 0x7424caf085e0>, kwargs = {}\nsslcontext = False, hosts = []\nhinfo = {'family': <AddressFamily.AF_INET: 2>, 'flags': 0, 'host': '127.0.0.1', 'hostname': '127.0.0.1', ...}\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n    \n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n    \n        hosts = yield from self._resolve_host(req.host, req.port)\n    \n        while hosts:\n            hinfo = hosts.pop()\n            try:\n>               return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\nE                   TypeError: cannot 'yield from' a coroutine object in a non-coroutine generator\n\naiohttp/connector.py:302: TypeError\n_________________ HttpClientConnectorTests.test_unix_connector _________________\n\nself = <r2e_tests.test_1.HttpClientConnectorTests testMethod=test_unix_connector>\n\n    @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix')\n    def test_unix_connector(self):\n        path = '/tmp/aiohttp_unix.sock'\n    \n        connector = aiohttp.UnixConnector(path, loop=self.loop)\n        self.assertEqual(path, connector.path)\n    \n        with test_utils.run_server(\n                self.loop, listen_addr=path, router=Functional) as httpd:\n>           r = self.loop.run_until_complete(\n                client.request(\n                    'get', httpd.url('method', 'get'),\n                    connector=connector,\n                    loop=self.loop))\n\nr2e_tests/test_1.py:367: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n../../../../.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/asyncio/base_events.py:647: in run_until_complete\n    return future.result()\naiohttp/client.py:106: in request\n    resp = req.send(conn.writer, conn.reader)\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <aiohttp.client.ClientRequest object at 0x7424cae67310>\nwriter = <[AttributeError(\"'StreamParser' object has no attribute '_waiter'\") raised in repr()] StreamWriter object at 0x7424cae672e0>\nreader = <[AttributeError(\"'StreamParser' object has no attribute '_waiter'\") raised in repr()] StreamParser object at 0x7424cae674c0>\n\n    def send(self, writer, reader):\n        request = aiohttp.Request(writer, self.method, self.path, self.version)\n    \n        if self.compress:\n            request.add_compression_filter(self.compress)\n    \n        if self.chunked is not None:\n            request.add_chunking_filter(self.chunked)\n    \n        request.add_headers(\n            *((k, v)\n              for k, v in ((k, value)\n                           for k, value in self.headers.items(getall=True))))\n        request.send_headers()\n    \n>       self._writer = asyncio.create_task(\n            self.write_bytes(request, reader), loop=self.loop)\nE       TypeError: create_task() got an unexpected keyword argument 'loop'\n\naiohttp/client.py:546: TypeError\n------------------------------ Captured log call -------------------------------\nERROR    asyncio:base_events.py:1753 Exception in callback run_server.<locals>.TestHttpServer.connection_made(<_SelectorSoc...e, bufsize=0>>)\nhandle: <Handle run_server.<locals>.TestHttpServer.connection_made(<_SelectorSoc...e, bufsize=0>>)>\nTraceback (most recent call last):\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/asyncio/events.py\", line 80, in _run\n    self._context.run(self._callback, *self._args)\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_980c0d0bd3636a79b29b28b5bdde7dcd796736b1/aiohttp/test_utils.py\", line 68, in connection_made\n    super().connection_made(transport)\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_980c0d0bd3636a79b29b28b5bdde7dcd796736b1/aiohttp/server.py\", line 131, in connection_made\n    self._request_handler = asyncio.create_task(self.start(), loop=self._loop)\nTypeError: create_task() got an unexpected keyword argument 'loop'\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_close\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_del\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_no_share_cookies\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_release\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_release_released\nPASSED r2e_tests/test_1.py::HttpConnectionTests::test_share_cookies\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_cleanup\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_close\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_connect\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_connect_oserr\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_connect_timeout\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_create_conn\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_ctor_loop\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_del\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_get\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_get_expired\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release_close\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release_not_opened\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_release_not_started\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_start_cleanup_task\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_tcp_connector_clear_resolved_hosts\nPASSED r2e_tests/test_1.py::BaseConnectorTests::test_tcp_connector_ctor\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth__not_modifying_request\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth_from_url\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_auth_utf8\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_connect\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_ctor\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_ctor2\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect_http_proxy_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect_resp_start_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_https_connect_runtime_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_proxy_auth\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_proxy_connection_error\nPASSED r2e_tests/test_1.py::ProxyConnectorTests::test_request_port\nFAILED r2e_tests/test_1.py::BaseConnectorTests::test_ambigous_verify_ssl_and_ssl_context\nFAILED r2e_tests/test_1.py::BaseConnectorTests::test_dont_recreate_ssl_context\nFAILED r2e_tests/test_1.py::BaseConnectorTests::test_respect_precreated_ssl_context\nFAILED r2e_tests/test_1.py::HttpClientConnectorTests::test_tcp_connector - Ty...\nFAILED r2e_tests/test_1.py::HttpClientConnectorTests::test_unix_connector - T...\n========================= 5 failed, 37 passed in 0.57s =========================\n",
    "old_commit_res_stderr": "/home/gcpuser/buckets/local_repoeval_bucket/repos/aiohttp_980c0d0bd3636a79b29b28b5bdde7dcd796736b1/.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/connector.py tests/test_connector.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** TCPConnector Raises TypeError When Using ssl_context Parameter

**Description:**
When initializing `TCPConnector` with the `ssl_context` parameter, a `TypeError` is raised because the constructor does not recognize the `ssl_context` argument.

**Example Code:**
```python
import ssl
import aiohttp

ssl_ctx = ssl.create_default_context()
connector = aiohttp.TCPConnector(ssl_context=ssl_ctx)
```

**Expected Behavior:**
`TCPConnector` should accept the `ssl_context` parameter and utilize it for configuring SSL settings.

**Actual Behavior:**
A `TypeError` is raised indicating that `TCPConnector` received an unexpected keyword argument `ssl_context`.

**Error Message:**
```
TypeError: __init__() got an unexpected keyword argument 'ssl_context'
```
[/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/connector.py
__all__ = ['BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector']

import asyncio
import aiohttp
import functools
import http.cookies
import time
import ssl
import socket
import weakref

from .client import ClientRequest
from .errors import ServerDisconnectedError
from .errors import HttpProxyError, ProxyConnectionError
from .errors import ClientOSError, ClientTimeoutError
from .helpers import BasicAuth


class Connection(object):

    def __init__(self, connector, key, request, transport, protocol, loop):
        self._key = key
        self._connector = connector
        self._request = request
        self._transport = transport
        self._protocol = protocol
        self._loop = loop
        self.reader = protocol.reader
        self.writer = protocol.writer
        self._wr = weakref.ref(self, lambda wr, tr=self._transport: tr.close())

    @property
    def loop(self):
        return self._loop

    def close(self):
        if self._transport is not None:
            self._connector._release(
                self._key, self._request, self._transport, self._protocol,
                should_close=True)
            self._transport = None
            self._wr = None

    def release(self):
        if self._transport:
            self._connector._release(
                self._key, self._request, self._transport, self._protocol)
            self._transport = None
            self._wr = None

    def share_cookies(self, cookies):
        if self._connector._share_cookies:  # XXX
            self._connector.update_cookies(cookies)


class BaseConnector(object):
    """Base connector class.

    :param conn_timeout: (optional) Connect timeout.
    :param keepalive_timeout: (optional) Keep-alive timeout.
    :param bool share_cookies: Set to True to keep cookies between requests.
    :param bool force_close: Set to True to froce close and do reconnect
        after each request (and between redirects).
    :param loop: Optional event loop.
    """

    def __init__(self, *, conn_timeout=None, keepalive_timeout=30,
                 share_cookies=False, force_close=False, loop=None):
        self._conns = {}
        self._conn_timeout = conn_timeout
        self._keepalive_timeout = keepalive_timeout
        self._share_cookies = share_cookies
        self._cleanup_handle = None
        self._force_close = force_close

        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self._factory = functools.partial(
            aiohttp.StreamProtocol, loop=loop,
            disconnect_error=ServerDisconnectedError)

        self.cookies = http.cookies.SimpleCookie()
        self._wr = weakref.ref(
            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))

    def _cleanup(self):
        """Cleanup unused transports."""
        if self._cleanup_handle:
            self._cleanup_handle.cancel()
            self._cleanup_handle = None

        now = time.time()

        connections = {}
        for key, conns in self._conns.items():
            alive = []
            for transport, proto, t0 in conns:
                if transport is not None:
                    if proto and not proto.is_connected():
                        transport = None
                    elif (now - t0) > self._keepalive_timeout:
                        transport.close()
                        transport = None

                if transport:
                    alive.append((transport, proto, t0))
            if alive:
                connections[key] = alive

        if connections:
            self._cleanup_handle = self._loop.call_later(
                self._keepalive_timeout, self._cleanup)

        self._conns = connections
        self._wr = weakref.ref(
            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))

    def _start_cleanup_task(self):
        if self._cleanup_handle is None:
            self._cleanup_handle = self._loop.call_later(
                self._keepalive_timeout, self._cleanup)

    def close(self):
        """Close all opened transports."""
        self._do_close(self._conns)

    @staticmethod
    def _do_close(conns):
        for key, data in conns.items():
            for transport, proto, td in data:
                transport.close()

        conns.clear()

    def update_cookies(self, cookies):
        """Update shared cookies."""
        if isinstance(cookies, dict):
            cookies = cookies.items()

        for name, value in cookies:
            if isinstance(value, http.cookies.Morsel):
                # use dict method because SimpleCookie class modifies value
                dict.__setitem__(self.cookies, name, value)
            else:
                self.cookies[name] = value

    @asyncio.coroutine
    def connect(self, req):
        """Get from pool or create new connection."""
        key = (req.host, req.port, req.ssl)

        if self._share_cookies:
            req.update_cookies(self.cookies.items())

        transport, proto = self._get(key)
        if transport is None:
            try:
                if self._conn_timeout:
                    transport, proto = yield from asyncio.wait_for(
                        self._create_connection(req),
                        self._conn_timeout, loop=self._loop)
                else:
                    transport, proto = yield from self._create_connection(req)
            except asyncio.TimeoutError as exc:
                raise ClientTimeoutError() from exc
            except OSError as exc:
                raise ClientOSError() from exc

        return Connection(self, key, req, transport, proto, self._loop)

    def _get(self, key):
        conns = self._conns.get(key)
        while conns:
            transport, proto, t0 = conns.pop()
            if transport is not None and proto.is_connected():
                if (time.time() - t0) > self._keepalive_timeout:
                    transport.close()
                    transport = None
                else:
                    return transport, proto

        return None, None

    def _release(self, key, req, transport, protocol, *, should_close=False):
        resp = req.response

        if not should_close:
            if resp is not None:
                if resp.message is None:
                    should_close = True
                else:
                    should_close = resp.message.should_close

            if self._force_close:
                should_close = True

        reader = protocol.reader
        if should_close or (reader.output and not reader.output.at_eof()):
            self._conns.pop(key, None)
            transport.close()
        else:
            conns = self._conns.get(key)
            if conns is None:
                conns = self._conns[key] = []
            conns.append((transport, protocol, time.time()))
            reader.unset_parser()

            self._start_cleanup_task()

    def _create_connection(self, req, *args, **kwargs):
        raise NotImplementedError()


class TCPConnector(BaseConnector):
    """TCP connector.

    :param bool verify_ssl: Set to True to check ssl certifications.
    :param bool resolve: Set to True to do DNS lookup for host name.
    :param familiy: socket address family
    :param args: see :class:`BaseConnector`
    :param kwargs: see :class:`BaseConnector`
    """

    def __init__(self, *args, verify_ssl=True,
                 resolve=False, family=socket.AF_INET, **kwargs):
        super().__init__(*args, **kwargs)

        self._verify_ssl = verify_ssl
        self._family = family
        self._resolve = resolve
        self._resolved_hosts = {}

    @property
    def verify_ssl(self):
        """Do check for ssl certifications?"""
        return self._verify_ssl

    @property
    def family(self):
        """Socket family like AF_INET."""
        return self._family

    @property
    def resolve(self):
        """Do DNS lookup for host name?"""
        return self._resolve

    @property
    def resolved_hosts(self):
        """The dict of (host, port) -> (ipaddr, port) pairs."""
        return dict(self._resolved_hosts)

    def clear_resolved_hosts(self, host=None, port=None):
        """Remove specified host/port or clear all resolve cache."""
        if host is not None and port is not None:
            key = (host, port)
            if key in self._resolved_hosts:
                del self._resolved_hosts[key]
        else:
            self._resolved_hosts.clear()

    @asyncio.coroutine
    def _resolve_host(self, host, port):
        if self._resolve:
            key = (host, port)

            if key not in self._resolved_hosts:
                infos = yield from self._loop.getaddrinfo(
                    host, port, type=socket.SOCK_STREAM, family=self._family)

                hosts = []
                for family, _, proto, _, address in infos:
                    hosts.append(
                        {'hostname': host,
                         'host': address[0], 'port': address[1],
                         'family': family, 'proto': proto,
                         'flags': socket.AI_NUMERICHOST})
                self._resolved_hosts[key] = hosts

            return list(self._resolved_hosts[key])
        else:
            return [{'hostname': host, 'host': host, 'port': port,
                     'family': self._family, 'proto': 0, 'flags': 0}]

    def _create_connection(self, req, **kwargs):
        """Create connection.

        Has same keyword arguments as BaseEventLoop.create_connection.
        """
        sslcontext = req.ssl
        if req.ssl and not self._verify_ssl:
            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
            sslcontext.options |= ssl.OP_NO_SSLv2
            sslcontext.set_default_verify_paths()

        hosts = yield from self._resolve_host(req.host, req.port)

        while hosts:
            hinfo = hosts.pop()
            try:
                return (yield from self._loop.create_connection(
                    self._factory, hinfo['host'], hinfo['port'],
                    ssl=sslcontext, family=hinfo['family'],
                    proto=hinfo['proto'], flags=hinfo['flags'],
                    server_hostname=hinfo['hostname'] if sslcontext else None,
                    **kwargs))
            except OSError as exc:
                if not hosts:
                    raise ClientOSError('Can not connect to %s:%s' %
                                        (req.host, req.port)) from exc


class ProxyConnector(TCPConnector):
    """Http Proxy connector.

    :param str proxy: Proxy URL address. Only http proxy supported.
    :param proxy_auth: (optional) Proxy HTTP Basic Auth
    :type proxy_auth: aiohttp.helpers.BasicAuth
    :param args: see :class:`TCPConnector`
    :param kwargs: see :class:`TCPConnector`

    Usage:

    >>> conn = ProxyConnector(proxy="http://some.proxy.com")
    >>> resp = yield from request('GET', 'http://python.org', connector=conn)

    """

    def __init__(self, proxy, *args, proxy_auth=None, **kwargs):
        super().__init__(*args, **kwargs)
        self._proxy = proxy
        self._proxy_auth = proxy_auth
        assert proxy.startswith('http://'), (
            "Only http proxy supported", proxy)
        assert proxy_auth is None or isinstance(proxy_auth, BasicAuth), (
            "proxy_auth must be None or BasicAuth() tuple", proxy_auth)

    @property
    def proxy(self):
        """Proxy URL."""
        return self._proxy

    @asyncio.coroutine
    def _create_connection(self, req, **kwargs):
        proxy_req = ClientRequest(
            'GET', self._proxy,
            headers={'Host': req.host},
            auth=self._proxy_auth,
            loop=self._loop)
        try:
            transport, proto = yield from super()._create_connection(proxy_req)
        except OSError as exc:
            raise ProxyConnectionError(*exc.args) from exc

        req.path = '{scheme}://{host}{path}'.format(scheme=req.scheme,
                                                    host=req.netloc,
                                                    path=req.path)
        if 'AUTHORIZATION' in proxy_req.headers:
            auth = proxy_req.headers['AUTHORIZATION']
            del proxy_req.headers['AUTHORIZATION']
            req.headers['PROXY-AUTHORIZATION'] = auth

        if req.ssl:
            # For HTTPS requests over HTTP proxy
            # we must notify proxy to tunnel connection
            # so we send CONNECT command:
            #   CONNECT www.python.org:443 HTTP/1.1
            #   Host: www.python.org
            #
            # next we must do TLS handshake and so on
            # to do this we must wrap raw socket into secure one
            # asyncio handles this perfectly
            proxy_req.method = 'CONNECT'
            proxy_req.path = '{}:{}'.format(req.host, req.port)
            key = (req.host, req.port, req.ssl)
            conn = Connection(self, key, proxy_req,
                              transport, proto, self._loop)
            proxy_resp = proxy_req.send(conn.writer, conn.reader)
            try:
                resp = yield from proxy_resp.start(conn, True)
            except:
                proxy_resp.close()
                conn.close()
                raise
            else:
                if resp.status != 200:
                    raise HttpProxyError(code=resp.status, message=resp.reason)
                rawsock = transport.get_extra_info('socket', default=None)
                if rawsock is None:
                    raise RuntimeError(
                        "Transport does not expose socket instance")
                transport.pause_reading()
                transport, proto = yield from self._loop.create_connection(
                    self._factory, ssl=True, sock=rawsock,
                    server_hostname=req.host, **kwargs)

        return transport, proto


class UnixConnector(BaseConnector):
    """Unix socket connector.

    :param str path: Unix socket path.
    :param args: see :class:`BaseConnector`
    :param kwargs: see :class:`BaseConnector`

    Usage:

    >>> conn = UnixConnector(path='/path/to/socket')
    >>> resp = yield from request('GET', 'http://python.org', connector=conn)

    """

    def __init__(self, path, *args, **kw):
        super().__init__(*args, **kw)
        self._path = path

    @property
    def path(self):
        """Path to unix socket."""
        return self._path

    @asyncio.coroutine
    def _create_connection(self, req, **kwargs):
        return (yield from self._loop.create_unix_connection(
            self._factory, self._path, **kwargs))

```
--- 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:** TCPConnector Raises TypeError When Using ssl_context Parameter

**Description:**
When initializing `TCPConnector` with the `ssl_context` parameter, a `TypeError` is raised because the constructor does not recognize the `ssl_context` argument.

**Example Code:**
```python
import ssl
import aiohttp

ssl_ctx = ssl.create_default_context()
connector = aiohttp.TCPConnector(ssl_context=ssl_ctx)
```

**Expected Behavior:**
`TCPConnector` should accept the `ssl_context` parameter and utilize it for configuring SSL settings.

**Actual Behavior:**
A `TypeError` is raised indicating that `TCPConnector` received an unexpected keyword argument `ssl_context`.

**Error Message:**
```
TypeError: __init__() got an unexpected keyword argument 'ssl_context'
```
[/ISSUE]
{
    "HttpConnectionTests.test_close": "PASSED",
    "HttpConnectionTests.test_del": "PASSED",
    "HttpConnectionTests.test_no_share_cookies": "PASSED",
    "HttpConnectionTests.test_release": "PASSED",
    "HttpConnectionTests.test_release_released": "PASSED",
    "HttpConnectionTests.test_share_cookies": "PASSED",
    "BaseConnectorTests.test_ambigous_verify_ssl_and_ssl_context": "PASSED",
    "BaseConnectorTests.test_cleanup": "PASSED",
    "BaseConnectorTests.test_close": "PASSED",
    "BaseConnectorTests.test_connect": "PASSED",
    "BaseConnectorTests.test_connect_oserr": "PASSED",
    "BaseConnectorTests.test_connect_timeout": "PASSED",
    "BaseConnectorTests.test_create_conn": "PASSED",
    "BaseConnectorTests.test_ctor_loop": "PASSED",
    "BaseConnectorTests.test_del": "PASSED",
    "BaseConnectorTests.test_dont_recreate_ssl_context": "PASSED",
    "BaseConnectorTests.test_get": "PASSED",
    "BaseConnectorTests.test_get_expired": "PASSED",
    "BaseConnectorTests.test_release": "PASSED",
    "BaseConnectorTests.test_release_close": "PASSED",
    "BaseConnectorTests.test_release_not_opened": "PASSED",
    "BaseConnectorTests.test_release_not_started": "PASSED",
    "BaseConnectorTests.test_respect_precreated_ssl_context": "PASSED",
    "BaseConnectorTests.test_start_cleanup_task": "PASSED",
    "BaseConnectorTests.test_tcp_connector_clear_resolved_hosts": "PASSED",
    "BaseConnectorTests.test_tcp_connector_ctor": "PASSED",
    "ProxyConnectorTests.test_auth": "PASSED",
    "ProxyConnectorTests.test_auth__not_modifying_request": "PASSED",
    "ProxyConnectorTests.test_auth_from_url": "PASSED",
    "ProxyConnectorTests.test_auth_utf8": "PASSED",
    "ProxyConnectorTests.test_connect": "PASSED",
    "ProxyConnectorTests.test_ctor": "PASSED",
    "ProxyConnectorTests.test_ctor2": "PASSED",
    "ProxyConnectorTests.test_https_connect": "PASSED",
    "ProxyConnectorTests.test_https_connect_http_proxy_error": "PASSED",
    "ProxyConnectorTests.test_https_connect_resp_start_error": "PASSED",
    "ProxyConnectorTests.test_https_connect_runtime_error": "PASSED",
    "ProxyConnectorTests.test_proxy_auth": "PASSED",
    "ProxyConnectorTests.test_proxy_connection_error": "PASSED",
    "ProxyConnectorTests.test_request_port": "PASSED",
    "HttpClientConnectorTests.test_tcp_connector": "FAILED",
    "HttpClientConnectorTests.test_unix_connector": "FAILED"
}
diff --git a/aiohttp/connector.py b/aiohttp/connector.py
index 7937b92c..ce0801aa 100644
--- a/aiohttp/connector.py
+++ b/aiohttp/connector.py
@@ -223,10 +223,17 @@ class TCPConnector(BaseConnector):
     """
 
     def __init__(self, *args, verify_ssl=True,
-                 resolve=False, family=socket.AF_INET, **kwargs):
+                 resolve=False, family=socket.AF_INET, ssl_context=None,
+                 **kwargs):
+        if not verify_ssl and ssl_context is not None:
+            raise ValueError(
+                "Either disable ssl certificate validation by "
+                "verify_ssl=False or specify ssl_context, not both.")
+
         super().__init__(*args, **kwargs)
 
         self._verify_ssl = verify_ssl
+        self._ssl_context = ssl_context
         self._family = family
         self._resolve = resolve
         self._resolved_hosts = {}
@@ -236,6 +243,33 @@ class TCPConnector(BaseConnector):
         """Do check for ssl certifications?"""
         return self._verify_ssl
 
+    @property
+    def ssl_context(self):
+        """SSLContext instance for https requests.
+
+        Lazy property, creates context on demand.
+        """
+        if self._ssl_context is None:
+            if not self._verify_ssl:
+                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+                sslcontext.options |= ssl.OP_NO_SSLv2
+                sslcontext.options |= ssl.OP_NO_SSLv3
+                sslcontext.options |= getattr(ssl, "OP_NO_COMPRESSION", 0)
+                sslcontext.set_default_verify_paths()
+            elif hasattr(ssl, 'create_default_context'):
+                # Python 3.4+
+                sslcontext = ssl.create_default_context()
+            else:  # pragma: no cover
+                # Fallback for Python 3.3.
+                sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+                sslcontext.options |= ssl.OP_NO_SSLv2
+                sslcontext.options |= ssl.OP_NO_SSLv3
+                sslcontext.options |= getattr(ssl, "OP_NO_COMPRESSION", 0)
+                sslcontext.set_default_verify_paths()
+                sslcontext.verify_mode = ssl.CERT_REQUIRED
+            self._ssl_context = sslcontext
+        return self._ssl_context
+
     @property
     def family(self):
         """Socket family like AF_INET."""
@@ -288,11 +322,10 @@ class TCPConnector(BaseConnector):
 
         Has same keyword arguments as BaseEventLoop.create_connection.
         """
-        sslcontext = req.ssl
-        if req.ssl and not self._verify_ssl:
-            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
-            sslcontext.options |= ssl.OP_NO_SSLv2
-            sslcontext.set_default_verify_paths()
+        if req.ssl:
+            sslcontext = self.ssl_context
+        else:
+            sslcontext = None
 
         hosts = yield from self._resolve_host(req.host, req.port)
 

{"aiohttp/connector.py": "__all__ = ['BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector']\n\nimport asyncio\nimport aiohttp\nimport functools\nimport http.cookies\nimport time\nimport ssl\nimport socket\nimport weakref\n\nfrom .client import ClientRequest\nfrom .errors import ServerDisconnectedError\nfrom .errors import HttpProxyError, ProxyConnectionError\nfrom .errors import ClientOSError, ClientTimeoutError\nfrom .helpers import BasicAuth\n\n\nclass Connection(object):\n\n    def __init__(self, connector, key, request, transport, protocol, loop):\n        self._key = key\n        self._connector = connector\n        self._request = request\n        self._transport = transport\n        self._protocol = protocol\n        self._loop = loop\n        self.reader = protocol.reader\n        self.writer = protocol.writer\n        self._wr = weakref.ref(self, lambda wr, tr=self._transport: tr.close())\n\n    @property\n    def loop(self):\n        return self._loop\n\n    def close(self):\n        if self._transport is not None:\n            self._connector._release(\n                self._key, self._request, self._transport, self._protocol,\n                should_close=True)\n            self._transport = None\n            self._wr = None\n\n    def release(self):\n        if self._transport:\n            self._connector._release(\n                self._key, self._request, self._transport, self._protocol)\n            self._transport = None\n            self._wr = None\n\n    def share_cookies(self, cookies):\n        if self._connector._share_cookies:  # XXX\n            self._connector.update_cookies(cookies)\n\n\nclass BaseConnector(object):\n    \"\"\"Base connector class.\n\n    :param conn_timeout: (optional) Connect timeout.\n    :param keepalive_timeout: (optional) Keep-alive timeout.\n    :param bool share_cookies: Set to True to keep cookies between requests.\n    :param bool force_close: Set to True to froce close and do reconnect\n        after each request (and between redirects).\n    :param loop: Optional event loop.\n    \"\"\"\n\n    def __init__(self, *, conn_timeout=None, keepalive_timeout=30,\n                 share_cookies=False, force_close=False, loop=None):\n        self._conns = {}\n        self._conn_timeout = conn_timeout\n        self._keepalive_timeout = keepalive_timeout\n        self._share_cookies = share_cookies\n        self._cleanup_handle = None\n        self._force_close = force_close\n\n        if loop is None:\n            loop = asyncio.get_event_loop()\n        self._loop = loop\n        self._factory = functools.partial(\n            aiohttp.StreamProtocol, loop=loop,\n            disconnect_error=ServerDisconnectedError)\n\n        self.cookies = http.cookies.SimpleCookie()\n        self._wr = weakref.ref(\n            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))\n\n    def _cleanup(self):\n        \"\"\"Cleanup unused transports.\"\"\"\n        if self._cleanup_handle:\n            self._cleanup_handle.cancel()\n            self._cleanup_handle = None\n\n        now = time.time()\n\n        connections = {}\n        for key, conns in self._conns.items():\n            alive = []\n            for transport, proto, t0 in conns:\n                if transport is not None:\n                    if proto and not proto.is_connected():\n                        transport = None\n                    elif (now - t0) > self._keepalive_timeout:\n                        transport.close()\n                        transport = None\n\n                if transport:\n                    alive.append((transport, proto, t0))\n            if alive:\n                connections[key] = alive\n\n        if connections:\n            self._cleanup_handle = self._loop.call_later(\n                self._keepalive_timeout, self._cleanup)\n\n        self._conns = connections\n        self._wr = weakref.ref(\n            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))\n\n    def _start_cleanup_task(self):\n        if self._cleanup_handle is None:\n            self._cleanup_handle = self._loop.call_later(\n                self._keepalive_timeout, self._cleanup)\n\n    def close(self):\n        \"\"\"Close all opened transports.\"\"\"\n        self._do_close(self._conns)\n\n    @staticmethod\n    def _do_close(conns):\n        for key, data in conns.items():\n            for transport, proto, td in data:\n                transport.close()\n\n        conns.clear()\n\n    def update_cookies(self, cookies):\n        \"\"\"Update shared cookies.\"\"\"\n        if isinstance(cookies, dict):\n            cookies = cookies.items()\n\n        for name, value in cookies:\n            if isinstance(value, http.cookies.Morsel):\n                # use dict method because SimpleCookie class modifies value\n                dict.__setitem__(self.cookies, name, value)\n            else:\n                self.cookies[name] = value\n\n    @asyncio.coroutine\n    def connect(self, req):\n        \"\"\"Get from pool or create new connection.\"\"\"\n        key = (req.host, req.port, req.ssl)\n\n        if self._share_cookies:\n            req.update_cookies(self.cookies.items())\n\n        transport, proto = self._get(key)\n        if transport is None:\n            try:\n                if self._conn_timeout:\n                    transport, proto = yield from asyncio.wait_for(\n                        self._create_connection(req),\n                        self._conn_timeout, loop=self._loop)\n                else:\n                    transport, proto = yield from self._create_connection(req)\n            except asyncio.TimeoutError as exc:\n                raise ClientTimeoutError() from exc\n            except OSError as exc:\n                raise ClientOSError() from exc\n\n        return Connection(self, key, req, transport, proto, self._loop)\n\n    def _get(self, key):\n        conns = self._conns.get(key)\n        while conns:\n            transport, proto, t0 = conns.pop()\n            if transport is not None and proto.is_connected():\n                if (time.time() - t0) > self._keepalive_timeout:\n                    transport.close()\n                    transport = None\n                else:\n                    return transport, proto\n\n        return None, None\n\n    def _release(self, key, req, transport, protocol, *, should_close=False):\n        resp = req.response\n\n        if not should_close:\n            if resp is not None:\n                if resp.message is None:\n                    should_close = True\n                else:\n                    should_close = resp.message.should_close\n\n            if self._force_close:\n                should_close = True\n\n        reader = protocol.reader\n        if should_close or (reader.output and not reader.output.at_eof()):\n            self._conns.pop(key, None)\n            transport.close()\n        else:\n            conns = self._conns.get(key)\n            if conns is None:\n                conns = self._conns[key] = []\n            conns.append((transport, protocol, time.time()))\n            reader.unset_parser()\n\n            self._start_cleanup_task()\n\n    def _create_connection(self, req, *args, **kwargs):\n        raise NotImplementedError()\n\n\nclass TCPConnector(BaseConnector):\n    \"\"\"TCP connector.\n\n    :param bool verify_ssl: Set to True to check ssl certifications.\n    :param bool resolve: Set to True to do DNS lookup for host name.\n    :param familiy: socket address family\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n    \"\"\"\n\n    def __init__(self, *args, verify_ssl=True,\n                 resolve=False, family=socket.AF_INET, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        self._verify_ssl = verify_ssl\n        self._family = family\n        self._resolve = resolve\n        self._resolved_hosts = {}\n\n    @property\n    def verify_ssl(self):\n        \"\"\"Do check for ssl certifications?\"\"\"\n        return self._verify_ssl\n\n    @property\n    def family(self):\n        \"\"\"Socket family like AF_INET.\"\"\"\n        return self._family\n\n    @property\n    def resolve(self):\n        \"\"\"Do DNS lookup for host name?\"\"\"\n        return self._resolve\n\n    @property\n    def resolved_hosts(self):\n        \"\"\"The dict of (host, port) -> (ipaddr, port) pairs.\"\"\"\n        return dict(self._resolved_hosts)\n\n    def clear_resolved_hosts(self, host=None, port=None):\n        \"\"\"Remove specified host/port or clear all resolve cache.\"\"\"\n        if host is not None and port is not None:\n            key = (host, port)\n            if key in self._resolved_hosts:\n                del self._resolved_hosts[key]\n        else:\n            self._resolved_hosts.clear()\n\n    @asyncio.coroutine\n    def _resolve_host(self, host, port):\n        if self._resolve:\n            key = (host, port)\n\n            if key not in self._resolved_hosts:\n                infos = yield from self._loop.getaddrinfo(\n                    host, port, type=socket.SOCK_STREAM, family=self._family)\n\n                hosts = []\n                for family, _, proto, _, address in infos:\n                    hosts.append(\n                        {'hostname': host,\n                         'host': address[0], 'port': address[1],\n                         'family': family, 'proto': proto,\n                         'flags': socket.AI_NUMERICHOST})\n                self._resolved_hosts[key] = hosts\n\n            return list(self._resolved_hosts[key])\n        else:\n            return [{'hostname': host, 'host': host, 'port': port,\n                     'family': self._family, 'proto': 0, 'flags': 0}]\n\n    def _create_connection(self, req, **kwargs):\n        \"\"\"Create connection.\n\n        Has same keyword arguments as BaseEventLoop.create_connection.\n        \"\"\"\n        sslcontext = req.ssl\n        if req.ssl and not self._verify_ssl:\n            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n            sslcontext.options |= ssl.OP_NO_SSLv2\n            sslcontext.set_default_verify_paths()\n\n        hosts = yield from self._resolve_host(req.host, req.port)\n\n        while hosts:\n            hinfo = hosts.pop()\n            try:\n                return (yield from self._loop.create_connection(\n                    self._factory, hinfo['host'], hinfo['port'],\n                    ssl=sslcontext, family=hinfo['family'],\n                    proto=hinfo['proto'], flags=hinfo['flags'],\n                    server_hostname=hinfo['hostname'] if sslcontext else None,\n                    **kwargs))\n            except OSError as exc:\n                if not hosts:\n                    raise ClientOSError('Can not connect to %s:%s' %\n                                        (req.host, req.port)) from exc\n\n\nclass ProxyConnector(TCPConnector):\n    \"\"\"Http Proxy connector.\n\n    :param str proxy: Proxy URL address. Only http proxy supported.\n    :param proxy_auth: (optional) Proxy HTTP Basic Auth\n    :type proxy_auth: aiohttp.helpers.BasicAuth\n    :param args: see :class:`TCPConnector`\n    :param kwargs: see :class:`TCPConnector`\n\n    Usage:\n\n    >>> conn = ProxyConnector(proxy=\"http://some.proxy.com\")\n    >>> resp = yield from request('GET', 'http://python.org', connector=conn)\n\n    \"\"\"\n\n    def __init__(self, proxy, *args, proxy_auth=None, **kwargs):\n        super().__init__(*args, **kwargs)\n        self._proxy = proxy\n        self._proxy_auth = proxy_auth\n        assert proxy.startswith('http://'), (\n            \"Only http proxy supported\", proxy)\n        assert proxy_auth is None or isinstance(proxy_auth, BasicAuth), (\n            \"proxy_auth must be None or BasicAuth() tuple\", proxy_auth)\n\n    @property\n    def proxy(self):\n        \"\"\"Proxy URL.\"\"\"\n        return self._proxy\n\n    @asyncio.coroutine\n    def _create_connection(self, req, **kwargs):\n        proxy_req = ClientRequest(\n            'GET', self._proxy,\n            headers={'Host': req.host},\n            auth=self._proxy_auth,\n            loop=self._loop)\n        try:\n            transport, proto = yield from super()._create_connection(proxy_req)\n        except OSError as exc:\n            raise ProxyConnectionError(*exc.args) from exc\n\n        req.path = '{scheme}://{host}{path}'.format(scheme=req.scheme,\n                                                    host=req.netloc,\n                                                    path=req.path)\n        if 'AUTHORIZATION' in proxy_req.headers:\n            auth = proxy_req.headers['AUTHORIZATION']\n            del proxy_req.headers['AUTHORIZATION']\n            req.headers['PROXY-AUTHORIZATION'] = auth\n\n        if req.ssl:\n            # For HTTPS requests over HTTP proxy\n            # we must notify proxy to tunnel connection\n            # so we send CONNECT command:\n            #   CONNECT www.python.org:443 HTTP/1.1\n            #   Host: www.python.org\n            #\n            # next we must do TLS handshake and so on\n            # to do this we must wrap raw socket into secure one\n            # asyncio handles this perfectly\n            proxy_req.method = 'CONNECT'\n            proxy_req.path = '{}:{}'.format(req.host, req.port)\n            key = (req.host, req.port, req.ssl)\n            conn = Connection(self, key, proxy_req,\n                              transport, proto, self._loop)\n            proxy_resp = proxy_req.send(conn.writer, conn.reader)\n            try:\n                resp = yield from proxy_resp.start(conn, True)\n            except:\n                proxy_resp.close()\n                conn.close()\n                raise\n            else:\n                if resp.status != 200:\n                    raise HttpProxyError(code=resp.status, message=resp.reason)\n                rawsock = transport.get_extra_info('socket', default=None)\n                if rawsock is None:\n                    raise RuntimeError(\n                        \"Transport does not expose socket instance\")\n                transport.pause_reading()\n                transport, proto = yield from self._loop.create_connection(\n                    self._factory, ssl=True, sock=rawsock,\n                    server_hostname=req.host, **kwargs)\n\n        return transport, proto\n\n\nclass UnixConnector(BaseConnector):\n    \"\"\"Unix socket connector.\n\n    :param str path: Unix socket path.\n    :param args: see :class:`BaseConnector`\n    :param kwargs: see :class:`BaseConnector`\n\n    Usage:\n\n    >>> conn = UnixConnector(path='/path/to/socket')\n    >>> resp = yield from request('GET', 'http://python.org', connector=conn)\n\n    \"\"\"\n\n    def __init__(self, path, *args, **kw):\n        super().__init__(*args, **kw)\n        self._path = path\n\n    @property\n    def path(self):\n        \"\"\"Path to unix socket.\"\"\"\n        return self._path\n\n    @asyncio.coroutine\n    def _create_connection(self, req, **kwargs):\n        return (yield from self._loop.create_unix_connection(\n            self._factory, self._path, **kwargs))\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:** TCPConnector Raises TypeError When Using ssl_context Parameter

**Description:**
When initializing `TCPConnector` with the `ssl_context` parameter, a `TypeError` is raised because the constructor does not recognize the `ssl_context` argument.

**Example Code:**
```python
import ssl
import aiohttp

ssl_ctx = ssl.create_default_context()
connector = aiohttp.TCPConnector(ssl_context=ssl_ctx)
```

**Expected Behavior:**
`TCPConnector` should accept the `ssl_context` parameter and utilize it for configuring SSL settings.

**Actual Behavior:**
A `TypeError` is raised indicating that `TCPConnector` received an unexpected keyword argument `ssl_context`.

**Error Message:**
```
TypeError: __init__() got an unexpected keyword argument 'ssl_context'
```
[/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/connector.py
__all__ = ['BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector']

import asyncio
import aiohttp
import functools
import http.cookies
import time
import ssl
import socket
import weakref

from .client import ClientRequest
from .errors import ServerDisconnectedError
from .errors import HttpProxyError, ProxyConnectionError
from .errors import ClientOSError, ClientTimeoutError
from .helpers import BasicAuth


class Connection(object):

    def __init__(self, connector, key, request, transport, protocol, loop):
        self._key = key
        self._connector = connector
        self._request = request
        self._transport = transport
        self._protocol = protocol
        self._loop = loop
        self.reader = protocol.reader
        self.writer = protocol.writer
        self._wr = weakref.ref(self, lambda wr, tr=self._transport: tr.close())

    @property
    def loop(self):
        return self._loop

    def close(self):
        if self._transport is not None:
            self._connector._release(
                self._key, self._request, self._transport, self._protocol,
                should_close=True)
            self._transport = None
            self._wr = None

    def release(self):
        if self._transport:
            self._connector._release(
                self._key, self._request, self._transport, self._protocol)
            self._transport = None
            self._wr = None

    def share_cookies(self, cookies):
        if self._connector._share_cookies:  # XXX
            self._connector.update_cookies(cookies)


class BaseConnector(object):
    """Base connector class.

    :param conn_timeout: (optional) Connect timeout.
    :param keepalive_timeout: (optional) Keep-alive timeout.
    :param bool share_cookies: Set to True to keep cookies between requests.
    :param bool force_close: Set to True to froce close and do reconnect
        after each request (and between redirects).
    :param loop: Optional event loop.
    """

    def __init__(self, *, conn_timeout=None, keepalive_timeout=30,
                 share_cookies=False, force_close=False, loop=None):
        self._conns = {}
        self._conn_timeout = conn_timeout
        self._keepalive_timeout = keepalive_timeout
        self._share_cookies = share_cookies
        self._cleanup_handle = None
        self._force_close = force_close

        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self._factory = functools.partial(
            aiohttp.StreamProtocol, loop=loop,
            disconnect_error=ServerDisconnectedError)

        self.cookies = http.cookies.SimpleCookie()
        self._wr = weakref.ref(
            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))

    def _cleanup(self):
        """Cleanup unused transports."""
        if self._cleanup_handle:
            self._cleanup_handle.cancel()
            self._cleanup_handle = None

        now = time.time()

        connections = {}
        for key, conns in self._conns.items():
            alive = []
            for transport, proto, t0 in conns:
                if transport is not None:
                    if proto and not proto.is_connected():
                        transport = None
                    elif (now - t0) > self._keepalive_timeout:
                        transport.close()
                        transport = None

                if transport:
                    alive.append((transport, proto, t0))
            if alive:
                connections[key] = alive

        if connections:
            self._cleanup_handle = self._loop.call_later(
                self._keepalive_timeout, self._cleanup)

        self._conns = connections
        self._wr = weakref.ref(
            self, lambda wr, f=self._do_close, conns=self._conns: f(conns))

    def _start_cleanup_task(self):
        if self._cleanup_handle is None:
            self._cleanup_handle = self._loop.call_later(
                self._keepalive_timeout, self._cleanup)

    def close(self):
        """Close all opened transports."""
        self._do_close(self._conns)

    @staticmethod
    def _do_close(conns):
        for key, data in conns.items():
            for transport, proto, td in data:
                transport.close()

        conns.clear()

    def update_cookies(self, cookies):
        """Update shared cookies."""
        if isinstance(cookies, dict):
            cookies = cookies.items()

        for name, value in cookies:
            if isinstance(value, http.cookies.Morsel):
                # use dict method because SimpleCookie class modifies value
                dict.__setitem__(self.cookies, name, value)
            else:
                self.cookies[name] = value

    @asyncio.coroutine
    def connect(self, req):
        """Get from pool or create new connection."""
        key = (req.host, req.port, req.ssl)

        if self._share_cookies:
            req.update_cookies(self.cookies.items())

        transport, proto = self._get(key)
        if transport is None:
            try:
                if self._conn_timeout:
                    transport, proto = yield from asyncio.wait_for(
                        self._create_connection(req),
                        self._conn_timeout, loop=self._loop)
                else:
                    transport, proto = yield from self._create_connection(req)
            except asyncio.TimeoutError as exc:
                raise ClientTimeoutError() from exc
            except OSError as exc:
                raise ClientOSError() from exc

        return Connection(self, key, req, transport, proto, self._loop)

    def _get(self, key):
        conns = self._conns.get(key)
        while conns:
            transport, proto, t0 = conns.pop()
            if transport is not None and proto.is_connected():
                if (time.time() - t0) > self._keepalive_timeout:
                    transport.close()
                    transport = None
                else:
                    return transport, proto

        return None, None

    def _release(self, key, req, transport, protocol, *, should_close=False):
        resp = req.response

        if not should_close:
            if resp is not None:
                if resp.message is None:
                    should_close = True
                else:
                    should_close = resp.message.should_close

            if self._force_close:
                should_close = True

        reader = protocol.reader
        if should_close or (reader.output and not reader.output.at_eof()):
            self._conns.pop(key, None)
            transport.close()
        else:
            conns = self._conns.get(key)
            if conns is None:
                conns = self._conns[key] = []
            conns.append((transport, protocol, time.time()))
            reader.unset_parser()

            self._start_cleanup_task()

    def _create_connection(self, req, *args, **kwargs):
        raise NotImplementedError()


class TCPConnector(BaseConnector):
    """TCP connector.

    :param bool verify_ssl: Set to True to check ssl certifications.
    :param bool resolve: Set to True to do DNS lookup for host name.
    :param familiy: socket address family
    :param args: see :class:`BaseConnector`
    :param kwargs: see :class:`BaseConnector`
    """

    def __init__(self, *args, verify_ssl=True,
                 resolve=False, family=socket.AF_INET, **kwargs):
        super().__init__(*args, **kwargs)

        self._verify_ssl = verify_ssl
        self._family = family
        self._resolve = resolve
        self._resolved_hosts = {}

    @property
    def verify_ssl(self):
        """Do check for ssl certifications?"""
        return self._verify_ssl

    @property
    def family(self):
        """Socket family like AF_INET."""
        return self._family

    @property
    def resolve(self):
        """Do DNS lookup for host name?"""
        return self._resolve

    @property
    def resolved_hosts(self):
        """The dict of (host, port) -> (ipaddr, port) pairs."""
        return dict(self._resolved_hosts)

    def clear_resolved_hosts(self, host=None, port=None):
        """Remove specified host/port or clear all resolve cache."""
        if host is not None and port is not None:
            key = (host, port)
            if key in self._resolved_hosts:
                del self._resolved_hosts[key]
        else:
            self._resolved_hosts.clear()

    @asyncio.coroutine
    def _resolve_host(self, host, port):
        if self._resolve:
            key = (host, port)

            if key not in self._resolved_hosts:
                infos = yield from self._loop.getaddrinfo(
                    host, port, type=socket.SOCK_STREAM, family=self._family)

                hosts = []
                for family, _, proto, _, address in infos:
                    hosts.append(
                        {'hostname': host,
                         'host': address[0], 'port': address[1],
                         'family': family, 'proto': proto,
                         'flags': socket.AI_NUMERICHOST})
                self._resolved_hosts[key] = hosts

            return list(self._resolved_hosts[key])
        else:
            return [{'hostname': host, 'host': host, 'port': port,
                     'family': self._family, 'proto': 0, 'flags': 0}]

    def _create_connection(self, req, **kwargs):
        """Create connection.

        Has same keyword arguments as BaseEventLoop.create_connection.
        """
        sslcontext = req.ssl
        if req.ssl and not self._verify_ssl:
            sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
            sslcontext.options |= ssl.OP_NO_SSLv2
            sslcontext.set_default_verify_paths()

        hosts = yield from self._resolve_host(req.host, req.port)

        while hosts:
            hinfo = hosts.pop()
            try:
                return (yield from self._loop.create_connection(
                    self._factory, hinfo['host'], hinfo['port'],
                    ssl=sslcontext, family=hinfo['family'],
                    proto=hinfo['proto'], flags=hinfo['flags'],
                    server_hostname=hinfo['hostname'] if sslcontext else None,
                    **kwargs))
            except OSError as exc:
                if not hosts:
                    raise ClientOSError('Can not connect to %s:%s' %
                                        (req.host, req.port)) from exc


class ProxyConnector(TCPConnector):
    """Http Proxy connector.

    :param str proxy: Proxy URL address. Only http proxy supported.
    :param proxy_auth: (optional) Proxy HTTP Basic Auth
    :type proxy_auth: aiohttp.helpers.BasicAuth
    :param args: see :class:`TCPConnector`
    :param kwargs: see :class:`TCPConnector`

    Usage:

    >>> conn = ProxyConnector(proxy="http://some.proxy.com")
    >>> resp = yield from request('GET', 'http://python.org', connector=conn)

    """

    def __init__(self, proxy, *args, proxy_auth=None, **kwargs):
        super().__init__(*args, **kwargs)
        self._proxy = proxy
        self._proxy_auth = proxy_auth
        assert proxy.startswith('http://'), (
            "Only http proxy supported", proxy)
        assert proxy_auth is None or isinstance(proxy_auth, BasicAuth), (
            "proxy_auth must be None or BasicAuth() tuple", proxy_auth)

    @property
    def proxy(self):
        """Proxy URL."""
        return self._proxy

    @asyncio.coroutine
    def _create_connection(self, req, **kwargs):
        proxy_req = ClientRequest(
            'GET', self._proxy,
            headers={'Host': req.host},
            auth=self._proxy_auth,
            loop=self._loop)
        try:
            transport, proto = yield from super()._create_connection(proxy_req)
        except OSError as exc:
            raise ProxyConnectionError(*exc.args) from exc

        req.path = '{scheme}://{host}{path}'.format(scheme=req.scheme,
                                                    host=req.netloc,
                                                    path=req.path)
        if 'AUTHORIZATION' in proxy_req.headers:
            auth = proxy_req.headers['AUTHORIZATION']
            del proxy_req.headers['AUTHORIZATION']
            req.headers['PROXY-AUTHORIZATION'] = auth

        if req.ssl:
            # For HTTPS requests over HTTP proxy
            # we must notify proxy to tunnel connection
            # so we send CONNECT command:
            #   CONNECT www.python.org:443 HTTP/1.1
            #   Host: www.python.org
            #
            # next we must do TLS handshake and so on
            # to do this we must wrap raw socket into secure one
            # asyncio handles this perfectly
            proxy_req.method = 'CONNECT'
            proxy_req.path = '{}:{}'.format(req.host, req.port)
            key = (req.host, req.port, req.ssl)
            conn = Connection(self, key, proxy_req,
                              transport, proto, self._loop)
            proxy_resp = proxy_req.send(conn.writer, conn.reader)
            try:
                resp = yield from proxy_resp.start(conn, True)
            except:
                proxy_resp.close()
                conn.close()
                raise
            else:
                if resp.status != 200:
                    raise HttpProxyError(code=resp.status, message=resp.reason)
                rawsock = transport.get_extra_info('socket', default=None)
                if rawsock is None:
                    raise RuntimeError(
                        "Transport does not expose socket instance")
                transport.pause_reading()
                transport, proto = yield from self._loop.create_connection(
                    self._factory, ssl=True, sock=rawsock,
                    server_hostname=req.host, **kwargs)

        return transport, proto


class UnixConnector(BaseConnector):
    """Unix socket connector.

    :param str path: Unix socket path.
    :param args: see :class:`BaseConnector`
    :param kwargs: see :class:`BaseConnector`

    Usage:

    >>> conn = UnixConnector(path='/path/to/socket')
    >>> resp = yield from request('GET', 'http://python.org', connector=conn)

    """

    def __init__(self, path, *args, **kw):
        super().__init__(*args, **kw)
        self._path = path

    @property
    def path(self):
        """Path to unix socket."""
        return self._path

    @asyncio.coroutine
    def _create_connection(self, req, **kwargs):
        return (yield from self._loop.create_unix_connection(
            self._factory, self._path, **kwargs))

```
--- 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