2022-02-15 19:11:53 +09:00
|
|
|
class Malformed(Exception):
|
|
|
|
pass
|
|
|
|
|
2022-02-16 18:55:30 +09:00
|
|
|
def parse_websocket_data(receipt):
|
2022-02-13 13:00:10 +09:00
|
|
|
if not isinstance(receipt, dict):
|
2022-02-15 19:11:53 +09:00
|
|
|
raise Malformed('not a json object')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
2022-02-15 19:11:53 +09:00
|
|
|
comment = receipt.get('comment')
|
|
|
|
if not isinstance(comment, str):
|
|
|
|
raise Malformed('malformed comment')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
|
|
|
nonce = receipt.get('nonce')
|
|
|
|
if not isinstance(nonce, str):
|
2022-02-15 19:11:53 +09:00
|
|
|
raise Malformed('malformed nonce')
|
2022-02-13 13:00:10 +09:00
|
|
|
|
2022-02-16 18:55:30 +09:00
|
|
|
return nonce, comment
|