From 8cacf9c00bcd2cfda75335186230e4a1d5c82b1a 2011-11-24 21:25:47 From: Fernando Perez Date: 2011-11-24 21:25:47 Subject: [PATCH] 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. --- diff --git a/IPython/parallel/apps/ipcontrollerapp.py b/IPython/parallel/apps/ipcontrollerapp.py index aa6b253..4ae3469 100755 --- a/IPython/parallel/apps/ipcontrollerapp.py +++ b/IPython/parallel/apps/ipcontrollerapp.py @@ -33,7 +33,8 @@ from multiprocessing import Process import zmq from zmq.devices import ProcessMonitoredQueue from zmq.log.handlers import PUBHandler -from zmq.utils import jsonapi as json +#from zmq.utils import jsonapi as json +from IPython.zmq import jsonapi as json from IPython.core.profiledir import ProfileDir diff --git a/IPython/zmq/entry_point.py b/IPython/zmq/entry_point.py index c54664e..6ecc33d 100644 --- a/IPython/zmq/entry_point.py +++ b/IPython/zmq/entry_point.py @@ -11,7 +11,8 @@ import sys import tempfile # System library imports -from zmq.utils import jsonapi as json +#from zmq.utils import jsonapi as json +from IPython.zmq import jsonapi as json # IPython imports from IPython.utils.localinterfaces import LOCALHOST diff --git a/IPython/zmq/jsonapi.py b/IPython/zmq/jsonapi.py new file mode 100644 index 0000000..cb2271c --- /dev/null +++ b/IPython/zmq/jsonapi.py @@ -0,0 +1,36 @@ +"""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)