Drop Python 3.4 and switch to async / await syntax for asyncio. Fixes #1425

This commit is contained in:
grossmj committed 2018-10-15 17:05:49 +07:00
1 parent 8baa480b79
commit 76af98404a
119 files changed
+2432 -3084

No files matched your search

+7 -10
View File
@@ -42,9 +42,8 @@ class Query:
self._api_version = api_version
self._session = None
@asyncio.coroutine
def close(self):
yield from self._session.close()
async def close(self):
await self._session.close()
def post(self, path, body={}, **kwargs):
return self._fetch("POST", path, body, **kwargs)
@@ -69,9 +68,8 @@ class Query:
"""
self._session = aiohttp.ClientSession()
@asyncio.coroutine
def go_request(future):
response = yield from self._session.ws_connect(self.get_url(path))
async def go_request(future):
response = await self._session.ws_connect(self.get_url(path))
future.set_result(response)
future = asyncio.Future()
asyncio.ensure_future(go_request(future))
@@ -87,14 +85,13 @@ class Query:
"""
return self._loop.run_until_complete(asyncio.ensure_future(self._async_fetch(method, path, body=body, **kwargs)))
@asyncio.coroutine
def _async_fetch(self, method, path, body=None, **kwargs):
async def _async_fetch(self, method, path, body=None, **kwargs):
if body is not None and not kwargs.get("raw", False):
body = json.dumps(body)
connector = aiohttp.TCPConnector()
response = yield from aiohttp.request(method, self.get_url(path), data=body, loop=self._loop, connector=connector)
response.body = yield from response.read()
response = await aiohttp.request(method, self.get_url(path), data=body, loop=self._loop, connector=connector)
response.body = await response.read()
x_route = response.headers.get('X-Route', None)
if x_route is not None:
response.route = x_route.replace("/v{}".format(self._api_version), "")
+4 -4
View File
@@ -341,10 +341,10 @@ def test_stop_capture(http_controller, tmpdir, project, compute, async_run):
def test_pcap(http_controller, tmpdir, project, compute, loop):
@asyncio.coroutine
def go(future):
response = yield from aiohttp.request("GET", http_controller.get_url("/projects/{}/links/{}/pcap".format(project.id, link.id)))
response.body = yield from response.content.read(5)
async def go(future):
response = await aiohttp.request("GET", http_controller.get_url("/projects/{}/links/{}/pcap".format(project.id, link.id)))
response.body = await response.content.read(5)
response.close()
future.set_result(response)
@@ -169,13 +169,13 @@ def test_load_project(http_controller, project, config):
def test_notification(http_controller, project, controller, loop, async_run):
@asyncio.coroutine
def go():
async def go():
connector = aiohttp.TCPConnector()
response = yield from aiohttp.request("GET", http_controller.get_url("/projects/{project_id}/notifications".format(project_id=project.id)), connector=connector)
response.body = yield from response.content.read(200)
response = await aiohttp.request("GET", http_controller.get_url("/projects/{project_id}/notifications".format(project_id=project.id)), connector=connector)
response.body = await response.content.read(200)
controller.notification.project_emit("node.created", {"a": "b"})
response.body += yield from response.content.readany()
response.body += await response.content.readany()
response.close()
return response
+2 -2
View File
@@ -31,8 +31,8 @@ def web_server():
def test_shutdown_local(http_controller, web_server, config):
@asyncio.coroutine
def hello():
async def hello():
return 0
web_server.shutdown_server.return_value = hello()