From 0ce08b66cf48fe840387bae1e2e502bbc984b830 Mon Sep 17 00:00:00 2001 From: meejah Date: Sun, 18 Apr 2021 21:25:25 -0600 Subject: [PATCH] defensive if's -> assert --- src/wormhole_transit_relay/transit_server.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/wormhole_transit_relay/transit_server.py b/src/wormhole_transit_relay/transit_server.py index 35a2853..4b7b0b5 100644 --- a/src/wormhole_transit_relay/transit_server.py +++ b/src/wormhole_transit_relay/transit_server.py @@ -52,11 +52,11 @@ class TransitConnection(LineReceiver): """ ITransitClient API """ - if self._buddy is not None: - if self.factory.log_requests: - log.msg("buddy_disconnected {}".format(self._buddy.get_token())) - self._buddy._client.disconnect() - self._buddy = None + assert self._buddy is not None, "internal error: no buddy" + if self.factory.log_requests: + log.msg("buddy_disconnected {}".format(self._buddy.get_token())) + self._buddy._client.disconnect() + self._buddy = None def connectionMade(self): # ideally more like self._reactor.seconds() ... but Twisted @@ -203,11 +203,11 @@ class WebSocketTransitConnection(WebSocketServerProtocol): """ ITransitClient API """ - if self._buddy is not None: - if self.factory.log_requests: - log.msg("buddy_disconnected {}".format(self._buddy.get_token())) - self._buddy._client.disconnect() - self._buddy = None + assert self._buddy is not None, "internal error: no buddy" + if self.factory.log_requests: + log.msg("buddy_disconnected {}".format(self._buddy.get_token())) + self._buddy._client.disconnect() + self._buddy = None def connectionMade(self): """