From 77284af60da716e946ecc1f60eaf0099805cde67 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 23 Mar 2015 09:38:56 -0400 Subject: [PATCH] Rework multiple node result data Before there was some awkward ambiguity between top level key names and node names. For example a node named 'error' would be tricky. Address that by allocating a 'databynode' top level container to clarify the namespace of keys is nodenames specifically. Use this to simplify code that tried to workaround the ambiguity. --- confluent_client/bin/confetty | 3 +++ confluent_client/confluent/client.py | 5 ++++- confluent_server/confluent/messages.py | 10 ++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/confluent_client/bin/confetty b/confluent_client/bin/confetty index 7815d250..044cec95 100755 --- a/confluent_client/bin/confetty +++ b/confluent_client/bin/confetty @@ -239,6 +239,9 @@ def print_result(res): if 'errorcode' in res or 'error' in res: print res['error'] return + if 'databynode' in res: + print_result(res['databynode']) + return for key in res.iterkeys(): notes = [] if res[key] is None: diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index c16f108c..1e819aca 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -71,12 +71,15 @@ class Command(object): self.authenticated = True def handle_results(self, ikey, rc, res): - if 'error' in res and type(res['error']) in (str, unicode): + if 'error' in res: sys.stderr.write('Error: {0}\n'.format(res['error'])) if 'errorcode' in res: return res['errorcode'] else: return 1 + if 'databynode' not in res: + return 0 + res = res['databynode'] for node in res: if 'error' in res[node]: sys.stderr.write('{0}: Error: {1}\n'.format( diff --git a/confluent_server/confluent/messages.py b/confluent_server/confluent/messages.py index b330ef04..5c7617b1 100644 --- a/confluent_server/confluent/messages.py +++ b/confluent_server/confluent/messages.py @@ -54,14 +54,20 @@ class ConfluentMessage(object): def json(self): # This will create the canonical json representation of this message - jsonsnippet = json.dumps(self.kvpairs, separators=(',', ':'))[1:-1] + if self.stripped: + datasource = self.kvpairs + else: + datasource = {'databynode': self.kvpairs} + jsonsnippet = json.dumps(datasource, separators=(',', ':'))[1:-1] return jsonsnippet def raw(self): """Return pythonic representation of the response. Used by httpapi while assembling data prior to json serialization""" - return self.kvpairs + if self.stripped: + return self.kvpairs + return {'databynode': self.kvpairs} def strip_node(self, node): self.stripped = True