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