From a2fc37121bbe3a9965b4d0e86220305064154f40 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Thu, 1 Mar 2018 22:35:58 -0800 Subject: [PATCH] migrating all to async syntax --- tests/test_keep_alive_timeout.py | 16 +++++++-------- tests/test_request_timeout.py | 34 +++++++++++++++----------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/tests/test_keep_alive_timeout.py b/tests/test_keep_alive_timeout.py index be2c6f0d..4df00640 100644 --- a/tests/test_keep_alive_timeout.py +++ b/tests/test_keep_alive_timeout.py @@ -16,10 +16,10 @@ class ReuseableTCPConnector(TCPConnector): self.old_proto = None if aiohttp.__version__ >= '3.0': - @asyncio.coroutine - def connect(self, req, traces=None): - new_conn = yield from super(ReuseableTCPConnector, self)\ - .connect(req, traces=traces) + + async def connect(self, req, traces=None): + new_conn = await super(ReuseableTCPConnector, self)\ + .connect(req, traces=traces) if self.old_proto is not None: if self.old_proto != new_conn._protocol: raise RuntimeError( @@ -28,10 +28,10 @@ class ReuseableTCPConnector(TCPConnector): self.old_proto = new_conn._protocol return new_conn else: - @asyncio.coroutine - def connect(self, req): - new_conn = yield from super(ReuseableTCPConnector, self)\ - .connect(req) + + async def connect(self, req): + new_conn = await super(ReuseableTCPConnector, self)\ + .connect(req) if self.old_proto is not None: if self.old_proto != new_conn._protocol: raise RuntimeError( diff --git a/tests/test_request_timeout.py b/tests/test_request_timeout.py index d667d0a4..80dd7218 100644 --- a/tests/test_request_timeout.py +++ b/tests/test_request_timeout.py @@ -28,19 +28,18 @@ class DelayableTCPConnector(TCPConnector): acting_as = self._acting_as return getattr(acting_as, item) - @asyncio.coroutine - def start(self, connection, read_until_eof=False): + async def start(self, connection, read_until_eof=False): if self.send_task is None: raise RuntimeError("do a send() before you do a start()") - resp = yield from self.send_task + resp = await self.send_task self.send_task = None self.resp = resp self._acting_as = self.resp self.orig_start = getattr(resp, 'start') try: - ret = yield from self.orig_start(connection, - read_until_eof) + ret = await self.orig_start(connection, + read_until_eof) except Exception as e: raise e return ret @@ -51,12 +50,11 @@ class DelayableTCPConnector(TCPConnector): if self.send_task is not None: self.send_task.cancel() - @asyncio.coroutine - def delayed_send(self, *args, **kwargs): + async def delayed_send(self, *args, **kwargs): req = self.req if self.delay and self.delay > 0: #sync_sleep(self.delay) - _ = yield from asyncio.sleep(self.delay) + await asyncio.sleep(self.delay) t = req.loop.time() print("sending at {}".format(t), flush=True) conn = next(iter(args)) # first arg is connection @@ -81,27 +79,27 @@ class DelayableTCPConnector(TCPConnector): self._pre_request_delay = _pre_request_delay if aiohttp.__version__ >= '3.0': - @asyncio.coroutine - def connect(self, req, traces=None): + + async def connect(self, req, traces=None): d_req = DelayableTCPConnector.\ RequestContextManager(req, self._pre_request_delay) - conn = yield from super(DelayableTCPConnector, self).connect(req, traces=traces) + conn = await super(DelayableTCPConnector, self).connect(req, traces=traces) if self._post_connect_delay and self._post_connect_delay > 0: - _ = yield from asyncio.sleep(self._post_connect_delay, - loop=self._loop) + await asyncio.sleep(self._post_connect_delay, + loop=self._loop) req.send = d_req.send t = req.loop.time() print("Connected at {}".format(t), flush=True) return conn else: - @asyncio.coroutine - def connect(self, req): + + async def connect(self, req): d_req = DelayableTCPConnector.\ RequestContextManager(req, self._pre_request_delay) - conn = yield from super(DelayableTCPConnector, self).connect(req) + conn = await super(DelayableTCPConnector, self).connect(req) if self._post_connect_delay and self._post_connect_delay > 0: - _ = yield from asyncio.sleep(self._post_connect_delay, - loop=self._loop) + await asyncio.sleep(self._post_connect_delay, + loop=self._loop) req.send = d_req.send t = req.loop.time() print("Connected at {}".format(t), flush=True)