From 098e3156246b1d1dd5ed5258d9b231dd1be0ba2e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 12 Feb 2018 17:34:11 -0800 Subject: [PATCH] remove a few lines by using defaultdict() --- src/wormhole_transit_relay/transit_server.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wormhole_transit_relay/transit_server.py b/src/wormhole_transit_relay/transit_server.py index cbb44cc..26d0274 100644 --- a/src/wormhole_transit_relay/transit_server.py +++ b/src/wormhole_transit_relay/transit_server.py @@ -1,5 +1,6 @@ from __future__ import print_function, unicode_literals import re, time, json +from collections import defaultdict from twisted.python import log from twisted.internet import protocol from .database import get_db @@ -265,12 +266,10 @@ class Transit(protocol.ServerFactory): self._db = get_db(usage_db) self._rebooted = time.time() # we don't track TransitConnections until they submit a token - self._pending_requests = {} # token -> set((side, TransitConnection)) + self._pending_requests = defaultdict(set) # token -> set((side, TransitConnection)) self._active_connections = set() # TransitConnection def connection_got_token(self, token, new_side, new_tc): - if token not in self._pending_requests: - self._pending_requests[token] = set() potentials = self._pending_requests[token] for old in potentials: (old_side, old_tc) = old