blob: 0b04c27f7e9c3b7fdee98a70c3bb7a6158a5172a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import json
import toggle_game
def recieve_game(game_json: str) -> dict:
game = json.loads(game_json)
if game['size'] < 0 or game['size'] > 100:
raise Exception("Invalid Board size")
if game['finished']:
raise Exception("The game is finished")
if game['human_turn']:
raise Exception("Not the computer's turn")
if game['version'] != "0.0.0":
raise Exception("Invalid version")
return game
def send_game(game: dict) -> str:
# TODO: mutate game
game_json = json.dumps(game)
return game_json
def application(env, start_response):
headers = [('Content-Type', 'application/json')]
start_response('200 OK', headers)
if env['REQUEST_METHOD'] == 'POST':
game = {'test': 0}
try:
game = json.load(env['wsgi.input'])
except json.JSONDecodeError:
return [json.dumps({'failure': True}).encode('utf-8')]
game['modified'] = 'modified by the server :)'
game_json = json.dumps(game)
return [game_json.encode('utf-8')]
return [json.dumps({'not_post': True}).encode('utf-8')]
def main():
pass
|