##// END OF EJS Templates
Work around incompatibilities between jsonlib and json....
Work around incompatibilities between jsonlib and json. Note that there seems to be a deeper problem with jsonlib; at least on my system it doesn't pass the full test suite. But with this fix, regular interactive use is now OK. Closes #1037.

File last commit:

r5416:8cacf9c0
r5416:8cacf9c0
Show More
jsonapi.py
36 lines | 1.4 KiB | text/x-python | PythonLexer
"""Wrap zmq's jsonapi and work around api incompatibilities.
This file is effectively a replacement for zmq.utils.jsonapi, that works around
incompatibilities between jsonlib and the stdlib json, such as the
interpretation of the 'indent' keyword in dumps().
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from zmq.utils import jsonapi as _json
from zmq.utils.jsonapi import *
#-----------------------------------------------------------------------------
# Function definitions
#-----------------------------------------------------------------------------
try:
_json.dumps(1, indent=2)
except TypeError:
# This happens with jsonlib, which takes indent as a string instead of as
# an int.
def dumps(o, **kw):
if 'indent' in kw:
indent = kw.pop('indent')
if isinstance(indent, int):
indent = ' ' * indent
kw['indent'] = indent
return _json.dumps(o, **kw)