Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
deluxghost committed Feb 19, 2018
1 parent ca94514 commit 4469ad9
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions ASF_IPC/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import asyncio
import posixpath
import urllib.parse as urlparse
from http.client import responses
import requests
import websockets
from websockets.exceptions import CLOSE_CODES

from . import error
from . import response
Expand Down Expand Up @@ -123,28 +121,8 @@ def post_games_to_redeem_in_background(self, botname, games):
async def get_log(self):
ws_url = self._build_endpoint('Log', ws=True)
headers = self._add_auth()
try:
websocket = await websockets.connect(ws_url, extra_headers=headers)
except ConnectionRefusedError:
raise error.ASF_ConnectionError(ws_url)
while True:
try:
async with websockets.connect(ws_url, extra_headers=headers) as websocket:
while True:
resp = await websocket.recv()
except websockets.exceptions.InvalidStatusCode as e:
code = None
message = ''
if hasattr(e, 'status_code'):
code = e.status_code
if code in CLOSE_CODES:
message = CLOSE_CODES[code]
elif code in responses:
message = responses[code]
elif hasattr(e, 'message'):
message = e.message
else:
message = 'Unknown'
elif hasattr(e, message):
message = e.message
raise error.ASF_ResponseError(message, code)
resp = response.WebsocketResponse(resp)
yield resp.result
resp = response.WebsocketResponse(resp)
yield resp.result

0 comments on commit 4469ad9

Please sign in to comment.