def process_reply(reply, nested=False):
"""
Process a reply so it looks nice:
- if it's from the prototype yang integration, ditch the 'data' root
- convert from list to nested format if requested
- convert quotes to avoid escaping
"""
try:
# @@@ strip 'data' from yang output
reply['result'] = reply['result'][0]['data']
except Exception:
pass
# If required, and query successful, convert the reply['result'] format.
try:
if nested:
reply['result'] = reformat(reply['result'])
except KeyError:
# Fails silently if there is no 'reply['result']' in the reply['result'], this
# means an error occurred.
pass
# @@@ cheesily try to avoid \" everywhere, at cost of valid json
return re.sub(r'\\"', "'", json.dumps(reply))
评论列表
文章目录