feat: Semaine 9
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import json, hashlib, time
|
||||
# https://docs.python.org/3/library/json.html
|
||||
# https://docs.python.org/3/library/hashlib.html
|
||||
|
||||
def compute_hash(content):
|
||||
return hashlib.sha256(content.encode()).hexdigest()
|
||||
|
||||
def get_timestamp():
|
||||
return time.time()
|
||||
|
||||
async def send_json(writer, data):
|
||||
message = f"{json.dumps(data)}\n"
|
||||
writer.write(message.encode())
|
||||
await writer.drain()
|
||||
|
||||
async def receive_json(reader):
|
||||
data = await reader.readline()
|
||||
if not data:
|
||||
return None
|
||||
return json.loads(data.decode())
|
||||
Reference in New Issue
Block a user