Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

json/jsonapi cleanup #1040

Closed
wants to merge 1 commit into from

2 participants

@minrk
Owner
  • never use zmq.utils.jsonapi when talking to files
  • catch decimal.Decimal returned by jsonlib in the parallel scheduler
  • remove IPython.zmq.jsonapi shim

See discussion in #1037 for details.

@minrk minrk json/jsonapi cleanup
* never use zmq.utils.jsonapi when talking to files
* catch decimal.Decimal returned by jsonlib in the parallel scheduler
* remove IPython.zmq.jsonapi shim
584513b
@fperez
Owner

This looks good, verified that the test suite now completes with jsonlib installed. I'd much rather take this approach than having in-house little hacks, so I'm merging it now (rebased to avoid recursive merge for just a single commit).

@fperez
Owner

Pushed as 3892cf3, closing. Thanks!

@fperez fperez closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 25, 2011
  1. @minrk

    json/jsonapi cleanup

    minrk authored
    * never use zmq.utils.jsonapi when talking to files
    * catch decimal.Decimal returned by jsonlib in the parallel scheduler
    * remove IPython.zmq.jsonapi shim
This page is out of date. Refresh to see the latest.
View
8 IPython/parallel/apps/ipcontrollerapp.py
@@ -23,6 +23,7 @@
from __future__ import with_statement
+import json
import os
import socket
import stat
@@ -34,11 +35,6 @@
from zmq.devices import ProcessMonitoredQueue
from zmq.log.handlers import PUBHandler
-# Note: use our own import to work around jsonlib api mismatch. When these
-# changes propagate to zmq, revert back to the following line instead:
-#from zmq.utils import jsonapi as json
-from IPython.zmq import jsonapi as json
-
from IPython.core.profiledir import ProfileDir
from IPython.parallel.apps.baseapp import (
@@ -214,7 +210,7 @@ def save_connection_dict(self, fname, cdict):
location = '127.0.0.1'
cdict['location'] = location
fname = os.path.join(self.profile_dir.security_dir, fname)
- with open(fname, 'wb') as f:
+ with open(fname, 'w') as f:
f.write(json.dumps(cdict, indent=2))
os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR)
View
4 IPython/parallel/controller/scheduler.py
@@ -359,7 +359,9 @@ def dispatch_submission(self, raw_msg):
# turn timeouts into datetime objects:
timeout = header.get('timeout', None)
if timeout:
- timeout = datetime.now() + timedelta(0,timeout,0)
+ # cast to float, because jsonlib returns floats as decimal.Decimal,
+ # which timedelta does not accept
+ timeout = datetime.now() + timedelta(0,float(timeout),0)
args = [raw_msg, targets, after, follow, timeout]
View
8 IPython/zmq/entry_point.py
@@ -4,6 +4,7 @@
# Standard library imports.
import atexit
+import json
import os
import socket
from subprocess import Popen, PIPE
@@ -12,11 +13,6 @@
# System library imports
-# Note: use our own import to work around jsonlib api mismatch. When these
-# changes propagate to zmq, revert back to the following line instead:
-#from zmq.utils import jsonapi as json
-from IPython.zmq import jsonapi as json
-
# IPython imports
from IPython.utils.localinterfaces import LOCALHOST
from IPython.utils.py3compat import bytes_to_str
@@ -86,7 +82,7 @@ def write_connection_file(fname=None, shell_port=0, iopub_port=0, stdin_port=0,
cfg['ip'] = ip
cfg['key'] = bytes_to_str(key)
- with open(fname, 'wb') as f:
+ with open(fname, 'w') as f:
f.write(json.dumps(cfg, indent=2))
return fname, cfg
View
36 IPython/zmq/jsonapi.py
@@ -1,36 +0,0 @@
-"""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)
Something went wrong with that request. Please try again.