Show More
@@ -72,6 +72,60 b' def spin_first(f, self, *args, **kwargs):' | |||||
72 | # Classes |
|
72 | # Classes | |
73 | #-------------------------------------------------------------------------- |
|
73 | #-------------------------------------------------------------------------- | |
74 |
|
74 | |||
|
75 | ||||
|
76 | class ExecuteReply(object): | |||
|
77 | """wrapper for finished Execute results""" | |||
|
78 | def __init__(self, msg_id, content, metadata): | |||
|
79 | self.msg_id = msg_id | |||
|
80 | self._content = content | |||
|
81 | self.execution_count = content['execution_count'] | |||
|
82 | self.metadata = metadata | |||
|
83 | ||||
|
84 | def __getitem__(self, key): | |||
|
85 | return self.metadata[key] | |||
|
86 | ||||
|
87 | def __getattr__(self, key): | |||
|
88 | if key not in self.metadata: | |||
|
89 | raise AttributeError(key) | |||
|
90 | return self.metadata[key] | |||
|
91 | ||||
|
92 | def __repr__(self): | |||
|
93 | pyout = self.metadata['pyout'] or {} | |||
|
94 | text_out = pyout.get('text/plain', '') | |||
|
95 | if len(text_out) > 32: | |||
|
96 | text_out = text_out[:29] + '...' | |||
|
97 | ||||
|
98 | return "<ExecuteReply[%i]: %s>" % (self.execution_count, text_out) | |||
|
99 | ||||
|
100 | def _repr_html_(self): | |||
|
101 | pyout = self.metadata['pyout'] or {} | |||
|
102 | return pyout.get("text/html") | |||
|
103 | ||||
|
104 | def _repr_latex_(self): | |||
|
105 | pyout = self.metadata['pyout'] or {} | |||
|
106 | return pyout.get("text/latex") | |||
|
107 | ||||
|
108 | def _repr_json_(self): | |||
|
109 | pyout = self.metadata['pyout'] or {} | |||
|
110 | return pyout.get("application/json") | |||
|
111 | ||||
|
112 | def _repr_javascript_(self): | |||
|
113 | pyout = self.metadata['pyout'] or {} | |||
|
114 | return pyout.get("application/javascript") | |||
|
115 | ||||
|
116 | def _repr_png_(self): | |||
|
117 | pyout = self.metadata['pyout'] or {} | |||
|
118 | return pyout.get("image/png") | |||
|
119 | ||||
|
120 | def _repr_jpeg_(self): | |||
|
121 | pyout = self.metadata['pyout'] or {} | |||
|
122 | return pyout.get("image/jpeg") | |||
|
123 | ||||
|
124 | def _repr_svg_(self): | |||
|
125 | pyout = self.metadata['pyout'] or {} | |||
|
126 | return pyout.get("image/svg+xml") | |||
|
127 | ||||
|
128 | ||||
75 | class Metadata(dict): |
|
129 | class Metadata(dict): | |
76 | """Subclass of dict for initializing metadata values. |
|
130 | """Subclass of dict for initializing metadata values. | |
77 |
|
131 | |||
@@ -646,7 +700,7 b' class Client(HasTraits):' | |||||
646 |
|
700 | |||
647 | # construct result: |
|
701 | # construct result: | |
648 | if content['status'] == 'ok': |
|
702 | if content['status'] == 'ok': | |
649 | self.results[msg_id] = content |
|
703 | self.results[msg_id] = ExecuteReply(msg_id, content, md) | |
650 | elif content['status'] == 'aborted': |
|
704 | elif content['status'] == 'aborted': | |
651 | self.results[msg_id] = error.TaskAborted(msg_id) |
|
705 | self.results[msg_id] = error.TaskAborted(msg_id) | |
652 | elif content['status'] == 'resubmitted': |
|
706 | elif content['status'] == 'resubmitted': | |
@@ -878,14 +932,14 b' class Client(HasTraits):' | |||||
878 | """ |
|
932 | """ | |
879 | if self._notification_socket: |
|
933 | if self._notification_socket: | |
880 | self._flush_notifications() |
|
934 | self._flush_notifications() | |
|
935 | if self._iopub_socket: | |||
|
936 | self._flush_iopub(self._iopub_socket) | |||
881 | if self._mux_socket: |
|
937 | if self._mux_socket: | |
882 | self._flush_results(self._mux_socket) |
|
938 | self._flush_results(self._mux_socket) | |
883 | if self._task_socket: |
|
939 | if self._task_socket: | |
884 | self._flush_results(self._task_socket) |
|
940 | self._flush_results(self._task_socket) | |
885 | if self._control_socket: |
|
941 | if self._control_socket: | |
886 | self._flush_control(self._control_socket) |
|
942 | self._flush_control(self._control_socket) | |
887 | if self._iopub_socket: |
|
|||
888 | self._flush_iopub(self._iopub_socket) |
|
|||
889 | if self._query_socket: |
|
943 | if self._query_socket: | |
890 | self._flush_ignored_hub_replies() |
|
944 | self._flush_ignored_hub_replies() | |
891 |
|
945 |
General Comments 0
You need to be logged in to leave comments.
Login now