squashed commit of many breaking changes

Dropping Support for Python 3.7; adding support for Python 3.9
This commit is contained in:
Fabian Dill
2020-10-19 08:26:31 +02:00
parent add0762114
commit 4f8c737eec
16 changed files with 149 additions and 150 deletions

View File

@@ -1,33 +1,34 @@
from __future__ import annotations
import asyncio
import json
import logging
import typing
from json import loads, dumps
import websockets
class Node:
endpoints: typing.List
dumper = staticmethod(dumps)
loader = staticmethod(loads)
def __init__(self):
self.endpoints = []
def broadcast_all(self, msgs):
msgs = json.dumps(msgs)
msgs = self.dumper(msgs)
for endpoint in self.endpoints:
asyncio.create_task(self.send_json_msgs(endpoint, msgs))
asyncio.create_task(self.send_encoded_msgs(endpoint, msgs))
async def send_msgs(self, endpoint: Endpoint, msgs):
if not endpoint.socket or not endpoint.socket.open or endpoint.socket.closed:
return
try:
await endpoint.socket.send(json.dumps(msgs))
await endpoint.socket.send(self.dumper(msgs))
except websockets.ConnectionClosed:
logging.exception("Exception during send_msgs")
await self.disconnect(endpoint)
async def send_json_msgs(self, endpoint: Endpoint, msg: str):
async def send_encoded_msgs(self, endpoint: Endpoint, msg: str):
if not endpoint.socket or not endpoint.socket.open or endpoint.socket.closed:
return
try: