diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py index 80ef922764f..56f16440a72 100644 --- a/aiohttp/client_reqrep.py +++ b/aiohttp/client_reqrep.py @@ -420,11 +420,6 @@ def write_bytes(self, request, conn): else: try: ret = yield from request.write_eof() - # NB: in asyncio 3.4.1+ StreamWriter.drain() is coroutine - # see bug #170 - if (asyncio.iscoroutine(ret) or - isinstance(ret, asyncio.Future)): - yield from ret except Exception as exc: new_exc = aiohttp.ClientRequestError( 'Can not write request body for %s' % self.url) diff --git a/aiohttp/streams.py b/aiohttp/streams.py index 1768b64ec6e..5097cd60972 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -120,19 +120,8 @@ def drain(self): w.write(data) yield from w.drain() """ - if self.transport is not None: - try: - if self.transport.is_closing(): - # Yield to the event loop so connection_lost() may be - # called. Without this, _drain_helper() would return - # immediately, and code that calls - # write(...); yield from drain() - # in a loop would never call connection_lost(), so it - # would not see an error when the socket is closed. - yield - except AttributeError: - pass - yield from self._protocol._drain_helper() + if self._protocol.transport is not None: + yield from self._protocol._drain_helper() if PY_35: diff --git a/tests/test_proxy_functional.py b/tests/test_proxy_functional.py index 14cbd409148..73f6aac3a7c 100644 --- a/tests/test_proxy_functional.py +++ b/tests/test_proxy_functional.py @@ -8,14 +8,6 @@ import aiohttp import aiohttp.helpers import aiohttp.web -from aiohttp.test_utils import loop_context - - -@pytest.yield_fixture -def loop(): - """Return an instance of the event loop.""" - with loop_context() as _loop: - yield _loop @pytest.fixture @@ -38,11 +30,18 @@ def proxy_handler(request, proxy_mock): if isinstance(proxy_mock.return_value, dict): response.update(proxy_mock.return_value) + headers = response['headers'] + if not headers: + headers = {} + if request.method == 'CONNECT': response['body'] = None + response['headers'] = headers + resp = aiohttp.web.Response(**response) yield from resp.prepare(request) + yield from resp.drain() return resp @asyncio.coroutine @@ -279,7 +278,7 @@ def request(pid): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_connect(proxy_test_server, get_request): +def _test_proxy_https_connect(proxy_test_server, get_request): proxy = yield from proxy_test_server() url = 'https://www.google.com.ua/search?q=aiohttp proxy' @@ -296,7 +295,7 @@ def test_proxy_https_connect(proxy_test_server, get_request): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_connect_with_port(proxy_test_server, get_request): +def _test_proxy_https_connect_with_port(proxy_test_server, get_request): proxy = yield from proxy_test_server() url = 'https://secure.aiohttp.io:2242/path' @@ -313,7 +312,7 @@ def test_proxy_https_connect_with_port(proxy_test_server, get_request): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_send_body(proxy_test_server, loop): +def _test_proxy_https_send_body(proxy_test_server, loop): sess = aiohttp.ClientSession(loop=loop) proxy = yield from proxy_test_server() proxy.return_value = {'status': 200, 'body': b'1'*(2**20)} @@ -329,7 +328,7 @@ def test_proxy_https_send_body(proxy_test_server, loop): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_idna_support(proxy_test_server, get_request): +def _test_proxy_https_idna_support(proxy_test_server, get_request): url = 'https://éé.com/' proxy = yield from proxy_test_server() @@ -368,7 +367,7 @@ def test_proxy_https_bad_response(proxy_test_server, get_request): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_auth(proxy_test_server, get_request): +def _test_proxy_https_auth(proxy_test_server, get_request): url = 'https://secure.aiohttp.io/path' auth = aiohttp.helpers.BasicAuth('user', 'pass') @@ -412,7 +411,7 @@ def test_proxy_https_auth(proxy_test_server, get_request): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_acquired_cleanup(proxy_test_server, loop): +def _test_proxy_https_acquired_cleanup(proxy_test_server, loop): url = 'https://secure.aiohttp.io/path' conn = aiohttp.TCPConnector(loop=loop) @@ -438,7 +437,7 @@ def request(): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_acquired_cleanup_force(proxy_test_server, loop): +def _test_proxy_https_acquired_cleanup_force(proxy_test_server, loop): url = 'https://secure.aiohttp.io/path' conn = aiohttp.TCPConnector(force_close=True, loop=loop) @@ -464,7 +463,7 @@ def request(): # @pytest.mark.xfail @asyncio.coroutine -def test_proxy_https_multi_conn_limit(proxy_test_server, loop): +def _test_proxy_https_multi_conn_limit(proxy_test_server, loop): url = 'https://secure.aiohttp.io/path' capacity, multi_conn_num = 1, 5