Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/IPython/core/payload.py: 40%
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# -*- coding: utf-8 -*-
2"""Payload system for IPython.
4Authors:
6* Fernando Perez
7* Brian Granger
8"""
10#-----------------------------------------------------------------------------
11# Copyright (C) 2008-2011 The IPython Development Team
12#
13# Distributed under the terms of the BSD License. The full license is in
14# the file COPYING, distributed as part of this software.
15#-----------------------------------------------------------------------------
17#-----------------------------------------------------------------------------
18# Imports
19#-----------------------------------------------------------------------------
21from traitlets.config.configurable import Configurable
22from traitlets import List
24#-----------------------------------------------------------------------------
25# Main payload class
26#-----------------------------------------------------------------------------
28class PayloadManager(Configurable):
29 _payload: List = List([])
31 def write_payload(self, data, single=True):
32 """Include or update the specified `data` payload in the PayloadManager.
34 If a previous payload with the same source exists and `single` is True,
35 it will be overwritten with the new one.
36 """
38 if not isinstance(data, dict):
39 raise TypeError('Each payload write must be a dict, got: %r' % data)
41 if single and 'source' in data:
42 source = data['source']
43 for i, pl in enumerate(self._payload):
44 if 'source' in pl and pl['source'] == source:
45 self._payload[i] = data
46 return
48 self._payload.append(data)
50 def read_payload(self):
51 return self._payload
53 def clear_payload(self):
54 self._payload = []