Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/IPython/core/payload.py: 42%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Payload system for IPython.
3Authors:
5* Fernando Perez
6* Brian Granger
7"""
9#-----------------------------------------------------------------------------
10# Copyright (C) 2008-2011 The IPython Development Team
11#
12# Distributed under the terms of the BSD License. The full license is in
13# the file COPYING, distributed as part of this software.
14#-----------------------------------------------------------------------------
16#-----------------------------------------------------------------------------
17# Imports
18#-----------------------------------------------------------------------------
20from traitlets.config.configurable import Configurable
21from traitlets import List
23#-----------------------------------------------------------------------------
24# Main payload class
25#-----------------------------------------------------------------------------
27class PayloadManager(Configurable):
28 _payload: List = List([])
30 def write_payload(self, data, single=True):
31 """Include or update the specified `data` payload in the PayloadManager.
33 If a previous payload with the same source exists and `single` is True,
34 it will be overwritten with the new one.
35 """
37 if not isinstance(data, dict):
38 raise TypeError('Each payload write must be a dict, got: %r' % data)
40 if single and 'source' in data:
41 source = data['source']
42 for i, pl in enumerate(self._payload):
43 if 'source' in pl and pl['source'] == source:
44 self._payload[i] = data
45 return
47 self._payload.append(data)
49 def read_payload(self):
50 return self._payload
52 def clear_payload(self):
53 self._payload = []