From 1645d22dc118ee1df0a82a318c50d59861474627 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann Date: Tue, 20 Oct 2009 18:17:12 +0200 Subject: [PATCH] =?utf8?q?Ensure=20RpcResult=20has=20=E2=80=9Cpayload=E2=80=9D?= =?utf8?q?=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also add assertions to avoid missing attributes in the future. They won't be included in optimized bytecode. Signed-off-by: Michael Hanselmann Reviewed-by: Guido Trotter --- lib/rpc.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/rpc.py b/lib/rpc.py index 61895d5..8701945 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -97,6 +97,7 @@ class RpcResult(object): self.offline = offline self.call = call self.node = node + if offline: self.fail_msg = "Node is marked offline" self.data = self.payload = None @@ -108,16 +109,26 @@ class RpcResult(object): if not isinstance(self.data, (tuple, list)): self.fail_msg = ("RPC layer error: invalid result type (%s)" % type(self.data)) + self.payload = None elif len(data) != 2: self.fail_msg = ("RPC layer error: invalid result length (%d), " "expected 2" % len(self.data)) + self.payload = None elif not self.data[0]: self.fail_msg = self._EnsureErr(self.data[1]) + self.payload = None else: # finally success self.fail_msg = None self.payload = data[1] + assert hasattr(self, "call") + assert hasattr(self, "data") + assert hasattr(self, "fail_msg") + assert hasattr(self, "node") + assert hasattr(self, "offline") + assert hasattr(self, "payload") + @staticmethod def _EnsureErr(val): """Helper to ensure we return a 'True' value for error.""" -- 1.7.10.4