##// END OF EJS Templates
Work around incompatibilities between jsonlib and json....
Fernando Perez -
Show More
@@ -0,0 +1,36 b''
1 """Wrap zmq's jsonapi and work around api incompatibilities.
2
3 This file is effectively a replacement for zmq.utils.jsonapi, that works around
4 incompatibilities between jsonlib and the stdlib json, such as the
5 interpretation of the 'indent' keyword in dumps().
6 """
7 #-----------------------------------------------------------------------------
8 # Copyright (C) 2011 The IPython Development Team
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #-----------------------------------------------------------------------------
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17
18 from zmq.utils import jsonapi as _json
19 from zmq.utils.jsonapi import *
20
21 #-----------------------------------------------------------------------------
22 # Function definitions
23 #-----------------------------------------------------------------------------
24 try:
25 _json.dumps(1, indent=2)
26 except TypeError:
27 # This happens with jsonlib, which takes indent as a string instead of as
28 # an int.
29 def dumps(o, **kw):
30 if 'indent' in kw:
31 indent = kw.pop('indent')
32 if isinstance(indent, int):
33 indent = ' ' * indent
34 kw['indent'] = indent
35
36 return _json.dumps(o, **kw)
@@ -33,7 +33,8 b' from multiprocessing import Process'
33 33 import zmq
34 34 from zmq.devices import ProcessMonitoredQueue
35 35 from zmq.log.handlers import PUBHandler
36 from zmq.utils import jsonapi as json
36 #from zmq.utils import jsonapi as json
37 from IPython.zmq import jsonapi as json
37 38
38 39 from IPython.core.profiledir import ProfileDir
39 40
@@ -11,7 +11,8 b' import sys'
11 11 import tempfile
12 12
13 13 # System library imports
14 from zmq.utils import jsonapi as json
14 #from zmq.utils import jsonapi as json
15 from IPython.zmq import jsonapi as json
15 16
16 17 # IPython imports
17 18 from IPython.utils.localinterfaces import LOCALHOST
General Comments 0
You need to be logged in to leave comments. Login now