##// END OF EJS Templates
move rekey to jsonutil from parallel.util...
MinRK -
Show More
@@ -28,6 +28,7 b' pjoin = os.path.join'
28 28 import zmq
29 29 # from zmq.eventloop import ioloop, zmqstream
30 30
31 from IPython.utils.jsonutil import rekey
31 32 from IPython.utils.path import get_ipython_dir
32 33 from IPython.utils.traitlets import (HasTraits, Int, Instance, Unicode,
33 34 Dict, List, Bool, Set)
@@ -1247,7 +1248,7 b' class Client(HasTraits):'
1247 1248 status = content.pop('status')
1248 1249 if status != 'ok':
1249 1250 raise self._unwrap_exception(content)
1250 content = util.rekey(content)
1251 content = rekey(content)
1251 1252 if isinstance(targets, int):
1252 1253 return content[targets]
1253 1254 else:
@@ -182,29 +182,6 b' def disambiguate_url(url, location=None):'
182 182
183 183 return "%s://%s:%s"%(proto,ip,port)
184 184
185
186 def rekey(dikt):
187 """Rekey a dict that has been forced to use str keys where there should be
188 ints by json. This belongs in the jsonutil added by fperez."""
189 for k in dikt.iterkeys():
190 if isinstance(k, str):
191 ik=fk=None
192 try:
193 ik = int(k)
194 except ValueError:
195 try:
196 fk = float(k)
197 except ValueError:
198 continue
199 if ik is not None:
200 nk = ik
201 else:
202 nk = fk
203 if nk in dikt:
204 raise KeyError("already have key %r"%nk)
205 dikt[nk] = dikt.pop(k)
206 return dikt
207
208 185 def serialize_object(obj, threshold=64e-6):
209 186 """Serialize an object into a list of sendable buffers.
210 187
@@ -27,6 +27,29 b' ISO8601_PAT=re.compile(r"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d+$")'
27 27 # Classes and functions
28 28 #-----------------------------------------------------------------------------
29 29
30 def rekey(dikt):
31 """Rekey a dict that has been forced to use str keys where there should be
32 ints by json."""
33 for k in dikt.iterkeys():
34 if isinstance(k, basestring):
35 ik=fk=None
36 try:
37 ik = int(k)
38 except ValueError:
39 try:
40 fk = float(k)
41 except ValueError:
42 continue
43 if ik is not None:
44 nk = ik
45 else:
46 nk = fk
47 if nk in dikt:
48 raise KeyError("already have key %r"%nk)
49 dikt[nk] = dikt.pop(k)
50 return dikt
51
52
30 53 def extract_dates(obj):
31 54 """extract ISO8601 dates from unpacked JSON"""
32 55 if isinstance(obj, dict):
General Comments 0
You need to be logged in to leave comments. Login now