Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def _handle_ws_reverse_universal(self):
self._add_ws_reverse_api_connection()
try:
while True:
try:
payload = json.loads(await websocket.receive())
except json.JSONDecodeError:
payload = None
if isinstance(payload, dict) and 'post_type' in payload:
# is a event
asyncio.ensure_future(
self._handle_event_payload_with_response(payload))
elif payload:
# is a api result
ResultStore.add(payload)
finally:
self._remove_ws_reverse_api_connection()
async def _handle_ws_reverse_api(self):
self._validate_access_token()
# noinspection PyProtectedMember
ws = websocket._get_current_object()
self_id = websocket.headers.get('X-Self-ID', '*')
self._connected_ws_reverse_api_clients[self_id] = ws
try:
while True:
try:
ResultStore.add(json.loads(await websocket.receive()))
except json.JSONDecodeError:
pass
finally:
if self_id in self._connected_ws_reverse_api_clients:
# we must check the existence here,
# because we allow wildcard ws connections,
# that is, the self_id may be '*'
del self._connected_ws_reverse_api_clients[self_id]
async def _handle_ws_reverse_api(self):
self._add_ws_reverse_api_connection()
try:
while True:
try:
ResultStore.add(json.loads(await websocket.receive()))
except json.JSONDecodeError:
pass
finally:
self._remove_ws_reverse_api_connection()