From 2c25b4d97dbf091282bb699d0d7cf3f12413ede4 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 12:47:51 -0700 Subject: [PATCH 01/11] `u""` cleanup on wormhole.py --- src/wormhole/wormhole.py | 64 ++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index 8f71c1c..3a716b1 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -77,15 +77,15 @@ class _GetCode: @inlineCallbacks def go(self): with self._timing.add("allocate"): - self._send_command(u"allocate") + self._send_command("allocate") nameplate_id = yield self._allocated_d code = codes.make_code(nameplate_id, self._code_length) - assert isinstance(code, type(u"")), type(code) + assert isinstance(code, type("")), type(code) returnValue(code) def _response_handle_allocated(self, msg): nid = msg["nameplate"] - assert isinstance(nid, type(u"")), type(nid) + assert isinstance(nid, type("")), type(nid) self._allocated_d.callback(nid) class _InputCode: @@ -99,7 +99,7 @@ class _InputCode: @inlineCallbacks def _list(self): self._lister_d = defer.Deferred() - self._send_command(u"list") + self._send_command("list") nameplates = yield self._lister_d self._lister_d = None returnValue(nameplates) @@ -135,8 +135,8 @@ class _InputCode: nids = [] for n in nameplates: assert isinstance(n, dict), type(n) - nameplate_id = n[u"id"] - assert isinstance(nameplate_id, type(u"")), type(nameplate_id) + nameplate_id = n["id"] + assert isinstance(nameplate_id, type("")), type(nameplate_id) nids.append(nameplate_id) self._lister_d.callback(nids) @@ -202,7 +202,7 @@ class _WelcomeHandler: if "error" in welcome: return self._signal_error(WelcomeError(welcome["error"]), - u"unwelcome") + "unwelcome") # states for nameplates, mailboxes, and the websocket connection (CLOSED, OPENING, OPEN, CLOSING) = ("closed", "opening", "open", "closing") @@ -378,7 +378,7 @@ class _Wormhole: self._connection_state = OPEN if self._closing: return self._maybe_finished_closing() - self._ws_send_command(u"bind", appid=self._appid, side=self._side) + self._ws_send_command("bind", appid=self._appid, side=self._side) self._maybe_claim_nameplate() self._maybe_send_pake() waiters, self._connection_waiters = self._connection_waiters, [] @@ -462,7 +462,7 @@ class _Wormhole: # entry point 3: paste in a fully-formed code def _API_set_code(self, code): self._timing.add("API set_code") - if not isinstance(code, type(u"")): raise TypeError(type(code)) + if not isinstance(code, type("")): raise TypeError(type(code)) if self._code is not None: raise UsageError self._event_learned_code(code) @@ -488,7 +488,7 @@ class _Wormhole: if not mo: raise ValueError("code (%s) must start with NN-" % code) nid = mo.group(1) - assert isinstance(nid, type(u"")), type(nid) + assert isinstance(nid, type("")), type(nid) self._nameplate_id = nid # fire more events self._maybe_build_msg1() @@ -516,12 +516,12 @@ class _Wormhole: def _maybe_claim_nameplate(self): if not (self._nameplate_id and self._connection_state == OPEN): return - self._ws_send_command(u"claim", nameplate=self._nameplate_id) + self._ws_send_command("claim", nameplate=self._nameplate_id) self._nameplate_state = OPEN def _response_handle_claimed(self, msg): mailbox_id = msg["mailbox"] - assert isinstance(mailbox_id, type(u"")), type(mailbox_id) + assert isinstance(mailbox_id, type("")), type(mailbox_id) self._mailbox_id = mailbox_id self._event_learned_mailbox() @@ -530,7 +530,7 @@ class _Wormhole: assert self._mailbox_state == CLOSED, self._mailbox_state if self._closing: return - self._ws_send_command(u"open", mailbox=self._mailbox_id) + self._ws_send_command("open", mailbox=self._mailbox_id) self._mailbox_state = OPEN # causes old messages to be sent now, and subscribes to new messages self._maybe_send_pake() @@ -542,14 +542,14 @@ class _Wormhole: and self._mailbox_state == OPEN and self._flag_need_to_send_PAKE): return - body = {u"pake_v1": bytes_to_hexstr(self._msg1)} + body = {"pake_v1": bytes_to_hexstr(self._msg1)} payload = dict_to_bytes(body) - self._msg_send(u"pake", payload) + self._msg_send("pake", payload) self._flag_need_to_send_PAKE = False def _event_received_pake(self, pake_msg): payload = bytes_to_dict(pake_msg) - msg2 = hexstr_to_bytes(payload[u"pake_v1"]) + msg2 = hexstr_to_bytes(payload["pake_v1"]) with self._timing.add("pake2", waiting="crypto"): self._key = self._sp.finish(msg2) self._event_established_key() @@ -571,7 +571,7 @@ class _Wormhole: # dictionary of version flags to let the other Wormhole know what # we're capable of (for future expansion) plaintext = dict_to_bytes(self._my_versions) - phase = u"version" + phase = "version" data_key = self._derive_phase_key(self._side, phase) encrypted = self._encrypt_data(data_key, plaintext) self._msg_send(phase, encrypted) @@ -616,13 +616,13 @@ class _Wormhole: self._version_checked = True side, body = self._version_message - data_key = self._derive_phase_key(side, u"version") + data_key = self._derive_phase_key(side, "version") try: plaintext = self._decrypt_data(data_key, body) except CryptoError: # this makes all API calls fail if self.DEBUG: print("CONFIRM FAILED") - self._signal_error(WrongPasswordError(), u"scary") + self._signal_error(WrongPasswordError(), "scary") return msg = bytes_to_dict(plaintext) self._version_received(msg) @@ -643,8 +643,8 @@ class _Wormhole: self._maybe_send_phase_messages() def _derive_phase_key(self, side, phase): - assert isinstance(side, type(u"")), type(side) - assert isinstance(phase, type(u"")), type(phase) + assert isinstance(side, type("")), type(side) + assert isinstance(phase, type("")), type(phase) side_bytes = side.encode("ascii") phase_bytes = phase.encode("ascii") purpose = (b"wormhole:phase:" @@ -663,7 +663,7 @@ class _Wormhole: for pm in plaintexts: (phase_int, plaintext) = pm assert isinstance(phase_int, int), type(phase_int) - phase = u"%d" % phase_int + phase = "%d" % phase_int data_key = self._derive_phase_key(self._side, phase) encrypted = self._encrypt_data(data_key, plaintext) self._msg_send(phase, encrypted) @@ -689,7 +689,7 @@ class _Wormhole: # TODO: retry on failure, with exponential backoff. We're guarding # against the rendezvous server being temporarily offline. self._timing.add("add", phase=phase) - self._ws_send_command(u"add", phase=phase, body=bytes_to_hexstr(body)) + self._ws_send_command("add", phase=phase, body=bytes_to_hexstr(body)) def _event_mailbox_used(self): if self.DEBUG: print("_event_mailbox_used") @@ -701,7 +701,7 @@ class _Wormhole: if self._error: raise self._error if self._key is None: raise UsageError # call derive_key after get_verifier() or get() - if not isinstance(purpose, type(u"")): raise TypeError(type(purpose)) + if not isinstance(purpose, type("")): raise TypeError(type(purpose)) return self._derive_key(to_bytes(purpose), length) def _derive_key(self, purpose, length=SecretBox.KEY_SIZE): @@ -713,7 +713,7 @@ class _Wormhole: def _response_handle_message(self, msg): side = msg["side"] phase = msg["phase"] - assert isinstance(phase, type(u"")), type(phase) + assert isinstance(phase, type("")), type(phase) body = hexstr_to_bytes(msg["body"]) if side == self._side: return @@ -726,9 +726,9 @@ class _Wormhole: if self._closing: log.msg("received peer message while closing '%s'" % phase) - if phase == u"pake": + if phase == "pake": return self._event_received_pake(body) - if phase == u"version": + if phase == "version": return self._event_received_version(side, body) if re.search(r'^\d+$', phase): return self._event_received_phase_message(side, phase, body) @@ -743,7 +743,7 @@ class _Wormhole: plaintext = self._decrypt_data(data_key, body) except CryptoError: e = WrongPasswordError() - self._signal_error(e, u"scary") # flunk all other API calls + self._signal_error(e, "scary") # flunk all other API calls # make tests fail, if they aren't explicitly catching it if self.DEBUG: print("CryptoError in msg received") log.err(e) @@ -764,7 +764,7 @@ class _Wormhole: def _API_get(self): if self._error: return defer.fail(self._error) - phase = u"%d" % self._next_receive_phase + phase = "%d" % self._next_receive_phase self._next_receive_phase += 1 with self._timing.add("API get", phase=phase): if phase in self._received_messages: @@ -780,7 +780,7 @@ class _Wormhole: if self.DEBUG: print("_signal_error done") @inlineCallbacks - def _API_close(self, res, mood=u"happy"): + def _API_close(self, res, mood="happy"): if self.DEBUG: print("close") if self._close_called: raise UsageError self._close_called = True @@ -838,7 +838,7 @@ class _Wormhole: if self.DEBUG: print("_maybe_release_nameplate", self._nameplate_state) if self._nameplate_state == OPEN: if self.DEBUG: print(" sending release") - self._ws_send_command(u"release") + self._ws_send_command("release") self._nameplate_state = CLOSING def _response_handle_released(self, msg): @@ -849,7 +849,7 @@ class _Wormhole: if self.DEBUG: print("_maybe_close_mailbox", self._mailbox_state) if self._mailbox_state == OPEN: if self.DEBUG: print(" sending close") - self._ws_send_command(u"close", mood=mood) + self._ws_send_command("close", mood=mood) self._mailbox_state = CLOSING def _response_handle_closed(self, msg): From 64f7348d05253d022f86b95591901ee26b81361c Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:06:27 -0700 Subject: [PATCH 02/11] `u""` cleanup on util.py and codes.py --- src/wormhole/codes.py | 4 ++-- src/wormhole/util.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wormhole/codes.py b/src/wormhole/codes.py index 8f922ae..a911f85 100644 --- a/src/wormhole/codes.py +++ b/src/wormhole/codes.py @@ -4,7 +4,7 @@ from .wordlist import (byte_to_even_word, byte_to_odd_word, even_words_lowercase, odd_words_lowercase) def make_code(channel_id, code_length): - assert isinstance(channel_id, type(u"")), type(channel_id) + assert isinstance(channel_id, type("")), type(channel_id) words = [] for i in range(code_length): # we start with an "odd word" @@ -12,7 +12,7 @@ def make_code(channel_id, code_length): words.append(byte_to_odd_word[os.urandom(1)].lower()) else: words.append(byte_to_even_word[os.urandom(1)].lower()) - return u"%s-%s" % (channel_id, u"-".join(words)) + return "%s-%s" % (channel_id, "-".join(words)) def extract_channel_id(code): channel_id = int(code.split("-")[0]) diff --git a/src/wormhole/util.py b/src/wormhole/util.py index 43dccfe..967243e 100644 --- a/src/wormhole/util.py +++ b/src/wormhole/util.py @@ -1,3 +1,4 @@ +# No unicode_literals import json, unicodedata from binascii import hexlify, unhexlify From 2c387954766bbe107c6575a80fd5b937614aa71d Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:08:38 -0700 Subject: [PATCH 03/11] `u""` cleanup on transit_server.py --- src/wormhole/server/transit_server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wormhole/server/transit_server.py b/src/wormhole/server/transit_server.py index 3241078..17d42a0 100644 --- a/src/wormhole/server/transit_server.py +++ b/src/wormhole/server/transit_server.py @@ -115,14 +115,14 @@ class TransitConnection(protocol.Protocol): finished = time.time() if not self._had_buddy: # 1 total_time = finished - self._started - self.factory.recordUsage(self._started, u"lonely", 0, + self.factory.recordUsage(self._started, "lonely", 0, total_time, None) if self._had_buddy and self._buddy: # 2,4 total_bytes = self._total_sent + self._buddy._total_sent starts = [self._started, self._buddy._started] total_time = finished - min(starts) waiting_time = max(starts) - min(starts) - self.factory.recordUsage(self._started, u"happy", total_bytes, + self.factory.recordUsage(self._started, "happy", total_bytes, total_time, waiting_time) def disconnect(self): @@ -130,7 +130,7 @@ class TransitConnection(protocol.Protocol): self.factory.transitFailed(self) finished = time.time() total_time = finished - self._started - self.factory.recordUsage(self._started, u"errory", 0, + self.factory.recordUsage(self._started, "errory", 0, total_time, None) class Transit(protocol.ServerFactory, service.MultiService): From 8537d905271da4335745818f05b380b73ebf8e1a Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:10:08 -0700 Subject: [PATCH 04/11] `u""` cleanup on rendezvous.py --- src/wormhole/server/rendezvous.py | 52 +++++++++++++++---------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/wormhole/server/rendezvous.py b/src/wormhole/server/rendezvous.py index ccc49c3..0f5ac82 100644 --- a/src/wormhole/server/rendezvous.py +++ b/src/wormhole/server/rendezvous.py @@ -63,7 +63,7 @@ class Mailbox: def open(self, side, when): # requires caller to db.commit() - assert isinstance(side, type(u"")), type(side) + assert isinstance(side, type("")), type(side) db = self._db row = db.execute("SELECT * FROM `mailboxes`" " WHERE `app_id`=? AND `id`=?", @@ -126,7 +126,7 @@ class Mailbox: self.broadcast_message(sm) def close(self, side, mood, when): - assert isinstance(side, type(u"")), type(side) + assert isinstance(side, type("")), type(side) db = self._db row = db.execute("SELECT * FROM `mailboxes`" " WHERE `app_id`=? AND `id`=?", @@ -200,7 +200,7 @@ class AppNamespace: for size in range(1,4): # stick to 1-999 for now available = set() for id_int in range(10**(size-1), 10**size): - id = u"%d" % id_int + id = "%d" % id_int if id not in claimed: available.add(id) if available: @@ -208,7 +208,7 @@ class AppNamespace: # ouch, 999 currently claimed. Try random ones for a while. for tries in range(1000): id_int = random.randrange(1000, 1000*1000) - id = u"%d" % id_int + id = "%d" % id_int if id not in claimed: return id raise ValueError("unable to find a free nameplate-id") @@ -226,8 +226,8 @@ class AppNamespace: # * started or second will be populated # * a mailbox id will be created, but not a mailbox row # (ids are randomly unique, so we can defer creation until 'open') - assert isinstance(nameplate_id, type(u"")), type(nameplate_id) - assert isinstance(side, type(u"")), type(side) + assert isinstance(nameplate_id, type("")), type(nameplate_id) + assert isinstance(side, type("")), type(side) db = self._db row = db.execute("SELECT * FROM `nameplates`" " WHERE `app_id`=? AND `id`=?", @@ -271,8 +271,8 @@ class AppNamespace: # * if the nameplate is now unused: # * mailbox.nameplate_closed will be populated # * the nameplate row will be removed - assert isinstance(nameplate_id, type(u"")), type(nameplate_id) - assert isinstance(side, type(u"")), type(side) + assert isinstance(nameplate_id, type("")), type(nameplate_id) + assert isinstance(side, type("")), type(side) db = self._db row = db.execute("SELECT * FROM `nameplates`" " WHERE `app_id`=? AND `id`=?", @@ -312,18 +312,18 @@ class AppNamespace: if row["second"]: waiting_time = row["second"] - row["started"] total_time = delete_time - row["started"] - result = u"lonely" + result = "lonely" if row["second"]: - result = u"happy" + result = "happy" if pruned: - result = u"pruney" + result = "pruney" if row["crowded"]: - result = u"crowded" + result = "crowded" return Usage(started=started, waiting_time=waiting_time, total_time=total_time, result=result) def open_mailbox(self, mailbox_id, side, when): - assert isinstance(mailbox_id, type(u"")), type(mailbox_id) + assert isinstance(mailbox_id, type("")), type(mailbox_id) db = self._db if not mailbox_id in self._mailboxes: if self._log_requests: @@ -379,23 +379,23 @@ class AppNamespace: total_time = delete_time - row["started"] if num_sides == 0: - result = u"quiet" + result = "quiet" elif num_sides == 1: - result = u"lonely" + result = "lonely" else: - result = u"happy" + result = "happy" moods = set([row["first_mood"], second_mood]) - if u"lonely" in moods: - result = u"lonely" - if u"errory" in moods: - result = u"errory" - if u"scary" in moods: - result = u"scary" + if "lonely" in moods: + result = "lonely" + if "errory" in moods: + result = "errory" + if "scary" in moods: + result = "scary" if pruned: - result = u"pruney" + result = "pruney" if row["crowded"]: - result = u"crowded" + result = "crowded" return Usage(started=started, waiting_time=waiting_time, total_time=total_time, result=result) @@ -512,7 +512,7 @@ class AppNamespace: log.msg(" deleting mailbox", mailbox_id) self._summarize_mailbox_and_store(mailbox_id, all_mailbox_rows[mailbox_id], - u"pruney", now, pruned=True) + "pruney", now, pruned=True) db.execute("DELETE FROM `messages`" " WHERE `app_id`=? AND `mailbox_id`=?", (self._app_id, mailbox_id)) @@ -547,7 +547,7 @@ class Rendezvous(service.MultiService): return self._log_requests def get_app(self, app_id): - assert isinstance(app_id, type(u"")) + assert isinstance(app_id, type("")) if not app_id in self._apps: if self._log_requests: log.msg("spawning app_id %s" % (app_id,)) From 57d117e4f002836eb9be848af20c68ac9ff571ec Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:12:00 -0700 Subject: [PATCH 05/11] `u""` cleanup on rendezvous_websocket.py --- src/wormhole/server/rendezvous_websocket.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wormhole/server/rendezvous_websocket.py b/src/wormhole/server/rendezvous_websocket.py index 358ccf1..2ab2643 100644 --- a/src/wormhole/server/rendezvous_websocket.py +++ b/src/wormhole/server/rendezvous_websocket.py @@ -164,7 +164,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): if self._did_allocate: raise Error("you already allocated one, don't be greedy") nameplate_id = self._app.allocate_nameplate(self._side, server_rx) - assert isinstance(nameplate_id, type(u"")) + assert isinstance(nameplate_id, type("")) self._did_allocate = True self.send("allocated", nameplate=nameplate_id) @@ -172,7 +172,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): if "nameplate" not in msg: raise Error("claim requires 'nameplate'") nameplate_id = msg["nameplate"] - assert isinstance(nameplate_id, type(u"")), type(nameplate_id) + assert isinstance(nameplate_id, type("")), type(nameplate_id) self._nameplate_id = nameplate_id try: mailbox_id = self._app.claim_nameplate(nameplate_id, self._side, @@ -195,7 +195,7 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): if "mailbox" not in msg: raise Error("open requires 'mailbox'") mailbox_id = msg["mailbox"] - assert isinstance(mailbox_id, type(u"")) + assert isinstance(mailbox_id, type("")) self._mailbox = self._app.open_mailbox(mailbox_id, self._side, server_rx) def _send(sm): From 255fb12f88fce04cfcc3c1d07dfc69ce20a6f264 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:13:51 -0700 Subject: [PATCH 06/11] `u"" cleanup on cmd_usage.py --- src/wormhole/server/cmd_usage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wormhole/server/cmd_usage.py b/src/wormhole/server/cmd_usage.py index 8c12fe9..290a619 100644 --- a/src/wormhole/server/cmd_usage.py +++ b/src/wormhole/server/cmd_usage.py @@ -68,9 +68,9 @@ def show_usage(args): " ORDER BY `started` ASC LIMIT ?", (args.n,)) for row in c.fetchall(): - if row["type"] == u"rendezvous": + if row["type"] == "rendezvous": counters = rendezvous_counters - elif row["type"] == u"transit": + elif row["type"] == "transit": counters = transit_counters total_transit_bytes += row["total_bytes"] else: From 8fa40d3cd53971bca86ec7f6fd2be21d1dbd2dd8 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:16:09 -0700 Subject: [PATCH 07/11] `u""` cleanup on test_wormhole.py --- src/wormhole/test/test_wormhole.py | 308 ++++++++++++++--------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/src/wormhole/test/test_wormhole.py b/src/wormhole/test/test_wormhole.py index 1ce51b2..2b795f2 100644 --- a/src/wormhole/test/test_wormhole.py +++ b/src/wormhole/test/test_wormhole.py @@ -15,7 +15,7 @@ from ..util import (bytes_to_dict, dict_to_bytes, hexstr_to_bytes, bytes_to_hexstr) from nacl.secret import SecretBox -APPID = u"appid" +APPID = "appid" class MockWebSocket: def __init__(self): @@ -37,83 +37,83 @@ def response(w, **kwargs): class Welcome(unittest.TestCase): def test_tolerate_no_current_version(self): - w = wormhole._WelcomeHandler(u"relay_url", u"current_cli_version", None) + w = wormhole._WelcomeHandler("relay_url", "current_cli_version", None) w.handle_welcome({}) def test_print_motd(self): - w = wormhole._WelcomeHandler(u"relay_url", u"current_cli_version", None) + w = wormhole._WelcomeHandler("relay_url", "current_cli_version", None) with mock.patch("sys.stderr") as stderr: - w.handle_welcome({u"motd": u"message of\nthe day"}) + w.handle_welcome({"motd": "message of\nthe day"}) self.assertEqual(stderr.method_calls, - [mock.call.write(u"Server (at relay_url) says:\n" + [mock.call.write("Server (at relay_url) says:\n" " message of\n the day"), - mock.call.write(u"\n")]) + mock.call.write("\n")]) # motd can be displayed multiple times with mock.patch("sys.stderr") as stderr2: - w.handle_welcome({u"motd": u"second message"}) + w.handle_welcome({"motd": "second message"}) self.assertEqual(stderr2.method_calls, - [mock.call.write(u"Server (at relay_url) says:\n" + [mock.call.write("Server (at relay_url) says:\n" " second message"), - mock.call.write(u"\n")]) + mock.call.write("\n")]) def test_current_version(self): - w = wormhole._WelcomeHandler(u"relay_url", u"2.0", None) + w = wormhole._WelcomeHandler("relay_url", "2.0", None) with mock.patch("sys.stderr") as stderr: - w.handle_welcome({u"current_cli_version": u"2.0"}) + w.handle_welcome({"current_cli_version": "2.0"}) self.assertEqual(stderr.method_calls, []) with mock.patch("sys.stderr") as stderr: - w.handle_welcome({u"current_cli_version": u"3.0"}) - exp1 = (u"Warning: errors may occur unless both sides are" + w.handle_welcome({"current_cli_version": "3.0"}) + exp1 = ("Warning: errors may occur unless both sides are" " running the same version") - exp2 = (u"Server claims 3.0 is current, but ours is 2.0") + exp2 = ("Server claims 3.0 is current, but ours is 2.0") self.assertEqual(stderr.method_calls, [mock.call.write(exp1), - mock.call.write(u"\n"), + mock.call.write("\n"), mock.call.write(exp2), - mock.call.write(u"\n"), + mock.call.write("\n"), ]) # warning is only displayed once with mock.patch("sys.stderr") as stderr: - w.handle_welcome({u"current_cli_version": u"3.0"}) + w.handle_welcome({"current_cli_version": "3.0"}) self.assertEqual(stderr.method_calls, []) def test_non_release_version(self): - w = wormhole._WelcomeHandler(u"relay_url", u"2.0-dirty", None) + w = wormhole._WelcomeHandler("relay_url", "2.0-dirty", None) with mock.patch("sys.stderr") as stderr: - w.handle_welcome({u"current_cli_version": u"3.0"}) + w.handle_welcome({"current_cli_version": "3.0"}) self.assertEqual(stderr.method_calls, []) def test_signal_error(self): se = mock.Mock() - w = wormhole._WelcomeHandler(u"relay_url", u"2.0", se) + w = wormhole._WelcomeHandler("relay_url", "2.0", se) w.handle_welcome({}) self.assertEqual(se.mock_calls, []) - w.handle_welcome({u"error": u"oops"}) + w.handle_welcome({"error": "oops"}) self.assertEqual(len(se.mock_calls), 1) self.assertEqual(len(se.mock_calls[0][1]), 2) # posargs we = se.mock_calls[0][1][0] self.assertIsInstance(we, WelcomeError) - self.assertEqual(we.args, (u"oops",)) + self.assertEqual(we.args, ("oops",)) mood = se.mock_calls[0][1][1] - self.assertEqual(mood, u"unwelcome") + self.assertEqual(mood, "unwelcome") # alas WelcomeError instances don't compare against each other - #self.assertEqual(se.mock_calls, [mock.call(WelcomeError(u"oops"))]) + #self.assertEqual(se.mock_calls, [mock.call(WelcomeError("oops"))]) class InputCode(unittest.TestCase): def test_list(self): send_command = mock.Mock() - ic = wormhole._InputCode(None, u"prompt", 2, send_command, + ic = wormhole._InputCode(None, "prompt", 2, send_command, DebugTiming()) d = ic._list() self.assertNoResult(d) - self.assertEqual(send_command.mock_calls, [mock.call(u"list")]) - ic._response_handle_nameplates({u"type": u"nameplates", - u"nameplates": [{u"id": u"123"}]}) + self.assertEqual(send_command.mock_calls, [mock.call("list")]) + ic._response_handle_nameplates({"type": "nameplates", + "nameplates": [{"id": "123"}]}) res = self.successResultOf(d) - self.assertEqual(res, [u"123"]) + self.assertEqual(res, ["123"]) class GetCode(unittest.TestCase): def test_get(self): @@ -121,14 +121,14 @@ class GetCode(unittest.TestCase): gc = wormhole._GetCode(2, send_command, DebugTiming()) d = gc.go() self.assertNoResult(d) - self.assertEqual(send_command.mock_calls, [mock.call(u"allocate")]) + self.assertEqual(send_command.mock_calls, [mock.call("allocate")]) # TODO: nameplate attributes get added and checked here - gc._response_handle_allocated({u"type": u"allocated", - u"nameplate": u"123"}) + gc._response_handle_allocated({"type": "allocated", + "nameplate": "123"}) code = self.successResultOf(d) - self.assertIsInstance(code, type(u"")) - self.assert_(code.startswith(u"123-")) - pieces = code.split(u"-") + self.assertIsInstance(code, type("")) + self.assert_(code.startswith("123-")) + pieces = code.split("-") self.assertEqual(len(pieces), 3) # nameplate plus two words self.assert_(re.search(r'^\d+-\w+-\w+$', code), code) @@ -148,7 +148,7 @@ class Basic(unittest.TestCase): out = ws.outbound() self.assertEqual(len(out), len(types), (out, types)) for i,t in enumerate(types): - self.assertEqual(out[i][u"type"], t, (i,t,out)) + self.assertEqual(out[i]["type"], t, (i,t,out)) return out def make_pake(self, code, side, msg1): @@ -159,7 +159,7 @@ class Basic(unittest.TestCase): return key, msg2 def test_create(self): - wormhole._Wormhole(APPID, u"relay_url", reactor, None, None) + wormhole._Wormhole(APPID, "relay_url", reactor, None, None) def test_basic(self): # We don't call w._start(), so this doesn't create a WebSocket @@ -172,9 +172,9 @@ class Basic(unittest.TestCase): timing = DebugTiming() with mock.patch("wormhole.wormhole._WelcomeHandler") as wh_c: - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) wh = wh_c.return_value - self.assertEqual(w._ws_url, u"relay_url") + self.assertEqual(w._ws_url, "relay_url") self.assertTrue(w._flag_need_nameplate) self.assertTrue(w._flag_need_to_build_msg1) self.assertTrue(w._flag_need_to_send_PAKE) @@ -190,50 +190,50 @@ class Basic(unittest.TestCase): w._event_ws_opened(None) out = ws.outbound() self.assertEqual(len(out), 1) - self.check_out(out[0], type=u"bind", appid=APPID, side=w._side) - self.assertIn(u"id", out[0]) + self.check_out(out[0], type="bind", appid=APPID, side=w._side) + self.assertIn("id", out[0]) # WelcomeHandler should get called upon 'welcome' response. Its full # behavior is exercised in 'Welcome' above. - WELCOME = {u"foo": u"bar"} + WELCOME = {"foo": "bar"} response(w, type="welcome", welcome=WELCOME) self.assertEqual(wh.mock_calls, [mock.call.handle_welcome(WELCOME)]) # because we're connected, setting the code also claims the mailbox - CODE = u"123-foo-bar" + CODE = "123-foo-bar" w.set_code(CODE) self.assertFalse(w._flag_need_to_build_msg1) out = ws.outbound() self.assertEqual(len(out), 1) - self.check_out(out[0], type=u"claim", nameplate=u"123") + self.check_out(out[0], type="claim", nameplate="123") # the server reveals the linked mailbox - response(w, type=u"claimed", mailbox=u"mb456") + response(w, type="claimed", mailbox="mb456") # that triggers event_learned_mailbox, which should send open() and # PAKE self.assertEqual(w._mailbox_state, wormhole.OPEN) out = ws.outbound() self.assertEqual(len(out), 2) - self.check_out(out[0], type=u"open", mailbox=u"mb456") - self.check_out(out[1], type=u"add", phase=u"pake") + self.check_out(out[0], type="open", mailbox="mb456") + self.check_out(out[1], type="add", phase="pake") self.assertNoResult(v) # server echoes back all "add" messages - response(w, type=u"message", phase=u"pake", body=out[1][u"body"], + response(w, type="message", phase="pake", body=out[1]["body"], side=w._side) self.assertNoResult(v) # extract our outbound PAKE message - body = bytes_to_dict(hexstr_to_bytes(out[1][u"body"])) - msg1 = hexstr_to_bytes(body[u"pake_v1"]) + body = bytes_to_dict(hexstr_to_bytes(out[1]["body"])) + msg1 = hexstr_to_bytes(body["pake_v1"]) # next we build the simulated peer's PAKE operation - side2 = w._side + u"other" + side2 = w._side + "other" key, msg2 = self.make_pake(CODE, side2, msg1) - payload = {u"pake_v1": bytes_to_hexstr(msg2)} + payload = {"pake_v1": bytes_to_hexstr(msg2)} body_hex = bytes_to_hexstr(dict_to_bytes(payload)) - response(w, type=u"message", phase=u"pake", body=body_hex, side=side2) + response(w, type="message", phase="pake", body=body_hex, side=side2) # hearing the peer's PAKE (msg2) makes us release the nameplate, send # the confirmation message, and sends any queued phase messages. It @@ -243,72 +243,72 @@ class Basic(unittest.TestCase): self.assertEqual(w._key, key) out = ws.outbound() self.assertEqual(len(out), 2, out) - self.check_out(out[0], type=u"release") - self.check_out(out[1], type=u"add", phase=u"version") + self.check_out(out[0], type="release") + self.check_out(out[1], type="add", phase="version") self.assertNoResult(v) # hearing a valid confirmation message doesn't throw an error plaintext = json.dumps({}).encode("utf-8") - data_key = w._derive_phase_key(side2, u"version") + data_key = w._derive_phase_key(side2, "version") confmsg = w._encrypt_data(data_key, plaintext) version2_hex = hexlify(confmsg).decode("ascii") - response(w, type=u"message", phase=u"version", body=version2_hex, + response(w, type="message", phase="version", body=version2_hex, side=side2) # and it releases the verifier verifier = self.successResultOf(v) self.assertEqual(verifier, - w.derive_key(u"wormhole:verifier", SecretBox.KEY_SIZE)) + w.derive_key("wormhole:verifier", SecretBox.KEY_SIZE)) # an outbound message can now be sent immediately w.send(b"phase0-outbound") out = ws.outbound() self.assertEqual(len(out), 1) - self.check_out(out[0], type=u"add", phase=u"0") + self.check_out(out[0], type="add", phase="0") # decrypt+check the outbound message - p0_outbound = unhexlify(out[0][u"body"].encode("ascii")) - msgkey0 = w._derive_phase_key(w._side, u"0") + p0_outbound = unhexlify(out[0]["body"].encode("ascii")) + msgkey0 = w._derive_phase_key(w._side, "0") p0_plaintext = w._decrypt_data(msgkey0, p0_outbound) self.assertEqual(p0_plaintext, b"phase0-outbound") # get() waits for the inbound message to arrive md = w.get() self.assertNoResult(md) - self.assertIn(u"0", w._receive_waiters) - self.assertNotIn(u"0", w._received_messages) - msgkey1 = w._derive_phase_key(side2, u"0") + self.assertIn("0", w._receive_waiters) + self.assertNotIn("0", w._received_messages) + msgkey1 = w._derive_phase_key(side2, "0") p0_inbound = w._encrypt_data(msgkey1, b"phase0-inbound") p0_inbound_hex = hexlify(p0_inbound).decode("ascii") - response(w, type=u"message", phase=u"0", body=p0_inbound_hex, + response(w, type="message", phase="0", body=p0_inbound_hex, side=side2) p0_in = self.successResultOf(md) self.assertEqual(p0_in, b"phase0-inbound") - self.assertNotIn(u"0", w._receive_waiters) - self.assertIn(u"0", w._received_messages) + self.assertNotIn("0", w._receive_waiters) + self.assertIn("0", w._received_messages) # receiving an inbound message will queue it until get() is called - msgkey2 = w._derive_phase_key(side2, u"1") + msgkey2 = w._derive_phase_key(side2, "1") p1_inbound = w._encrypt_data(msgkey2, b"phase1-inbound") p1_inbound_hex = hexlify(p1_inbound).decode("ascii") - response(w, type=u"message", phase=u"1", body=p1_inbound_hex, + response(w, type="message", phase="1", body=p1_inbound_hex, side=side2) - self.assertIn(u"1", w._received_messages) - self.assertNotIn(u"1", w._receive_waiters) + self.assertIn("1", w._received_messages) + self.assertNotIn("1", w._receive_waiters) p1_in = self.successResultOf(w.get()) self.assertEqual(p1_in, b"phase1-inbound") - self.assertIn(u"1", w._received_messages) - self.assertNotIn(u"1", w._receive_waiters) + self.assertIn("1", w._received_messages) + self.assertNotIn("1", w._receive_waiters) d = w.close() self.assertNoResult(d) out = ws.outbound() self.assertEqual(len(out), 1) - self.check_out(out[0], type=u"close", mood=u"happy") + self.check_out(out[0], type="close", mood="happy") self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"released") + response(w, type="released") self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"closed") + response(w, type="closed") self.assertEqual(w._drop_connection.mock_calls, [mock.call()]) w._ws_closed(True, None, None) self.assertEqual(self.successResultOf(d), None) @@ -317,7 +317,7 @@ class Basic(unittest.TestCase): # Close before the connection is established. The connection still # gets established, but it is then torn down before sending anything. timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() d = w.close() @@ -335,14 +335,14 @@ class Basic(unittest.TestCase): def test_close_wait_1(self): # close before even claiming the nameplate timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) d = w.close() - self.check_outbound(ws, [u"bind"]) + self.check_outbound(ws, ["bind"]) self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, [mock.call()]) self.assertNoResult(d) @@ -354,27 +354,27 @@ class Basic(unittest.TestCase): # Close after claiming the nameplate, but before opening the mailbox. # The 'claimed' response arrives before we close. timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - CODE = u"123-foo-bar" + CODE = "123-foo-bar" w.set_code(CODE) - self.check_outbound(ws, [u"bind", u"claim"]) + self.check_outbound(ws, ["bind", "claim"]) - response(w, type=u"claimed", mailbox=u"mb123") + response(w, type="claimed", mailbox="mb123") d = w.close() - self.check_outbound(ws, [u"open", u"add", u"release", u"close"]) + self.check_outbound(ws, ["open", "add", "release", "close"]) self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"released") + response(w, type="released") self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"closed") + response(w, type="closed") self.assertEqual(w._drop_connection.mock_calls, [mock.call()]) self.assertNoResult(d) @@ -385,22 +385,22 @@ class Basic(unittest.TestCase): # close after claiming the nameplate, but before opening the mailbox # The 'claimed' response arrives after we start to close. timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - CODE = u"123-foo-bar" + CODE = "123-foo-bar" w.set_code(CODE) - self.check_outbound(ws, [u"bind", u"claim"]) + self.check_outbound(ws, ["bind", "claim"]) d = w.close() - response(w, type=u"claimed", mailbox=u"mb123") - self.check_outbound(ws, [u"release"]) + response(w, type="claimed", mailbox="mb123") + self.check_outbound(ws, ["release"]) self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"released") + response(w, type="released") self.assertEqual(w._drop_connection.mock_calls, [mock.call()]) self.assertNoResult(d) @@ -410,26 +410,26 @@ class Basic(unittest.TestCase): def test_close_wait_4(self): # close after both claiming the nameplate and opening the mailbox timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - CODE = u"123-foo-bar" + CODE = "123-foo-bar" w.set_code(CODE) - response(w, type=u"claimed", mailbox=u"mb456") - self.check_outbound(ws, [u"bind", u"claim", u"open", u"add"]) + response(w, type="claimed", mailbox="mb456") + self.check_outbound(ws, ["bind", "claim", "open", "add"]) d = w.close() - self.check_outbound(ws, [u"release", u"close"]) + self.check_outbound(ws, ["release", "close"]) self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"released") + response(w, type="released") self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"closed") + response(w, type="closed") self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, [mock.call()]) @@ -440,34 +440,34 @@ class Basic(unittest.TestCase): # close after claiming the nameplate, opening the mailbox, then # releasing the nameplate timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - CODE = u"123-foo-bar" + CODE = "123-foo-bar" w.set_code(CODE) - response(w, type=u"claimed", mailbox=u"mb456") + response(w, type="claimed", mailbox="mb456") w._key = b"" - msgkey = w._derive_phase_key(u"side2", u"misc") + msgkey = w._derive_phase_key("side2", "misc") p1_inbound = w._encrypt_data(msgkey, b"") p1_inbound_hex = hexlify(p1_inbound).decode("ascii") - response(w, type=u"message", phase=u"misc", side=u"side2", + response(w, type="message", phase="misc", side="side2", body=p1_inbound_hex) - self.check_outbound(ws, [u"bind", u"claim", u"open", u"add", - u"release"]) + self.check_outbound(ws, ["bind", "claim", "open", "add", + "release"]) d = w.close() - self.check_outbound(ws, [u"close"]) + self.check_outbound(ws, ["close"]) self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"released") + response(w, type="released") self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, []) - response(w, type=u"closed") + response(w, type="closed") self.assertNoResult(d) self.assertEqual(w._drop_connection.mock_calls, [mock.call()]) @@ -481,11 +481,11 @@ class Basic(unittest.TestCase): def test_get_code_mock(self): timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) ws = MockWebSocket() # TODO: mock w._ws_send_command instead w._event_connected(ws) w._event_ws_opened(None) - self.check_outbound(ws, [u"bind"]) + self.check_outbound(ws, ["bind"]) gc_c = mock.Mock() gc = gc_c.return_value = mock.Mock() @@ -494,31 +494,31 @@ class Basic(unittest.TestCase): d = w.get_code() self.assertNoResult(d) - gc_d.callback(u"123-foo-bar") + gc_d.callback("123-foo-bar") code = self.successResultOf(d) - self.assertEqual(code, u"123-foo-bar") + self.assertEqual(code, "123-foo-bar") def test_get_code_real(self): timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - self.check_outbound(ws, [u"bind"]) + self.check_outbound(ws, ["bind"]) d = w.get_code() out = ws.outbound() self.assertEqual(len(out), 1) - self.check_out(out[0], type=u"allocate") + self.check_out(out[0], type="allocate") # TODO: nameplate attributes go here self.assertNoResult(d) - response(w, type=u"allocated", nameplate=u"123") + response(w, type="allocated", nameplate="123") code = self.successResultOf(d) - self.assertIsInstance(code, type(u"")) - self.assert_(code.startswith(u"123-")) - pieces = code.split(u"-") + self.assertIsInstance(code, type("")) + self.assert_(code.startswith("123-")) + pieces = code.split("-") self.assertEqual(len(pieces), 3) # nameplate plus two words self.assert_(re.search(r'^\d+-\w+-\w+$', code), code) @@ -532,11 +532,11 @@ class Basic(unittest.TestCase): #print(when, order, success) timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() w._ws_send_command = mock.Mock() w._mailbox_state = wormhole.OPEN - side2 = u"side2" + side2 = "side2" d = None if success: @@ -544,7 +544,7 @@ class Basic(unittest.TestCase): else: w._key = b"wrongkey" plaintext = json.dumps({}).encode("utf-8") - data_key = w._derive_phase_key(side2, u"version") + data_key = w._derive_phase_key(side2, "version") confmsg = w._encrypt_data(data_key, plaintext) w._key = None @@ -595,12 +595,12 @@ class Basic(unittest.TestCase): # states in which we might see it. timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - self.check_outbound(ws, [u"bind"]) + self.check_outbound(ws, ["bind"]) d1 = w.get() d2 = w.verify() @@ -611,15 +611,15 @@ class Basic(unittest.TestCase): self.assertNoResult(d2) self.assertNoResult(d3) - w._signal_error(WelcomeError(u"you are not actually welcome"), u"pouty") + w._signal_error(WelcomeError("you are not actually welcome"), "pouty") self.failureResultOf(d1, WelcomeError) self.failureResultOf(d2, WelcomeError) self.failureResultOf(d3, WelcomeError) # once the error is signalled, all API calls should fail - self.assertRaises(WelcomeError, w.send, u"foo") + self.assertRaises(WelcomeError, w.send, "foo") self.assertRaises(WelcomeError, - w.derive_key, u"foo", SecretBox.KEY_SIZE) + w.derive_key, "foo", SecretBox.KEY_SIZE) self.failureResultOf(w.get(), WelcomeError) self.failureResultOf(w.verify(), WelcomeError) @@ -628,13 +628,13 @@ class Basic(unittest.TestCase): # PAKE message, by which point we should know the key. If the # confirmation message doesn't decrypt, we signal an error. timing = DebugTiming() - w = wormhole._Wormhole(APPID, u"relay_url", reactor, None, timing) + w = wormhole._Wormhole(APPID, "relay_url", reactor, None, timing) w._drop_connection = mock.Mock() ws = MockWebSocket() w._event_connected(ws) w._event_ws_opened(None) - w.set_code(u"123-foo-bar") - response(w, type=u"claimed", mailbox=u"mb456") + w.set_code("123-foo-bar") + response(w, type="claimed", mailbox="mb456") d1 = w.get() d2 = w.verify() @@ -642,33 +642,33 @@ class Basic(unittest.TestCase): self.assertNoResult(d2) out = ws.outbound() - # [u"bind", u"claim", u"open", u"add"] + # ["bind", "claim", "open", "add"] self.assertEqual(len(out), 4) - self.assertEqual(out[3][u"type"], u"add") + self.assertEqual(out[3]["type"], "add") sp2 = SPAKE2_Symmetric(b"", idSymmetric=wormhole.to_bytes(APPID)) msg2 = sp2.start() - payload = {u"pake_v1": bytes_to_hexstr(msg2)} + payload = {"pake_v1": bytes_to_hexstr(msg2)} body_hex = bytes_to_hexstr(dict_to_bytes(payload)) - response(w, type=u"message", phase=u"pake", body=body_hex, side=u"s2") + response(w, type="message", phase="pake", body=body_hex, side="s2") self.assertNoResult(d1) self.assertNoResult(d2) # verify() waits for confirmation # sending a random version message will cause a confirmation error - confkey = w.derive_key(u"WRONG", SecretBox.KEY_SIZE) + confkey = w.derive_key("WRONG", SecretBox.KEY_SIZE) nonce = os.urandom(wormhole.CONFMSG_NONCE_LENGTH) badversion = wormhole.make_confmsg(confkey, nonce) badversion_hex = hexlify(badversion).decode("ascii") - response(w, type=u"message", phase=u"version", body=badversion_hex, - side=u"s2") + response(w, type="message", phase="version", body=badversion_hex, + side="s2") self.failureResultOf(d1, WrongPasswordError) self.failureResultOf(d2, WrongPasswordError) # once the error is signalled, all API calls should fail - self.assertRaises(WrongPasswordError, w.send, u"foo") + self.assertRaises(WrongPasswordError, w.send, "foo") self.assertRaises(WrongPasswordError, - w.derive_key, u"foo", SecretBox.KEY_SIZE) + w.derive_key, "foo", SecretBox.KEY_SIZE) self.failureResultOf(w.get(), WrongPasswordError) self.failureResultOf(w.verify(), WrongPasswordError) @@ -757,8 +757,8 @@ class Wormholes(ServerBase, unittest.TestCase): w1.send(b"data1") w2 = wormhole.wormhole(APPID, self.relayurl, reactor) d = w2.get() - w1.set_code(u"123-abc-def") - w2.set_code(u"123-abc-def") + w1.set_code("123-abc-def") + w2.set_code("123-abc-def") dataY = yield d self.assertEqual(dataY, b"data1") yield w1.close() @@ -768,8 +768,8 @@ class Wormholes(ServerBase, unittest.TestCase): def test_fixed_code(self): w1 = wormhole.wormhole(APPID, self.relayurl, reactor) w2 = wormhole.wormhole(APPID, self.relayurl, reactor) - w1.set_code(u"123-purple-elephant") - w2.set_code(u"123-purple-elephant") + w1.set_code("123-purple-elephant") + w2.set_code("123-purple-elephant") w1.send(b"data1"), w2.send(b"data2") dl = yield self.doBoth(w1.get(), w2.get()) (dataX, dataY) = dl @@ -783,8 +783,8 @@ class Wormholes(ServerBase, unittest.TestCase): def test_multiple_messages(self): w1 = wormhole.wormhole(APPID, self.relayurl, reactor) w2 = wormhole.wormhole(APPID, self.relayurl, reactor) - w1.set_code(u"123-purple-elephant") - w2.set_code(u"123-purple-elephant") + w1.set_code("123-purple-elephant") + w2.set_code("123-purple-elephant") w1.send(b"data1"), w2.send(b"data2") w1.send(b"data3"), w2.send(b"data4") dl = yield self.doBoth(w1.get(), w2.get()) @@ -859,15 +859,15 @@ class Wormholes(ServerBase, unittest.TestCase): def test_versions(self): # there's no API for this yet, but make sure the internals work w1 = wormhole.wormhole(APPID, self.relayurl, reactor) - w1._my_versions = {u"w1": 123} + w1._my_versions = {"w1": 123} w2 = wormhole.wormhole(APPID, self.relayurl, reactor) - w2._my_versions = {u"w2": 456} + w2._my_versions = {"w2": 456} code = yield w1.get_code() w2.set_code(code) yield w1.verify() - self.assertEqual(w1._their_versions, {u"w2": 456}) + self.assertEqual(w1._their_versions, {"w2": 456}) yield w2.verify() - self.assertEqual(w2._their_versions, {u"w1": 123}) + self.assertEqual(w2._their_versions, {"w1": 123}) yield w1.close() yield w2.close() @@ -876,11 +876,11 @@ class Errors(ServerBase, unittest.TestCase): def test_codes_1(self): w = wormhole.wormhole(APPID, self.relayurl, reactor) # definitely too early - self.assertRaises(UsageError, w.derive_key, u"purpose", 12) + self.assertRaises(UsageError, w.derive_key, "purpose", 12) - w.set_code(u"123-purple-elephant") + w.set_code("123-purple-elephant") # code can only be set once - self.assertRaises(UsageError, w.set_code, u"123-nope") + self.assertRaises(UsageError, w.set_code, "123-nope") yield self.assertFailure(w.get_code(), UsageError) yield self.assertFailure(w.input_code(), UsageError) yield w.close() @@ -889,7 +889,7 @@ class Errors(ServerBase, unittest.TestCase): def test_codes_2(self): w = wormhole.wormhole(APPID, self.relayurl, reactor) yield w.get_code() - self.assertRaises(UsageError, w.set_code, u"123-nope") + self.assertRaises(UsageError, w.set_code, "123-nope") yield self.assertFailure(w.get_code(), UsageError) yield self.assertFailure(w.input_code(), UsageError) yield w.close() From aff13e91212695c1d285ec90638fe3cf9349c5c5 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:17:25 -0700 Subject: [PATCH 08/11] `u""` cleanup on test_util.py --- src/wormhole/test/test_util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wormhole/test/test_util.py b/src/wormhole/test/test_util.py index c9a6cbc..fb58adc 100644 --- a/src/wormhole/test/test_util.py +++ b/src/wormhole/test/test_util.py @@ -5,23 +5,23 @@ from .. import util class Utils(unittest.TestCase): def test_to_bytes(self): - b = util.to_bytes(u"abc") + b = util.to_bytes("abc") self.assertIsInstance(b, type(b"")) self.assertEqual(b, b"abc") A = unicodedata.lookup("LATIN SMALL LETTER A WITH DIAERESIS") - b = util.to_bytes(A + u"bc") + b = util.to_bytes(A + "bc") self.assertIsInstance(b, type(b"")) self.assertEqual(b, b"\xc3\xa4\x62\x63") def test_bytes_to_hexstr(self): b = b"\x00\x45\x91\xfe\xff" hexstr = util.bytes_to_hexstr(b) - self.assertIsInstance(hexstr, type(u"")) - self.assertEqual(hexstr, u"004591feff") + self.assertIsInstance(hexstr, type("")) + self.assertEqual(hexstr, "004591feff") def test_hexstr_to_bytes(self): - hexstr = u"004591feff" + hexstr = "004591feff" b = util.hexstr_to_bytes(hexstr) hexstr = util.bytes_to_hexstr(b) self.assertIsInstance(b, type(b"")) @@ -37,4 +37,4 @@ class Utils(unittest.TestCase): b = b'{"a": "b", "c": 2}' d = util.bytes_to_dict(b) self.assertIsInstance(d, dict) - self.assertEqual(d, {u"a": u"b", u"c": 2}) + self.assertEqual(d, {"a": "b", "c": 2}) From 2dd76f57c007c1f0d5615e0a586a3e6201aef0e1 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:18:43 -0700 Subject: [PATCH 09/11] `u""` cleanup on test_transit.py --- src/wormhole/test/test_transit.py | 60 +++++++++++++++---------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/wormhole/test/test_transit.py b/src/wormhole/test/test_transit.py index ee80b0a..6f3f0cd 100644 --- a/src/wormhole/test/test_transit.py +++ b/src/wormhole/test/test_transit.py @@ -80,7 +80,7 @@ class Highlander(unittest.TestCase): class Forever(unittest.TestCase): def _forever_setup(self): clock = task.Clock() - c = transit.Common(u"", reactor=clock) + c = transit.Common("", reactor=clock) cancelled = [] result = [] d0 = defer.Deferred(cancelled.append) @@ -129,7 +129,7 @@ class Misc(unittest.TestCase): class Hints(unittest.TestCase): def test_endpoint_from_hint_obj(self): - c = transit.Common(u"") + c = transit.Common("") ep = c._endpoint_from_hint_obj(transit.DirectTCPV1Hint("localhost", 1234)) self.assertIsInstance(ep, endpoints.HostnameEndpoint) ep = c._endpoint_from_hint_obj("unknown:stuff:yowza:pivlor") @@ -139,12 +139,12 @@ class Hints(unittest.TestCase): class Basic(unittest.TestCase): @inlineCallbacks def test_relay_hints(self): - URL = u"tcp:host:1234" + URL = "tcp:host:1234" c = transit.Common(URL, no_listen=True) hints = yield c.get_connection_hints() self.assertEqual(hints, [{"type": "relay-v1", "hints": [{"type": "direct-tcp-v1", - "hostname": u"host", + "hostname": "host", "port": 1234}], }]) self.assertRaises(UsageError, transit.Common, 123) @@ -156,7 +156,7 @@ class Basic(unittest.TestCase): self.assertEqual(hints, []) def test_ignore_bad_hints(self): - c = transit.Common(u"") + c = transit.Common("") c.add_connection_hints([{"type": "unknown"}]) c.add_connection_hints([{"type": "relay-v1", "hints": [{"type": "unknown"}]}]) @@ -165,7 +165,7 @@ class Basic(unittest.TestCase): def test_ignore_localhost_hint(self): # this actually starts the listener - c = transit.TransitSender(u"") + c = transit.TransitSender("") results = [] d = c.get_connection_hints() d.addBoth(results.append) @@ -174,14 +174,14 @@ class Basic(unittest.TestCase): # If there are non-localhost hints, then localhost hints should be # removed. But if the only hint is localhost, it should stay. if len(hints) == 1: - if hints[0][u'hostname'] == u'127.0.0.1': + if hints[0]["hostname"] == "127.0.0.1": return for hint in hints: - self.assertFalse(hint[u'hostname'] == u'127.0.0.1') + self.assertFalse(hint["hostname"] == "127.0.0.1") def test_transit_key_wait(self): KEY = b"123" - c = transit.Common(u"") + c = transit.Common("") results = [] d = c._get_transit_key() d.addBoth(results.append) @@ -191,7 +191,7 @@ class Basic(unittest.TestCase): def test_transit_key_already_set(self): KEY = b"123" - c = transit.Common(u"") + c = transit.Common("") c.set_transit_key(KEY) results = [] d = c._get_transit_key() @@ -200,9 +200,9 @@ class Basic(unittest.TestCase): def test_transit_keys(self): KEY = b"123" - s = transit.TransitSender(u"") + s = transit.TransitSender("") s.set_transit_key(KEY) - r = transit.TransitReceiver(u"") + r = transit.TransitReceiver("") r.set_transit_key(KEY) self.assertEqual(s._send_this(), b"transit sender 559bdeae4b49fa6a23378d2b68f4c7e69378615d4af049c371c6a26e82391089 ready\n\n") @@ -220,20 +220,20 @@ class Basic(unittest.TestCase): hexlify(s._receiver_record_key())) def test_connection_ready(self): - s = transit.TransitSender(u"") + s = transit.TransitSender("") self.assertEqual(s.connection_ready("p1"), "go") self.assertEqual(s._winner, "p1") self.assertEqual(s.connection_ready("p2"), "nevermind") self.assertEqual(s._winner, "p1") - r = transit.TransitReceiver(u"") + r = transit.TransitReceiver("") self.assertEqual(r.connection_ready("p1"), "wait-for-decision") self.assertEqual(r.connection_ready("p2"), "wait-for-decision") class Listener(unittest.TestCase): def test_listener(self): - c = transit.Common(u"") + c = transit.Common("") hints, ep = c._build_listener() self.assertIsInstance(hints, (list, set)) if hints: @@ -242,7 +242,7 @@ class Listener(unittest.TestCase): def test_get_direct_hints(self): # this actually starts the listener - c = transit.TransitSender(u"") + c = transit.TransitSender("") results = [] d = c.get_connection_hints() @@ -1188,25 +1188,25 @@ class FileConsumer(unittest.TestCase): self.assertEqual(f.getvalue(), b"."*99+b"!") -DIRECT_HINT = {u"type": u"direct-tcp-v1", - u"hostname": u"direct", u"port": 1234} -RELAY_HINT = {u"type": u"relay-v1", - u"hints": [{u"type": u"direct-tcp-v1", - u"hostname": u"relay", u"port": 1234}]} -UNUSABLE_HINT = {u"type": u"unknown"} -RELAY_HINT2 = {u"type": u"relay-v1", - u"hints": [{u"type": u"direct-tcp-v1", - u"hostname": u"relay", u"port": 1234}, +DIRECT_HINT = {"type": "direct-tcp-v1", + "hostname": "direct", "port": 1234} +RELAY_HINT = {"type": "relay-v1", + "hints": [{"type": "direct-tcp-v1", + "hostname": "relay", "port": 1234}]} +UNUSABLE_HINT = {"type": "unknown"} +RELAY_HINT2 = {"type": "relay-v1", + "hints": [{"type": "direct-tcp-v1", + "hostname": "relay", "port": 1234}, UNUSABLE_HINT]} -DIRECT_HINT_INTERNAL = transit.DirectTCPV1Hint(u"direct", 1234) -RELAY_HINT_FIRST = transit.DirectTCPV1Hint(u"relay", 1234) +DIRECT_HINT_INTERNAL = transit.DirectTCPV1Hint("direct", 1234) +RELAY_HINT_FIRST = transit.DirectTCPV1Hint("relay", 1234) RELAY_HINT_INTERNAL = transit.RelayV1Hint([RELAY_HINT_FIRST]) class Transit(unittest.TestCase): @inlineCallbacks def test_success_direct(self): clock = task.Clock() - s = transit.TransitSender(u"", reactor=clock) + s = transit.TransitSender("", reactor=clock) s.set_transit_key(b"key") hints = yield s.get_connection_hints() # start the listener del hints @@ -1239,7 +1239,7 @@ class Transit(unittest.TestCase): @inlineCallbacks def test_wait_for_relay(self): clock = task.Clock() - s = transit.TransitSender(u"", reactor=clock, no_listen=True) + s = transit.TransitSender("", reactor=clock, no_listen=True) s.set_transit_key(b"key") hints = yield s.get_connection_hints() # start the listener del hints @@ -1278,7 +1278,7 @@ class Transit(unittest.TestCase): @inlineCallbacks def test_no_direct_hints(self): clock = task.Clock() - s = transit.TransitSender(u"", reactor=clock, no_listen=True) + s = transit.TransitSender("", reactor=clock, no_listen=True) s.set_transit_key(b"key") hints = yield s.get_connection_hints() # start the listener del hints From bb970dafc015187f6d6d8af91e1c00b1efac7fdb Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 13:27:28 -0700 Subject: [PATCH 10/11] `u""` cleanup on test_server.py --- src/wormhole/test/test_server.py | 554 +++++++++++++++---------------- 1 file changed, 277 insertions(+), 277 deletions(-) diff --git a/src/wormhole/test/test_server.py b/src/wormhole/test/test_server.py index c625695..981adf9 100644 --- a/src/wormhole/test/test_server.py +++ b/src/wormhole/test/test_server.py @@ -16,18 +16,18 @@ from ..server.database import get_db class Server(ServerBase, unittest.TestCase): def test_apps(self): - app1 = self._rendezvous.get_app(u"appid1") - self.assertIdentical(app1, self._rendezvous.get_app(u"appid1")) - app2 = self._rendezvous.get_app(u"appid2") + app1 = self._rendezvous.get_app("appid1") + self.assertIdentical(app1, self._rendezvous.get_app("appid1")) + app2 = self._rendezvous.get_app("appid2") self.assertNotIdentical(app1, app2) def test_nameplate_allocation(self): - app = self._rendezvous.get_app(u"appid") + app = self._rendezvous.get_app("appid") nids = set() # this takes a second, and claims all the short-numbered nameplates def add(): - nameplate_id = app.allocate_nameplate(u"side1", 0) - self.assertEqual(type(nameplate_id), type(u"")) + nameplate_id = app.allocate_nameplate("side1", 0) + self.assertEqual(type(nameplate_id), type("")) nid = int(nameplate_id) nids.add(nid) for i in range(9): add() @@ -53,41 +53,41 @@ class Server(ServerBase, unittest.TestCase): (nameplate_id,)).fetchone() def test_nameplate(self): - app = self._rendezvous.get_app(u"appid") - nameplate_id = app.allocate_nameplate(u"side1", 0) - self.assertEqual(type(nameplate_id), type(u"")) + app = self._rendezvous.get_app("appid") + nameplate_id = app.allocate_nameplate("side1", 0) + self.assertEqual(type(nameplate_id), type("")) nid = int(nameplate_id) self.assert_(0 < nid < 10, nid) self.assertEqual(app.get_nameplate_ids(), set([nameplate_id])) # allocate also does a claim row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side1") + self.assertEqual(row["side1"], "side1") self.assertEqual(row["side2"], None) self.assertEqual(row["crowded"], False) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], None) - mailbox_id = app.claim_nameplate(nameplate_id, u"side1", 1) - self.assertEqual(type(mailbox_id), type(u"")) + mailbox_id = app.claim_nameplate(nameplate_id, "side1", 1) + self.assertEqual(type(mailbox_id), type("")) # duplicate claims by the same side are combined row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side1") + self.assertEqual(row["side1"], "side1") self.assertEqual(row["side2"], None) - mailbox_id2 = app.claim_nameplate(nameplate_id, u"side1", 2) + mailbox_id2 = app.claim_nameplate(nameplate_id, "side1", 2) self.assertEqual(mailbox_id, mailbox_id2) row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side1") + self.assertEqual(row["side1"], "side1") self.assertEqual(row["side2"], None) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], None) # claim by the second side is new - mailbox_id3 = app.claim_nameplate(nameplate_id, u"side2", 3) + mailbox_id3 = app.claim_nameplate(nameplate_id, "side2", 3) self.assertEqual(mailbox_id, mailbox_id3) row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side1") - self.assertEqual(row["side2"], u"side2") + self.assertEqual(row["side1"], "side1") + self.assertEqual(row["side2"], "side2") self.assertEqual(row["crowded"], False) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], 3) @@ -95,43 +95,43 @@ class Server(ServerBase, unittest.TestCase): # a third claim marks the nameplate as "crowded", but leaves the two # existing claims alone self.assertRaises(rendezvous.CrowdedError, - app.claim_nameplate, nameplate_id, u"side3", 0) + app.claim_nameplate, nameplate_id, "side3", 0) row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side1") - self.assertEqual(row["side2"], u"side2") + self.assertEqual(row["side1"], "side1") + self.assertEqual(row["side2"], "side2") self.assertEqual(row["crowded"], True) # releasing a non-existent nameplate is ignored - app.release_nameplate(nameplate_id+u"not", u"side4", 0) + app.release_nameplate(nameplate_id+"not", "side4", 0) # releasing a side that never claimed the nameplate is ignored - app.release_nameplate(nameplate_id, u"side4", 0) + app.release_nameplate(nameplate_id, "side4", 0) row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side1") - self.assertEqual(row["side2"], u"side2") + self.assertEqual(row["side1"], "side1") + self.assertEqual(row["side2"], "side2") # releasing one side leaves the second claim - app.release_nameplate(nameplate_id, u"side1", 5) + app.release_nameplate(nameplate_id, "side1", 5) row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side2") + self.assertEqual(row["side1"], "side2") self.assertEqual(row["side2"], None) # releasing one side multiple times is ignored - app.release_nameplate(nameplate_id, u"side1", 5) + app.release_nameplate(nameplate_id, "side1", 5) row = self._nameplate(app, nameplate_id) - self.assertEqual(row["side1"], u"side2") + self.assertEqual(row["side1"], "side2") self.assertEqual(row["side2"], None) # releasing the second side frees the nameplate, and adds usage - app.release_nameplate(nameplate_id, u"side2", 6) + app.release_nameplate(nameplate_id, "side2", 6) row = self._nameplate(app, nameplate_id) self.assertEqual(row, None) usage = app._db.execute("SELECT * FROM `nameplate_usage`").fetchone() - self.assertEqual(usage["app_id"], u"appid") + self.assertEqual(usage["app_id"], "appid") self.assertEqual(usage["started"], 0) self.assertEqual(usage["waiting_time"], 3) self.assertEqual(usage["total_time"], 6) - self.assertEqual(usage["result"], u"crowded") + self.assertEqual(usage["result"], "crowded") def _mailbox(self, app, mailbox_id): @@ -140,12 +140,12 @@ class Server(ServerBase, unittest.TestCase): (mailbox_id,)).fetchone() def test_mailbox(self): - app = self._rendezvous.get_app(u"appid") - mailbox_id = u"mid" - m1 = app.open_mailbox(mailbox_id, u"side1", 0) + app = self._rendezvous.get_app("appid") + mailbox_id = "mid" + m1 = app.open_mailbox(mailbox_id, "side1", 0) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side1") + self.assertEqual(row["side1"], "side1") self.assertEqual(row["side2"], None) self.assertEqual(row["crowded"], False) self.assertEqual(row["started"], 0) @@ -153,55 +153,55 @@ class Server(ServerBase, unittest.TestCase): # opening the same mailbox twice, by the same side, gets the same # object - self.assertIdentical(m1, app.open_mailbox(mailbox_id, u"side1", 1)) + self.assertIdentical(m1, app.open_mailbox(mailbox_id, "side1", 1)) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side1") + self.assertEqual(row["side1"], "side1") self.assertEqual(row["side2"], None) self.assertEqual(row["crowded"], False) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], None) # opening a second side gets the same object, and adds a new claim - self.assertIdentical(m1, app.open_mailbox(mailbox_id, u"side2", 2)) + self.assertIdentical(m1, app.open_mailbox(mailbox_id, "side2", 2)) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side1") - self.assertEqual(row["side2"], u"side2") + self.assertEqual(row["side1"], "side1") + self.assertEqual(row["side2"], "side2") self.assertEqual(row["crowded"], False) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], 2) # a third open marks it as crowded self.assertRaises(rendezvous.CrowdedError, - app.open_mailbox, mailbox_id, u"side3", 3) + app.open_mailbox, mailbox_id, "side3", 3) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side1") - self.assertEqual(row["side2"], u"side2") + self.assertEqual(row["side1"], "side1") + self.assertEqual(row["side2"], "side2") self.assertEqual(row["crowded"], True) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], 2) # closing a side that never claimed the mailbox is ignored - m1.close(u"side4", u"mood", 4) + m1.close("side4", "mood", 4) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side1") - self.assertEqual(row["side2"], u"side2") + self.assertEqual(row["side1"], "side1") + self.assertEqual(row["side2"], "side2") self.assertEqual(row["crowded"], True) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], 2) # closing one side leaves the second claim - m1.close(u"side1", u"mood", 5) + m1.close("side1", "mood", 5) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side2") + self.assertEqual(row["side1"], "side2") self.assertEqual(row["side2"], None) self.assertEqual(row["crowded"], True) self.assertEqual(row["started"], 0) self.assertEqual(row["second"], 2) # closing one side multiple is ignored - m1.close(u"side1", u"mood", 6) + m1.close("side1", "mood", 6) row = self._mailbox(app, mailbox_id) - self.assertEqual(row["side1"], u"side2") + self.assertEqual(row["side1"], "side2") self.assertEqual(row["side2"], None) self.assertEqual(row["crowded"], True) self.assertEqual(row["started"], 0) @@ -211,17 +211,17 @@ class Server(ServerBase, unittest.TestCase): m1.add_listener("handle1", l1.append, stop1_f) # closing the second side frees the mailbox, and adds usage - m1.close(u"side2", u"mood", 7) + m1.close("side2", "mood", 7) self.assertEqual(stop1, [True]) row = self._mailbox(app, mailbox_id) self.assertEqual(row, None) usage = app._db.execute("SELECT * FROM `mailbox_usage`").fetchone() - self.assertEqual(usage["app_id"], u"appid") + self.assertEqual(usage["app_id"], "appid") self.assertEqual(usage["started"], 0) self.assertEqual(usage["waiting_time"], 2) self.assertEqual(usage["total_time"], 7) - self.assertEqual(usage["result"], u"crowded") + self.assertEqual(usage["result"], "crowded") def _messages(self, app): c = app._db.execute("SELECT * FROM `messages`" @@ -229,85 +229,85 @@ class Server(ServerBase, unittest.TestCase): return c.fetchall() def test_messages(self): - app = self._rendezvous.get_app(u"appid") - mailbox_id = u"mid" - m1 = app.open_mailbox(mailbox_id, u"side1", 0) - m1.add_message(SidedMessage(side=u"side1", phase=u"phase", - body=u"body", server_rx=1, - msg_id=u"msgid")) + app = self._rendezvous.get_app("appid") + mailbox_id = "mid" + m1 = app.open_mailbox(mailbox_id, "side1", 0) + m1.add_message(SidedMessage(side="side1", phase="phase", + body="body", server_rx=1, + msg_id="msgid")) msgs = self._messages(app) self.assertEqual(len(msgs), 1) - self.assertEqual(msgs[0]["body"], u"body") + self.assertEqual(msgs[0]["body"], "body") l1 = []; stop1 = []; stop1_f = lambda: stop1.append(True) l2 = []; stop2 = []; stop2_f = lambda: stop2.append(True) old = m1.add_listener("handle1", l1.append, stop1_f) self.assertEqual(len(old), 1) - self.assertEqual(old[0].side, u"side1") - self.assertEqual(old[0].body, u"body") + self.assertEqual(old[0].side, "side1") + self.assertEqual(old[0].body, "body") - m1.add_message(SidedMessage(side=u"side1", phase=u"phase2", - body=u"body2", server_rx=1, - msg_id=u"msgid")) + m1.add_message(SidedMessage(side="side1", phase="phase2", + body="body2", server_rx=1, + msg_id="msgid")) self.assertEqual(len(l1), 1) - self.assertEqual(l1[0].body, u"body2") + self.assertEqual(l1[0].body, "body2") old = m1.add_listener("handle2", l2.append, stop2_f) self.assertEqual(len(old), 2) - m1.add_message(SidedMessage(side=u"side1", phase=u"phase3", - body=u"body3", server_rx=1, - msg_id=u"msgid")) + m1.add_message(SidedMessage(side="side1", phase="phase3", + body="body3", server_rx=1, + msg_id="msgid")) self.assertEqual(len(l1), 2) - self.assertEqual(l1[-1].body, u"body3") + self.assertEqual(l1[-1].body, "body3") self.assertEqual(len(l2), 1) - self.assertEqual(l2[-1].body, u"body3") + self.assertEqual(l2[-1].body, "body3") m1.remove_listener("handle1") - m1.add_message(SidedMessage(side=u"side1", phase=u"phase4", - body=u"body4", server_rx=1, - msg_id=u"msgid")) + m1.add_message(SidedMessage(side="side1", phase="phase4", + body="body4", server_rx=1, + msg_id="msgid")) self.assertEqual(len(l1), 2) - self.assertEqual(l1[-1].body, u"body3") + self.assertEqual(l1[-1].body, "body3") self.assertEqual(len(l2), 2) - self.assertEqual(l2[-1].body, u"body4") + self.assertEqual(l2[-1].body, "body4") m1._shutdown() self.assertEqual(stop1, []) self.assertEqual(stop2, [True]) # message adds are not idempotent: clients filter duplicates - m1.add_message(SidedMessage(side=u"side1", phase=u"phase", - body=u"body", server_rx=1, - msg_id=u"msgid")) + m1.add_message(SidedMessage(side="side1", phase="phase", + body="body", server_rx=1, + msg_id="msgid")) msgs = self._messages(app) self.assertEqual(len(msgs), 5) - self.assertEqual(msgs[-1]["body"], u"body") + self.assertEqual(msgs[-1]["body"], "body") class Prune(unittest.TestCase): def test_apps(self): rv = rendezvous.Rendezvous(get_db(":memory:"), None, None) - app = rv.get_app(u"appid") - app.allocate_nameplate(u"side", 121) + app = rv.get_app("appid") + app.allocate_nameplate("side", 121) app.prune = mock.Mock() rv.prune(now=123, old=122) self.assertEqual(app.prune.mock_calls, [mock.call(123, 122)]) def test_active(self): rv = rendezvous.Rendezvous(get_db(":memory:"), None, None) - app = rv.get_app(u"appid1") + app = rv.get_app("appid1") self.assertFalse(app.is_active()) - mb = app.open_mailbox(u"mbid", u"side1", 0) + mb = app.open_mailbox("mbid", "side1", 0) self.assertFalse(mb.is_active()) self.assertFalse(app.is_active()) - mb.add_listener(u"handle", None, None) + mb.add_listener("handle", None, None) self.assertTrue(mb.is_active()) self.assertTrue(app.is_active()) - mb.remove_listener(u"handle") + mb.remove_listener("handle") self.assertFalse(mb.is_active()) self.assertFalse(app.is_active()) @@ -322,35 +322,35 @@ class Prune(unittest.TestCase): new_mailboxes = set() new_messages = set() - APPID = u"appid" + APPID = "appid" app = rv.get_app(APPID) # Exercise the first-vs-second newness tests. These nameplates have # no mailbox. - app.claim_nameplate(u"np-1", u"side1", 1) - app.claim_nameplate(u"np-2", u"side1", 1) - app.claim_nameplate(u"np-2", u"side2", 2) - app.claim_nameplate(u"np-3", u"side1", 60) - new_nameplates.add(u"np-3") - app.claim_nameplate(u"np-4", u"side1", 1) - app.claim_nameplate(u"np-4", u"side2", 60) - new_nameplates.add(u"np-4") - app.claim_nameplate(u"np-5", u"side1", 60) - app.claim_nameplate(u"np-5", u"side2", 61) - new_nameplates.add(u"np-5") + app.claim_nameplate("np-1", "side1", 1) + app.claim_nameplate("np-2", "side1", 1) + app.claim_nameplate("np-2", "side2", 2) + app.claim_nameplate("np-3", "side1", 60) + new_nameplates.add("np-3") + app.claim_nameplate("np-4", "side1", 1) + app.claim_nameplate("np-4", "side2", 60) + new_nameplates.add("np-4") + app.claim_nameplate("np-5", "side1", 60) + app.claim_nameplate("np-5", "side2", 61) + new_nameplates.add("np-5") # same for mailboxes - app.open_mailbox(u"mb-11", u"side1", 1) - app.open_mailbox(u"mb-12", u"side1", 1) - app.open_mailbox(u"mb-12", u"side2", 2) - app.open_mailbox(u"mb-13", u"side1", 60) - new_mailboxes.add(u"mb-13") - app.open_mailbox(u"mb-14", u"side1", 1) - app.open_mailbox(u"mb-14", u"side2", 60) - new_mailboxes.add(u"mb-14") - app.open_mailbox(u"mb-15", u"side1", 60) - app.open_mailbox(u"mb-15", u"side2", 61) - new_mailboxes.add(u"mb-15") + app.open_mailbox("mb-11", "side1", 1) + app.open_mailbox("mb-12", "side1", 1) + app.open_mailbox("mb-12", "side2", 2) + app.open_mailbox("mb-13", "side1", 60) + new_mailboxes.add("mb-13") + app.open_mailbox("mb-14", "side1", 1) + app.open_mailbox("mb-14", "side2", 60) + new_mailboxes.add("mb-14") + app.open_mailbox("mb-15", "side1", 60) + app.open_mailbox("mb-15", "side2", 61) + new_mailboxes.add("mb-15") rv.prune(now=123, old=50) @@ -387,7 +387,7 @@ class Prune(unittest.TestCase): db = get_db(":memory:") rv = rendezvous.Rendezvous(db, None, 3600) - APPID = u"appid" + APPID = "appid" app = rv.get_app(APPID) # timestamps <=50 are "old", >=51 are "new" @@ -397,12 +397,12 @@ class Prune(unittest.TestCase): mailbox_survives = False messages_survive = False - mbid = u"mbid" + mbid = "mbid" if nameplate is not None: - app.claim_nameplate(u"npid", u"side1", when[nameplate], + app.claim_nameplate("npid", "side1", when[nameplate], _test_mailbox_id=mbid) if mailbox is not None: - mb = app.open_mailbox(mbid, u"side1", when[mailbox]) + mb = app.open_mailbox(mbid, "side1", when[mailbox]) else: # We might want a Mailbox, because that's the easiest way to add # a "messages" row, but we can't use app.open_mailbox() because @@ -415,8 +415,8 @@ class Prune(unittest.TestCase): app._mailboxes[mbid] = mb if messages is not None: - sm = SidedMessage(u"side1", u"phase", u"body", when[messages], - u"msgid") + sm = SidedMessage("side1", "phase", "body", when[messages], + "msgid") mb.add_message(sm) if has_listeners: @@ -500,7 +500,7 @@ class WSClient(websocket.WebSocketClientProtocol): returnValue(m) def strip_acks(self): - self.events = [e for e in self.events if e["type"] != u"ack"] + self.events = [e for e in self.events if e["type"] != "ack"] def send(self, mtype, **kwargs): kwargs["type"] = mtype @@ -630,126 +630,126 @@ class WebSocketAPI(ServerBase, unittest.TestCase): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid") # missing side= + c1.send("bind", appid="appid") # missing side= err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"bind requires 'side'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "bind requires 'side'") - c1.send(u"bind", side=u"side") # missing appid= + c1.send("bind", side="side") # missing appid= err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"bind requires 'appid'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "bind requires 'appid'") - c1.send(u"bind", appid=u"appid", side=u"side") + c1.send("bind", appid="appid", side="side") yield c1.sync() - self.assertEqual(list(self._rendezvous._apps.keys()), [u"appid"]) + self.assertEqual(list(self._rendezvous._apps.keys()), ["appid"]) - c1.send(u"bind", appid=u"appid", side=u"side") # duplicate + c1.send("bind", appid="appid", side="side") # duplicate err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"already bound") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "already bound") c1.send_notype(other="misc") # missing 'type' err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"missing 'type'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "missing 'type'") c1.send("___unknown") # unknown type err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"unknown type") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "unknown type") c1.send("ping") # missing 'ping' err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"ping requires 'ping'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "ping requires 'ping'") @inlineCallbacks def test_list(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"list") # too early, must bind first + c1.send("list") # too early, must bind first err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"must bind first") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "must bind first") - c1.send(u"bind", appid=u"appid", side=u"side") - c1.send(u"list") + c1.send("bind", appid="appid", side="side") + c1.send("list") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"nameplates") - self.assertEqual(m[u"nameplates"], []) + self.assertEqual(m["type"], "nameplates") + self.assertEqual(m["nameplates"], []) - app = self._rendezvous.get_app(u"appid") - nameplate_id1 = app.allocate_nameplate(u"side", 0) - app.claim_nameplate(u"np2", u"side", 0) + app = self._rendezvous.get_app("appid") + nameplate_id1 = app.allocate_nameplate("side", 0) + app.claim_nameplate("np2", "side", 0) - c1.send(u"list") + c1.send("list") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"nameplates") + self.assertEqual(m["type"], "nameplates") nids = set() - for n in m[u"nameplates"]: + for n in m["nameplates"]: self.assertEqual(type(n), dict) - self.assertEqual(list(n.keys()), [u"id"]) - nids.add(n[u"id"]) - self.assertEqual(nids, set([nameplate_id1, u"np2"])) + self.assertEqual(list(n.keys()), ["id"]) + nids.add(n["id"]) + self.assertEqual(nids, set([nameplate_id1, "np2"])) @inlineCallbacks def test_allocate(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"allocate") # too early, must bind first + c1.send("allocate") # too early, must bind first err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"must bind first") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "must bind first") - c1.send(u"bind", appid=u"appid", side=u"side") - app = self._rendezvous.get_app(u"appid") - c1.send(u"allocate") + c1.send("bind", appid="appid", side="side") + app = self._rendezvous.get_app("appid") + c1.send("allocate") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"allocated") - nameplate_id = m[u"nameplate"] + self.assertEqual(m["type"], "allocated") + nameplate_id = m["nameplate"] nids = app.get_nameplate_ids() self.assertEqual(len(nids), 1) self.assertEqual(nameplate_id, list(nids)[0]) - c1.send(u"allocate") + c1.send("allocate") err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], - u"you already allocated one, don't be greedy") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], + "you already allocated one, don't be greedy") - c1.send(u"claim", nameplate=nameplate_id) # allocate+claim is ok + c1.send("claim", nameplate=nameplate_id) # allocate+claim is ok yield c1.sync() row = app._db.execute("SELECT * FROM `nameplates`" " WHERE `app_id`='appid' AND `id`=?", (nameplate_id,)).fetchone() - self.assertEqual(row["side1"], u"side") + self.assertEqual(row["side1"], "side") self.assertEqual(row["side2"], None) @inlineCallbacks def test_claim(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid", side=u"side") - app = self._rendezvous.get_app(u"appid") + c1.send("bind", appid="appid", side="side") + app = self._rendezvous.get_app("appid") - c1.send(u"claim") # missing nameplate= + c1.send("claim") # missing nameplate= err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"claim requires 'nameplate'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "claim requires 'nameplate'") - c1.send(u"claim", nameplate=u"np1") + c1.send("claim", nameplate="np1") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"claimed") - mailbox_id = m[u"mailbox"] - self.assertEqual(type(mailbox_id), type(u"")) + self.assertEqual(m["type"], "claimed") + mailbox_id = m["mailbox"] + self.assertEqual(type(mailbox_id), type("")) nids = app.get_nameplate_ids() self.assertEqual(len(nids), 1) - self.assertEqual(u"np1", list(nids)[0]) + self.assertEqual("np1", list(nids)[0]) # claiming a nameplate will assign a random mailbox id, but won't # create the mailbox itself @@ -761,212 +761,212 @@ class WebSocketAPI(ServerBase, unittest.TestCase): def test_claim_crowded(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid", side=u"side") - app = self._rendezvous.get_app(u"appid") + c1.send("bind", appid="appid", side="side") + app = self._rendezvous.get_app("appid") - app.claim_nameplate(u"np1", u"side1", 0) - app.claim_nameplate(u"np1", u"side2", 0) + app.claim_nameplate("np1", "side1", 0) + app.claim_nameplate("np1", "side2", 0) # the third claim will signal crowding - c1.send(u"claim", nameplate=u"np1") + c1.send("claim", nameplate="np1") err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"crowded") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "crowded") @inlineCallbacks def test_release(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid", side=u"side") - app = self._rendezvous.get_app(u"appid") + c1.send("bind", appid="appid", side="side") + app = self._rendezvous.get_app("appid") - app.claim_nameplate(u"np1", u"side2", 0) + app.claim_nameplate("np1", "side2", 0) - c1.send(u"release") # didn't do claim first + c1.send("release") # didn't do claim first err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], - u"must claim a nameplate before releasing it") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], + "must claim a nameplate before releasing it") - c1.send(u"claim", nameplate=u"np1") + c1.send("claim", nameplate="np1") yield c1.next_non_ack() - c1.send(u"release") + c1.send("release") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"released") + self.assertEqual(m["type"], "released") row = app._db.execute("SELECT * FROM `nameplates`" " WHERE `app_id`='appid' AND `id`='np1'").fetchone() - self.assertEqual(row["side1"], u"side2") + self.assertEqual(row["side1"], "side2") self.assertEqual(row["side2"], None) - c1.send(u"release") # no longer claimed + c1.send("release") # no longer claimed err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], - u"must claim a nameplate before releasing it") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], + "must claim a nameplate before releasing it") @inlineCallbacks def test_open(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid", side=u"side") - app = self._rendezvous.get_app(u"appid") + c1.send("bind", appid="appid", side="side") + app = self._rendezvous.get_app("appid") - c1.send(u"open") # missing mailbox= + c1.send("open") # missing mailbox= err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"open requires 'mailbox'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "open requires 'mailbox'") - mb1 = app.open_mailbox(u"mb1", u"side2", 0) - mb1.add_message(SidedMessage(side=u"side2", phase=u"phase", - body=u"body", server_rx=0, - msg_id=u"msgid")) + mb1 = app.open_mailbox("mb1", "side2", 0) + mb1.add_message(SidedMessage(side="side2", phase="phase", + body="body", server_rx=0, + msg_id="msgid")) - c1.send(u"open", mailbox=u"mb1") + c1.send("open", mailbox="mb1") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"message") - self.assertEqual(m[u"body"], u"body") + self.assertEqual(m["type"], "message") + self.assertEqual(m["body"], "body") - mb1.add_message(SidedMessage(side=u"side2", phase=u"phase2", - body=u"body2", server_rx=0, - msg_id=u"msgid")) + mb1.add_message(SidedMessage(side="side2", phase="phase2", + body="body2", server_rx=0, + msg_id="msgid")) m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"message") - self.assertEqual(m[u"body"], u"body2") + self.assertEqual(m["type"], "message") + self.assertEqual(m["body"], "body2") - c1.send(u"open", mailbox=u"mb1") + c1.send("open", mailbox="mb1") err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"you already have a mailbox open") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "you already have a mailbox open") @inlineCallbacks def test_add(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid", side=u"side") - app = self._rendezvous.get_app(u"appid") - mb1 = app.open_mailbox(u"mb1", u"side2", 0) + c1.send("bind", appid="appid", side="side") + app = self._rendezvous.get_app("appid") + mb1 = app.open_mailbox("mb1", "side2", 0) l1 = []; stop1 = []; stop1_f = lambda: stop1.append(True) mb1.add_listener("handle1", l1.append, stop1_f) - c1.send(u"add") # didn't open first + c1.send("add") # didn't open first err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"must open mailbox before adding") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "must open mailbox before adding") - c1.send(u"open", mailbox=u"mb1") + c1.send("open", mailbox="mb1") - c1.send(u"add", body=u"body") # missing phase= + c1.send("add", body="body") # missing phase= err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"missing 'phase'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "missing 'phase'") - c1.send(u"add", phase=u"phase") # missing body= + c1.send("add", phase="phase") # missing body= err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"missing 'body'") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "missing 'body'") - c1.send(u"add", phase=u"phase", body=u"body") + c1.send("add", phase="phase", body="body") m = yield c1.next_non_ack() # echoed back - self.assertEqual(m[u"type"], u"message") - self.assertEqual(m[u"body"], u"body") + self.assertEqual(m["type"], "message") + self.assertEqual(m["body"], "body") self.assertEqual(len(l1), 1) - self.assertEqual(l1[0].body, u"body") + self.assertEqual(l1[0].body, "body") @inlineCallbacks def test_close(self): c1 = yield self.make_client() yield c1.next_non_ack() - c1.send(u"bind", appid=u"appid", side=u"side") + c1.send("bind", appid="appid", side="side") - c1.send(u"close", mood=u"mood") # must open first + c1.send("close", mood="mood") # must open first err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"must open mailbox before closing") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "must open mailbox before closing") - c1.send(u"open", mailbox=u"mb1") - c1.send(u"close", mood=u"mood") + c1.send("open", mailbox="mb1") + c1.send("close", mood="mood") m = yield c1.next_non_ack() - self.assertEqual(m[u"type"], u"closed") + self.assertEqual(m["type"], "closed") - c1.send(u"close", mood=u"mood") # already closed + c1.send("close", mood="mood") # already closed err = yield c1.next_non_ack() - self.assertEqual(err[u"type"], u"error") - self.assertEqual(err[u"error"], u"must open mailbox before closing") + self.assertEqual(err["type"], "error") + self.assertEqual(err["error"], "must open mailbox before closing") class Summary(unittest.TestCase): def test_mailbox(self): app = rendezvous.AppNamespace(None, None, False, None) # starts at time 1, maybe gets second open at time 3, closes at 5 - base_row = {u"started": 1, u"second": None, - u"first_mood": None, u"crowded": False} + base_row = {"started": 1, "second": None, + "first_mood": None, "crowded": False} def summ(num_sides, second_mood=None, pruned=False, **kwargs): row = base_row.copy() row.update(kwargs) return app._summarize_mailbox(row, num_sides, second_mood, 5, pruned) - self.assertEqual(summ(1), Usage(1, None, 4, u"lonely")) - self.assertEqual(summ(1, u"lonely"), Usage(1, None, 4, u"lonely")) - self.assertEqual(summ(1, u"errory"), Usage(1, None, 4, u"errory")) - self.assertEqual(summ(1, crowded=True), Usage(1, None, 4, u"crowded")) + self.assertEqual(summ(1), Usage(1, None, 4, "lonely")) + self.assertEqual(summ(1, "lonely"), Usage(1, None, 4, "lonely")) + self.assertEqual(summ(1, "errory"), Usage(1, None, 4, "errory")) + self.assertEqual(summ(1, crowded=True), Usage(1, None, 4, "crowded")) - self.assertEqual(summ(2, first_mood=u"happy", - second=3, second_mood=u"happy"), - Usage(1, 2, 4, u"happy")) + self.assertEqual(summ(2, first_mood="happy", + second=3, second_mood="happy"), + Usage(1, 2, 4, "happy")) - self.assertEqual(summ(2, first_mood=u"errory", - second=3, second_mood=u"happy"), - Usage(1, 2, 4, u"errory")) + self.assertEqual(summ(2, first_mood="errory", + second=3, second_mood="happy"), + Usage(1, 2, 4, "errory")) - self.assertEqual(summ(2, first_mood=u"happy", - second=3, second_mood=u"errory"), - Usage(1, 2, 4, u"errory")) + self.assertEqual(summ(2, first_mood="happy", + second=3, second_mood="errory"), + Usage(1, 2, 4, "errory")) - self.assertEqual(summ(2, first_mood=u"scary", - second=3, second_mood=u"happy"), - Usage(1, 2, 4, u"scary")) + self.assertEqual(summ(2, first_mood="scary", + second=3, second_mood="happy"), + Usage(1, 2, 4, "scary")) - self.assertEqual(summ(2, first_mood=u"scary", - second=3, second_mood=u"errory"), - Usage(1, 2, 4, u"scary")) + self.assertEqual(summ(2, first_mood="scary", + second=3, second_mood="errory"), + Usage(1, 2, 4, "scary")) - self.assertEqual(summ(2, first_mood=u"happy", second=3, pruned=True), - Usage(1, 2, 4, u"pruney")) + self.assertEqual(summ(2, first_mood="happy", second=3, pruned=True), + Usage(1, 2, 4, "pruney")) def test_nameplate(self): a = rendezvous.AppNamespace(None, None, False, None) # starts at time 1, maybe gets second open at time 3, closes at 5 - base_row = {u"started": 1, u"second": None, u"crowded": False} + base_row = {"started": 1, "second": None, "crowded": False} def summ(num_sides, pruned=False, **kwargs): row = base_row.copy() row.update(kwargs) return a._summarize_nameplate_usage(row, 5, pruned) - self.assertEqual(summ(1), Usage(1, None, 4, u"lonely")) - self.assertEqual(summ(1, crowded=True), Usage(1, None, 4, u"crowded")) + self.assertEqual(summ(1), Usage(1, None, 4, "lonely")) + self.assertEqual(summ(1, crowded=True), Usage(1, None, 4, "crowded")) - self.assertEqual(summ(2, second=3), Usage(1, 2, 4, u"happy")) + self.assertEqual(summ(2, second=3), Usage(1, 2, 4, "happy")) self.assertEqual(summ(2, second=3, pruned=True), - Usage(1, 2, 4, u"pruney")) + Usage(1, 2, 4, "pruney")) def test_blur(self): db = get_db(":memory:") rv = rendezvous.Rendezvous(db, None, 3600) - APPID = u"appid" + APPID = "appid" app = rv.get_app(APPID) - app.claim_nameplate(u"npid", u"side1", 10) # start time is 10 + app.claim_nameplate("npid", "side1", 10) # start time is 10 rv.prune(now=123, old=50) # start time should be rounded to top of the hour (blur_usage=3600) row = db.execute("SELECT * FROM `nameplate_usage`").fetchone() self.assertEqual(row["started"], 0) app = rv.get_app(APPID) - app.open_mailbox(u"mbid", u"side1", 20) # start time is 20 + app.open_mailbox("mbid", "side1", 20) # start time is 20 rv.prune(now=123, old=50) row = db.execute("SELECT * FROM `mailbox_usage`").fetchone() self.assertEqual(row["started"], 0) @@ -974,15 +974,15 @@ class Summary(unittest.TestCase): def test_no_blur(self): db = get_db(":memory:") rv = rendezvous.Rendezvous(db, None, None) - APPID = u"appid" + APPID = "appid" app = rv.get_app(APPID) - app.claim_nameplate(u"npid", u"side1", 10) # start time is 10 + app.claim_nameplate("npid", "side1", 10) # start time is 10 rv.prune(now=123, old=50) row = db.execute("SELECT * FROM `nameplate_usage`").fetchone() self.assertEqual(row["started"], 10) app = rv.get_app(APPID) - app.open_mailbox(u"mbid", u"side1", 20) # start time is 20 + app.open_mailbox("mbid", "side1", 20) # start time is 20 rv.prune(now=123, old=50) row = db.execute("SELECT * FROM `mailbox_usage`").fetchone() self.assertEqual(row["started"], 20) From 150caedf7343a479640c50a30a130df9b297cd19 Mon Sep 17 00:00:00 2001 From: laharah Date: Sat, 4 Jun 2016 14:03:05 -0700 Subject: [PATCH 11/11] `u""` cleanup on test_scripts.py --- src/wormhole/test/common.py | 1 + src/wormhole/test/test_scripts.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py index 5b337bf..91961d7 100644 --- a/src/wormhole/test/common.py +++ b/src/wormhole/test/common.py @@ -1,3 +1,4 @@ +# no unicode_literals untill twisted update from twisted.application import service from twisted.internet import reactor, defer from twisted.python import log diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index 7e5ce01..40dbf8d 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -241,7 +241,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): common_args = ["--hide-progress", "--relay-url", self.relayurl, "--transit-helper", ""] - code = u"1-abc" + code = "1-abc" message = "test message" send_args = common_args + [ @@ -443,7 +443,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): common_args = ["--hide-progress", "--no-listen", "--relay-url", self.relayurl, "--transit-helper", ""] - code = u"1-abc" + code = "1-abc" message = "test message" send_args = common_args + [ "send", "--code", code ] @@ -527,7 +527,7 @@ class PregeneratedCode(ServerBase, ScriptsBase, unittest.TestCase): class NotWelcome(ServerBase, unittest.TestCase): def setUp(self): - self._setup_relay(error=u"please upgrade XYZ") + self._setup_relay(error="please upgrade XYZ") @inlineCallbacks def test_sender(self): @@ -535,7 +535,7 @@ class NotWelcome(ServerBase, unittest.TestCase): "--relay-url", self.relayurl, "--transit-helper", ""] send_args = common_args + [ "send", "--text", "hi", - "--code", u"1-abc" ] + "--code", "1-abc" ] sargs = runner.parser.parse_args(send_args) sargs.cwd = self.mktemp() sargs.stdout = io.StringIO() @@ -551,7 +551,7 @@ class NotWelcome(ServerBase, unittest.TestCase): common_args = ["--hide-progress", "--no-listen", "--relay-url", self.relayurl, "--transit-helper", ""] - receive_args = common_args + [ "receive", u"1-abc" ] + receive_args = common_args + [ "receive", "1-abc" ] rargs = runner.parser.parse_args(receive_args) rargs.cwd = self.mktemp() rargs.stdout = io.StringIO() @@ -566,7 +566,7 @@ class Cleanup(ServerBase, unittest.TestCase): @inlineCallbacks def test_text(self): # the rendezvous channel should be deleted after success - code = u"1-abc" + code = "1-abc" common_args = ["--hide-progress", "--relay-url", self.relayurl, "--transit-helper", ""] @@ -601,12 +601,12 @@ class Cleanup(ServerBase, unittest.TestCase): sargs = runner.parser.parse_args(common_args + ["send", "--text", "secret message", - "--code", u"1-abc"]) + "--code", "1-abc"]) sargs.stdout = io.StringIO() sargs.stderr = io.StringIO() sargs.timing = DebugTiming() rargs = runner.parser.parse_args(common_args + - ["receive", u"1-WRONG"]) + ["receive", "1-WRONG"]) rargs.stdout = io.StringIO() rargs.stderr = io.StringIO() rargs.timing = DebugTiming() @@ -624,7 +624,7 @@ class Cleanup(ServerBase, unittest.TestCase): class ExtractFile(unittest.TestCase): def test_filenames(self): args = mock.Mock() - args.relay_url = u"" + args.relay_url = "" ef = cmd_receive.TwistedReceiver(args)._extract_file extract_dir = os.path.abspath(self.mktemp())