2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-12-25 12:41:39 +00:00

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.
This commit is contained in:
Jarrod Johnson 2015-03-23 09:38:56 -04:00
parent 54d2d2dffa
commit 77284af60d
3 changed files with 15 additions and 3 deletions

View File

@ -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:

View File

@ -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(

View File

@ -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