xfer_util: work on py2+py3

wormhole.send takes bytes, but the utility functions take strings. So
encode the JSON blob before sending, and decode it on the way back out.
This commit is contained in:
Brian Warner 2016-08-15 17:34:33 -07:00
parent fe29b3130b
commit d057b91371

View File

@ -34,7 +34,7 @@ def receive(reactor, appid, relay_url, code, use_tor=None, on_code=None):
if on_code:
on_code(code)
data = yield wh.get()
data = json.loads(data)
data = json.loads(data.decode("utf-8"))
offer = data.get('offer', None)
if not offer:
raise Exception(
@ -43,7 +43,7 @@ def receive(reactor, appid, relay_url, code, use_tor=None, on_code=None):
msg = None
if 'message' in offer:
msg = offer['message']
wh.send(json.dumps({"answer": {"message_ack": "ok"}}))
wh.send(json.dumps({"answer": {"message_ack": "ok"}}).encode("utf-8"))
else:
raise Exception(
@ -87,10 +87,10 @@ def send(reactor, appid, relay_url, data, code, use_tor=None, on_code=None):
"offer": {
"message": data
}
})
}).encode("utf-8")
)
data = yield wh.get()
data = json.loads(data)
data = json.loads(data.decode("utf-8"))
answer = data.get('answer', None)
yield wh.close()
if answer: