From e5fcc6a8c8371f19fa97526e43a4f2d620629bfb Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 24 Jul 2015 16:18:03 -0700 Subject: [PATCH] rename some methods to make them more private --- src/wormhole/blocking/transcribe.py | 16 ++++++++-------- src/wormhole/twisted/transcribe.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/wormhole/blocking/transcribe.py b/src/wormhole/blocking/transcribe.py index 4560350..1ca1264 100644 --- a/src/wormhole/blocking/transcribe.py +++ b/src/wormhole/blocking/transcribe.py @@ -59,7 +59,7 @@ class Wormhole: self.key = None self.verifier = None - def url(self, verb, msgnum=None): + def _url(self, verb, msgnum=None): url = "%s%d/%s/%s" % (self.relay, self.channel_id, self.side, verb) if msgnum is not None: url += "/" + msgnum @@ -87,7 +87,7 @@ class Wormhole: if "error" in welcome: raise ServerError(welcome["error"], self.relay) - def get(self, old_msgs, verb, msgnum): + def _get_messages(self, old_msgs, verb, msgnum): # For now, server errors cause the client to fail. TODO: don't. This # will require changing the client to re-post messages when the # server comes back up. @@ -103,7 +103,7 @@ class Wormhole: if remaining < 0: raise Timeout #time.sleep(self.wait) - f = EventSourceFollower(self.url(verb, msgnum), remaining) + f = EventSourceFollower(self._url(verb, msgnum), remaining) for (eventtype, data) in f.iter_events(): if eventtype == "welcome": self.handle_welcome(json.loads(data)) @@ -172,11 +172,11 @@ class Wormhole: def _get_key(self): if not self.key: post_data = {"message": hexlify(self.msg1).decode("ascii")} - r = requests.post(self.url("post", "pake"), + r = requests.post(self._url("post", "pake"), data=json.dumps(post_data)) r.raise_for_status() other_msgs = r.json()["messages"] - msgs = self.get(other_msgs, "poll", "pake") + msgs = self._get_messages(other_msgs, "poll", "pake") pake_msg = unhexlify(msgs[0].encode("ascii")) self.key = self.sp.finish(pake_msg) self.verifier = self.derive_key(self.appid+b":Verifier") @@ -224,16 +224,16 @@ class Wormhole: def _post_data(self, data): post_data = json.dumps({"message": hexlify(data).decode("ascii")}) - r = requests.post(self.url("post", "data"), data=post_data) + r = requests.post(self._url("post", "data"), data=post_data) r.raise_for_status() other_msgs = r.json()["messages"] return other_msgs def _get_data(self, other_msgs): - msgs = self.get(other_msgs, "poll", "data") + msgs = self._get_messages(other_msgs, "poll", "data") data = unhexlify(msgs[0].encode("ascii")) return data def _deallocate(self): - r = requests.post(self.url("deallocate")) + r = requests.post(self._url("deallocate")) r.raise_for_status() diff --git a/src/wormhole/twisted/transcribe.py b/src/wormhole/twisted/transcribe.py index 4728236..a50672e 100644 --- a/src/wormhole/twisted/transcribe.py +++ b/src/wormhole/twisted/transcribe.py @@ -69,7 +69,7 @@ class SymmetricWormhole: def _allocate_channel(self): url = self.relay + "allocate/%s" % self.side - d = self.post(url) + d = self._post_json(url) def _got_channel(data): if "welcome" in data: self.handle_welcome(data["welcome"]) @@ -149,13 +149,13 @@ class SymmetricWormhole: if "error" in welcome: raise ServerError(welcome["error"], self.relay) - def url(self, verb, msgnum=None): + def _url(self, verb, msgnum=None): url = "%s%d/%s/%s" % (self.relay, self.channel_id, self.side, verb) if msgnum is not None: url += "/" + msgnum return url - def post(self, url, post_json=None): + def _post_json(self, url, post_json=None): # TODO: retry on failure, with exponential backoff. We're guarding # against the rendezvous server being temporarily offline. p = None @@ -172,7 +172,7 @@ class SymmetricWormhole: d.addCallback(lambda data: json.loads(data)) return d - def _get_msgs(self, old_msgs, verb, msgnum): + def _get_messages(self, old_msgs, verb, msgnum): # fire with a list of messages that match verb/msgnum, which either # came from old_msgs, or from an EventSource that we attached to the # corresponding URL @@ -186,7 +186,7 @@ class SymmetricWormhole: if name == "message": msgs.append(json.loads(data)["message"]) d.callback(None) - es = ReconnectingEventSource(None, lambda: self.url(verb, msgnum), + es = ReconnectingEventSource(None, lambda: self._url(verb, msgnum), _handle)#, agent=self.agent) es.startService() # TODO: .setServiceParent(self) es.activate() @@ -220,8 +220,8 @@ class SymmetricWormhole: if self.key: return defer.succeed(self.key) data = {"message": hexlify(self.msg1).decode("ascii")} - d = self.post(self.url("post", "pake"), data) - d.addCallback(lambda j: self._get_msgs(j["messages"], "poll", "pake")) + d = self._post_json(self._url("post", "pake"), data) + d.addCallback(lambda j: self._get_messages(j["messages"], "poll", "pake")) def _got_pake(msgs): pake_msg = unhexlify(msgs[0].encode("ascii")) key = self.sp.finish(pake_msg) @@ -251,8 +251,8 @@ class SymmetricWormhole: data_key = self.derive_key(b"data-key") outbound_encrypted = self._encrypt_data(data_key, outbound_data) data = {"message": hexlify(outbound_encrypted).decode("ascii")} - d = self.post(self.url("post", "data"), data) - d.addCallback(lambda j: self._get_msgs(j["messages"], "poll", "data")) + d = self._post_json(self._url("post", "data"), data) + d.addCallback(lambda j: self._get_messages(j["messages"], "poll", "data")) def _got_data(msgs): inbound_encrypted = unhexlify(msgs[0].encode("ascii")) if inbound_encrypted == outbound_encrypted: @@ -268,6 +268,6 @@ class SymmetricWormhole: def _deallocate(self, res): # only try once, no retries - d = self.agent.request("POST", self.url("deallocate")) + d = self.agent.request("POST", self._url("deallocate")) d.addBoth(lambda _: res) # ignore POST failure, pass-through result return d