tuxbot-bot/venv/lib/python3.7/site-packages/websockets/py36/protocol.py
2019-12-16 18:12:10 +01:00

20 lines
428 B
Python

from ..exceptions import ConnectionClosed
async def __aiter__(self):
"""
Iterate on received messages.
Exit normally when the connection is closed with code 1000.
Raise an exception in other cases.
"""
try:
while True:
yield await self.recv()
except ConnectionClosed as exc:
if exc.code == 1000 or exc.code == 1001:
return
else:
raise