fix some py2-isms that broke py3

This also changes the can-I-run-wormhole check to use C.UTF-8 instead of
en_US.UTF-8, which seems necessary to hush Click on py3. See issue #127 for
more discusson.
This commit is contained in:
Brian Warner 2017-04-03 19:07:53 -07:00
parent b981b4260d
commit d0d2992d44
3 changed files with 10 additions and 9 deletions

View File

@ -1,6 +1,7 @@
from __future__ import print_function, absolute_import, unicode_literals
from zope.interface import implementer from zope.interface import implementer
import contextlib import contextlib
from _interfaces import IJournal from ._interfaces import IJournal
@implementer(IJournal) @implementer(IJournal)
class Journal(object): class Journal(object):

View File

@ -228,7 +228,7 @@ class Key(unittest.TestCase):
k.got_code(code) k.got_code(code)
self.assertEqual(len(events), 1) self.assertEqual(len(events), 1)
self.assertEqual(events[0][:2], ("m.add_message", "pake")) self.assertEqual(events[0][:2], ("m.add_message", "pake"))
msg1_json = events[0][2] msg1_json = events[0][2].decode("utf-8")
events[:] = [] events[:] = []
msg1 = json.loads(msg1_json) msg1 = json.loads(msg1_json)
msg1_bytes = hexstr_to_bytes(msg1["pake_v1"]) msg1_bytes = hexstr_to_bytes(msg1["pake_v1"])
@ -249,9 +249,9 @@ class Key(unittest.TestCase):
k.got_code(code) k.got_code(code)
self.assertEqual(len(events), 1) self.assertEqual(len(events), 1)
self.assertEqual(events[0][:2], ("m.add_message", "pake")) self.assertEqual(events[0][:2], ("m.add_message", "pake"))
pake_1_json = events[0][2] pake_1_json = events[0][2].decode("utf-8")
pake_1 = json.loads(pake_1_json) pake_1 = json.loads(pake_1_json)
self.assertEqual(pake_1.keys(), ["pake_v1"]) # value is PAKE stuff self.assertEqual(list(pake_1.keys()), ["pake_v1"]) # value is PAKE stuff
events[:] = [] events[:] = []
bad_pake_d = {"not_pake_v1": "stuff"} bad_pake_d = {"not_pake_v1": "stuff"}
k.got_pake(dict_to_bytes(bad_pake_d)) k.got_pake(dict_to_bytes(bad_pake_d))

View File

@ -175,11 +175,11 @@ class ScriptsBase:
# Setting LANG/LC_ALL to a unicode-capable locale is necessary to # Setting LANG/LC_ALL to a unicode-capable locale is necessary to
# convince Click to not complain about a forced-ascii locale. My # convince Click to not complain about a forced-ascii locale. My
# apologies to folks who want to run tests on a machine that doesn't # apologies to folks who want to run tests on a machine that doesn't
# have the en_US.UTF-8 locale installed. # have the C.UTF-8 locale installed.
wormhole = self.find_executable() wormhole = self.find_executable()
d = getProcessOutputAndValue(wormhole, ["--version"], d = getProcessOutputAndValue(wormhole, ["--version"],
env=dict(LC_ALL="en_US.UTF-8", env=dict(LC_ALL="C.UTF-8",
LANG="en_US.UTF-8")) LANG="C.UTF-8"))
def _check(res): def _check(res):
out, err, rc = res out, err, rc = res
if rc != 0: if rc != 0:
@ -335,7 +335,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
send_d = getProcessOutputAndValue( send_d = getProcessOutputAndValue(
wormhole_bin, send_args, wormhole_bin, send_args,
path=send_dir, path=send_dir,
env=dict(LC_ALL="en_US.UTF-8", LANG="en_US.UTF-8"), env=dict(LC_ALL="C.UTF-8", LANG="C.UTF-8"),
) )
recv_args = [ recv_args = [
'--relay-url', self.relayurl, '--relay-url', self.relayurl,
@ -351,7 +351,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase):
receive_d = getProcessOutputAndValue( receive_d = getProcessOutputAndValue(
wormhole_bin, recv_args, wormhole_bin, recv_args,
path=receive_dir, path=receive_dir,
env=dict(LC_ALL="en_US.UTF-8", LANG="en_US.UTF-8"), env=dict(LC_ALL="C.UTF-8", LANG="C.UTF-8"),
) )
(send_res, receive_res) = yield gatherResults([send_d, receive_d], (send_res, receive_res) = yield gatherResults([send_d, receive_d],