From: erickson Date: Wed, 18 Jul 2007 22:27:53 +0000 (+0000) Subject: Merged revisions 1044-1049 via svnmerge from X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=ade105b41e66bc906abae1fd8c5198f059f05c4d;p=OpenSRF.git Merged revisions 1044-1049 via svnmerge from svn://svn.open-ils.org/OpenSRF/trunk ........ r1049 | erickson | 2007-07-18 18:27:04 -0400 (Wed, 18 Jul 2007) | 1 line fixed bug in json encoding of hinted objects and some display bugs ........ git-svn-id: svn://svn.open-ils.org/OpenSRF/branches/new-json2@1050 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/python/osrf/json.py b/src/python/osrf/json.py index 8845b92..a972b09 100644 --- a/src/python/osrf/json.py +++ b/src/python/osrf/json.py @@ -4,10 +4,21 @@ from osrf.const import OSRF_JSON_PAYLOAD_KEY, OSRF_JSON_CLASS_KEY class osrfJSONNetworkEncoder(simplejson.JSONEncoder): def default(self, obj): + if isinstance(obj, osrfNetworkObject): + reg = obj.getRegistry() + data = obj.getData() + + # re-encode the object as an array if necessary + if reg.wireProtocol == 'array': + d = [] + for k in reg.keys: + d.append(data[k]) + data = d + return { - OSRF_JSON_CLASS_KEY: obj.getRegistry().hint, - OSRF_JSON_PAYLOAD_KEY: self.default(obj.getData()) + OSRF_JSON_CLASS_KEY: reg.hint, + OSRF_JSON_PAYLOAD_KEY: self.default(data) } return obj @@ -77,9 +88,15 @@ def osrfFormatJSON(json): instring = False inescape = False done = False + eatws = False for c in json: + if eatws: # simpljson adds a pesky after array and object items + if c == ' ': + continue + + eatws = False done = False if (c == '{' or c == '[') and not instring: t += 1 @@ -94,6 +111,10 @@ def osrfFormatJSON(json): if c == ',' and not instring: r += c + '\n' + __tabs(t) done = True + eatws = True + + if c == ':' and not instring: + eatws = True if c == '"' and not inescape: instring = not instring diff --git a/src/python/srfsh.py b/src/python/srfsh.py index 70a278e..bb058b1 100755 --- a/src/python/srfsh.py +++ b/src/python/srfsh.py @@ -129,7 +129,7 @@ def handle_request(parts): otp = get_var('SRFSH_OUTPUT') if otp == 'pretty': - print osrfDebugNetworkObject(resp.content()) + print "\n" + osrfDebugNetworkObject(resp.content()) else: print osrfFormatJSON(osrfObjectToJSON(resp.content()))