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:
parent
fe29b3130b
commit
d057b91371
|
@ -34,7 +34,7 @@ def receive(reactor, appid, relay_url, code, use_tor=None, on_code=None):
|
||||||
if on_code:
|
if on_code:
|
||||||
on_code(code)
|
on_code(code)
|
||||||
data = yield wh.get()
|
data = yield wh.get()
|
||||||
data = json.loads(data)
|
data = json.loads(data.decode("utf-8"))
|
||||||
offer = data.get('offer', None)
|
offer = data.get('offer', None)
|
||||||
if not offer:
|
if not offer:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
@ -43,7 +43,7 @@ def receive(reactor, appid, relay_url, code, use_tor=None, on_code=None):
|
||||||
msg = None
|
msg = None
|
||||||
if 'message' in offer:
|
if 'message' in offer:
|
||||||
msg = offer['message']
|
msg = offer['message']
|
||||||
wh.send(json.dumps({"answer": {"message_ack": "ok"}}))
|
wh.send(json.dumps({"answer": {"message_ack": "ok"}}).encode("utf-8"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
@ -87,10 +87,10 @@ def send(reactor, appid, relay_url, data, code, use_tor=None, on_code=None):
|
||||||
"offer": {
|
"offer": {
|
||||||
"message": data
|
"message": data
|
||||||
}
|
}
|
||||||
})
|
}).encode("utf-8")
|
||||||
)
|
)
|
||||||
data = yield wh.get()
|
data = yield wh.get()
|
||||||
data = json.loads(data)
|
data = json.loads(data.decode("utf-8"))
|
||||||
answer = data.get('answer', None)
|
answer = data.get('answer', None)
|
||||||
yield wh.close()
|
yield wh.close()
|
||||||
if answer:
|
if answer:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user