summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-05-29 18:51:09 +0300
committerLars Wirzenius <liw@liw.fi>2021-05-29 18:51:09 +0300
commit19fd3032fc36cce09be4db89fc6580f7e124bb63 (patch)
treec555e0179de3c02b0e852c0df48cfa76ac1e95ef
parent88165aace3c1586adfee8285c9e9689a00bb2f31 (diff)
downloadoso-work-sample-19fd3032fc36cce09be4db89fc6580f7e124bb63.tar.gz
chore: reformat for consistency (placate flake8)
Sponsored-by: author
-rw-r--r--max-client.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/max-client.py b/max-client.py
index d691909..488fc6b 100644
--- a/max-client.py
+++ b/max-client.py
@@ -10,27 +10,32 @@ class Compare:
right: int
type: str = "compare"
+
@dataclass
class ComparisonResult:
request_id: int
answer: bool
type: str = "comp_result"
+
@dataclass
class ComputeMax:
length: int
type: str = "compute_max"
+
@dataclass
class ComputeMin:
length: int
type: str = "compute_min"
+
@dataclass
class Done:
result: int
type: str = "done"
+
def message_to_struct(message):
if message["type"] == "compare":
return Compare(**message)
@@ -43,6 +48,7 @@ def message_to_struct(message):
elif message["type"] == "done":
return Done(**message)
+
class Client:
def __init__(self, address, log=False):
self.address = address if address else "http://localhost:5000"
@@ -72,15 +78,21 @@ class Client:
request_id = next_message.request_id
left = next_message.left
right = next_message.right
- next_message = self.send(ComparisonResult(request_id, values[left] < values[right]))
+ next_message = self.send(
+ ComparisonResult(request_id, values[left] < values[right])
+ )
else:
raise Exception("Unexpected message: ", next_message)
if __name__ == "__main__":
- parser = argparse.ArgumentParser(description='Run the max computer')
- parser.add_argument('--address', type=str, required=False,
- help='address of the max computer (defaults to http://localhost:5000)')
+ parser = argparse.ArgumentParser(description="Run the max computer")
+ parser.add_argument(
+ "--address",
+ type=str,
+ required=False,
+ help="address of the max computer (defaults to http://localhost:5000)",
+ )
args = parser.parse_args()
client = Client(args.address, log=True)