if active_key:
return self.get_poll(active_key)
- def get_poll(self, key: str) -> Poll | None:
- poll_bin = self.db.get(key.encode())
+ def get_poll(self, key: str | bytes) -> Poll | None:
+ binkey = key if isinstance(key, bytes) else key.encode()
+ poll_bin = self.db.get(binkey)
if poll_bin:
poll = json.loads(poll_bin.decode("utf-8"))
return Poll.from_json(poll)
self.db.put(key, poll.to_json().encode())
self.db.put(self.KEY_ACTIVE, key)
- def close_poll(self, key: str):
+ def close_poll(self, key: str | bytes):
+ binkey = key if isinstance(key, bytes) else key.encode()
active_key = self.db.get(self.KEY_ACTIVE)
- if active_key == key.encode():
+ if active_key == binkey:
self.db.delete(self.KEY_ACTIVE)
def check_poll(self):