Browse Source

move get_index from network to session

3.3.3.1
SomberNight 6 years ago
parent
commit
8b8ca14c6d
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 9
      electrum/interface.py
  2. 5
      electrum/network.py

9
electrum/interface.py

@ -54,7 +54,7 @@ class NotificationSession(ClientSession):
# will catch the exception, count errors, and at some point disconnect
if isinstance(request, Notification):
params, result = request.args[:-1], request.args[-1]
key = request.method + repr(params)
key = self.get_index(request.method, params)
if key in self.subscriptions:
self.cache[key] = result
for queue in self.subscriptions[key]:
@ -70,7 +70,7 @@ class NotificationSession(ClientSession):
timeout)
async def subscribe(self, method, params, queue):
key = method + repr(params)
key = self.get_index(method, params)
if key in self.subscriptions:
self.subscriptions[key].append(queue)
result = self.cache[key]
@ -88,6 +88,11 @@ class NotificationSession(ClientSession):
if queue in v:
v.remove(queue)
@classmethod
def get_index(cls, method, params):
"""Hashable index for subscriptions and cache"""
return str(method) + repr(params)
# FIXME this is often raised inside a TaskGroup, but then it's not silent :(
class GracefulDisconnect(AIOSafeSilentException): pass

5
electrum/network.py

@ -598,11 +598,6 @@ class Network(PrintError):
self.recent_servers = self.recent_servers[0:20]
self.save_recent_servers()
@classmethod
def get_index(cls, method, params):
""" hashable index for subscriptions and cache"""
return str(method) + (':' + str(params[0]) if params else '')
@with_interface_lock
def connection_down(self, server):
'''A connection to server either went down, or was never made.

Loading…
Cancel
Save