##// END OF EJS Templates
Merge pull request #5810 from minrk/clean-comm-msg...
Thomas Kluyver -
r16642:e0c5da18 merge
parent child Browse files
Show More
@@ -1,26 +1,16 b''
1 """Base class for a Comm"""
1 """Base class for a Comm"""
2
2
3 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Copyright (C) 2013 The IPython Development Team
4 # Distributed under the terms of the Modified BSD License.
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
13
5
14 import uuid
6 import uuid
15
7
16 from IPython.config import LoggingConfigurable
8 from IPython.config import LoggingConfigurable
17 from IPython.core.getipython import get_ipython
9 from IPython.core.getipython import get_ipython
18
10
11 from IPython.utils.jsonutil import json_clean
19 from IPython.utils.traitlets import Instance, Unicode, Bytes, Bool, Dict, Any
12 from IPython.utils.traitlets import Instance, Unicode, Bytes, Bool, Dict, Any
20
13
21 #-----------------------------------------------------------------------------
22 # Code
23 #-----------------------------------------------------------------------------
24
14
25 class Comm(LoggingConfigurable):
15 class Comm(LoggingConfigurable):
26
16
@@ -69,9 +59,10 b' class Comm(LoggingConfigurable):'
69 """Helper for sending a comm message on IOPub"""
59 """Helper for sending a comm message on IOPub"""
70 data = {} if data is None else data
60 data = {} if data is None else data
71 metadata = {} if metadata is None else metadata
61 metadata = {} if metadata is None else metadata
62 content = json_clean(dict(data=data, comm_id=self.comm_id, **keys))
72 self.session.send(self.iopub_socket, msg_type,
63 self.session.send(self.iopub_socket, msg_type,
73 dict(data=data, comm_id=self.comm_id, **keys),
64 content,
74 metadata=metadata,
65 metadata=json_clean(metadata),
75 parent=self.shell.get_parent(),
66 parent=self.shell.get_parent(),
76 ident=self.topic,
67 ident=self.topic,
77 )
68 )
@@ -67,7 +67,11 b' def squash_unicode(obj):'
67 #-----------------------------------------------------------------------------
67 #-----------------------------------------------------------------------------
68
68
69 # ISO8601-ify datetime objects
69 # ISO8601-ify datetime objects
70 json_packer = lambda obj: jsonapi.dumps(obj, default=date_default, ensure_ascii=False)
70 # allow unicode
71 # disallow nan, because it's not actually valid JSON
72 json_packer = lambda obj: jsonapi.dumps(obj, default=date_default,
73 ensure_ascii=False, allow_nan=False,
74 )
71 json_unpacker = lambda s: jsonapi.loads(s)
75 json_unpacker = lambda s: jsonapi.loads(s)
72
76
73 pickle_packer = lambda o: pickle.dumps(squash_dates(o),-1)
77 pickle_packer = lambda o: pickle.dumps(squash_dates(o),-1)
General Comments 0
You need to be logged in to leave comments. Login now