Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket.send_bytes is a coroutine as of aiohttp 3.0 changing transp… #16

Merged
merged 2 commits into from
Mar 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions aiogremlin/driver/aiohttp/transport.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import aiohttp

from gremlin_python.driver import transport
Expand All @@ -18,21 +19,23 @@ async def connect(self, url, *, ssl_context=None):
self._ws = await self._client_session.ws_connect(url)
self._connected = True

def write(self, message):
self._ws.send_bytes(message)
async def write(self, message):
coro = self._ws.send_bytes(message)
if asyncio.iscoroutine(coro):
await coro

async def read(self):
data = await self._ws.receive()
if data.tp == aiohttp.WSMsgType.close:
if data.type == aiohttp.WSMsgType.close:
await self._transport.close()
raise RuntimeError("Connection closed by server")
elif data.tp == aiohttp.WSMsgType.error:
elif data.type == aiohttp.WSMsgType.error:
# This won't raise properly, fix
raise data.data
elif data.tp == aiohttp.WSMsgType.closed:
elif data.type == aiohttp.WSMsgType.closed:
# Hmm
raise RuntimeError("Connection closed by server")
elif data.tp == aiohttp.WSMsgType.text:
elif data.type == aiohttp.WSMsgType.text:
# Should return bytes
data = data.data.strip().encode('utf-8')
else:
Expand Down