From ec5f0c1796f754a1831c48daadae4c24b81d430b Mon Sep 17 00:00:00 2001 From: genjix Date: Mon, 23 Apr 2012 04:09:11 +0100 Subject: [PATCH] be stricter with response typing. --- backends/libbitcoin/__init__.py | 1 - processor.py | 16 +++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backends/libbitcoin/__init__.py b/backends/libbitcoin/__init__.py index 0687092..5d9a4d8 100644 --- a/backends/libbitcoin/__init__.py +++ b/backends/libbitcoin/__init__.py @@ -254,7 +254,6 @@ class NumblocksSubscribe: def subscribe(self, request): latest = self.latest.get() response = {"id": request["id"], - "method": "blockchain.numblocks.subscribe", "result": latest, "error": None} self.processor.push_response(response) diff --git a/processor.py b/processor.py index e41e303..4005408 100644 --- a/processor.py +++ b/processor.py @@ -189,7 +189,8 @@ class Session: self.subscriptions.append(subdesc) # subdesc = A subscription description - def build_subdesc(self, method, params): + @staticmethod + def build_subdesc(method, params): if method == "blockchain.numblocks.subscribe": return method, elif method == "blockchain.address.get_history": @@ -222,18 +223,19 @@ class ResponseDispatcher(threading.Thread): #print "pop response", response internal_id = response.get('id') method = response.get('method') - params = response.get('params', []) + params = response.get('params') # A notification - if internal_id is None and method is None: - self.notification(response) - elif internal_id is not None: + if internal_id is None and method is not None and params is not None: + self.notification(method, params, response) + # A response + elif internal_id is not None and method is None and params is None: self.send_response(internal_id, response) else: print "no method", response - def notification(self, response): - subdesc = self.build_subdesc(method, params) + def notification(self, method, params, response): + subdesc = Session.build_subdesc(method, params) for session in self.processor.sessions: if session.stopped(): continue -- 1.7.1