Show More
@@ -1,55 +1,55 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Payload system for IPython. |
|
3 | 3 | |
|
4 | 4 | Authors: |
|
5 | 5 | |
|
6 | 6 | * Fernando Perez |
|
7 | 7 | * Brian Granger |
|
8 | 8 | """ |
|
9 | 9 | |
|
10 | 10 | #----------------------------------------------------------------------------- |
|
11 | 11 | # Copyright (C) 2008-2011 The IPython Development Team |
|
12 | 12 | # |
|
13 | 13 | # Distributed under the terms of the BSD License. The full license is in |
|
14 | 14 | # the file COPYING, distributed as part of this software. |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | # Imports |
|
19 | 19 | #----------------------------------------------------------------------------- |
|
20 | 20 | |
|
21 | 21 | from IPython.config.configurable import Configurable |
|
22 | 22 | from IPython.utils.traitlets import List |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------------------------------------------- |
|
25 | 25 | # Main payload class |
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | class PayloadManager(Configurable): |
|
29 | 29 | |
|
30 | 30 | _payload = List([]) |
|
31 | 31 | |
|
32 | 32 | def write_payload(self, data, single=True): |
|
33 | 33 | """Include or update the specified `data` payload in the PayloadManager. |
|
34 | 34 | |
|
35 |
If a previous payload with the same source |
|
|
36 |
|
|
|
35 | If a previous payload with the same source exists and `single` is True, | |
|
36 | it will be overwritten with the new one. | |
|
37 | 37 | """ |
|
38 | 38 | |
|
39 | 39 | if not isinstance(data, dict): |
|
40 | 40 | raise TypeError('Each payload write must be a dict, got: %r' % data) |
|
41 | 41 | |
|
42 | 42 | if single and 'source' in data: |
|
43 | 43 | source = data['source'] |
|
44 | 44 | for i, pl in enumerate(self._payload): |
|
45 | 45 | if 'source' in pl and pl['source'] == source: |
|
46 | 46 | self._payload[i] = data |
|
47 | 47 | return |
|
48 | 48 | |
|
49 | 49 | self._payload.append(data) |
|
50 | 50 | |
|
51 | 51 | def read_payload(self): |
|
52 | 52 | return self._payload |
|
53 | 53 | |
|
54 | 54 | def clear_payload(self): |
|
55 | 55 | self._payload = [] |
General Comments 0
You need to be logged in to leave comments.
Login now