defensive if's -> assert

This commit is contained in:
meejah 2021-04-18 21:25:25 -06:00
parent dfd3bdd1a1
commit 0ce08b66cf

View File

@ -52,11 +52,11 @@ class TransitConnection(LineReceiver):
""" """
ITransitClient API ITransitClient API
""" """
if self._buddy is not None: assert self._buddy is not None, "internal error: no buddy"
if self.factory.log_requests: if self.factory.log_requests:
log.msg("buddy_disconnected {}".format(self._buddy.get_token())) log.msg("buddy_disconnected {}".format(self._buddy.get_token()))
self._buddy._client.disconnect() self._buddy._client.disconnect()
self._buddy = None self._buddy = None
def connectionMade(self): def connectionMade(self):
# ideally more like self._reactor.seconds() ... but Twisted # ideally more like self._reactor.seconds() ... but Twisted
@ -203,11 +203,11 @@ class WebSocketTransitConnection(WebSocketServerProtocol):
""" """
ITransitClient API ITransitClient API
""" """
if self._buddy is not None: assert self._buddy is not None, "internal error: no buddy"
if self.factory.log_requests: if self.factory.log_requests:
log.msg("buddy_disconnected {}".format(self._buddy.get_token())) log.msg("buddy_disconnected {}".format(self._buddy.get_token()))
self._buddy._client.disconnect() self._buddy._client.disconnect()
self._buddy = None self._buddy = None
def connectionMade(self): def connectionMade(self):
""" """