/opt/imh-python/lib/python3.9/site-packages/IPython/utils
NameSizeModeActions
tests/-0755rm
__pycache__/-0755rm
capture.py51610644editdlrm
colorable.py7860644editdlrm
coloransi.py69720644editdlrm
contexts.py16190644editdlrm
daemonize.py2000644editdlrm
data.py10150644editdlrm
decorators.py26800644editdlrm
dir2.py22320644editdlrm
docs.py860644editdlrm
encoding.py28430644editdlrm
eventful.py1380644editdlrm
frame.py30480644editdlrm
generics.py7060644editdlrm
importstring.py10500644editdlrm
io.py46310644editdlrm
ipstruct.py118560644editdlrm
jsonutil.py1480644editdlrm
localinterfaces.py1690644editdlrm
log.py1230644editdlrm
module_paths.py23270644editdlrm
openpy.py34170644editdlrm
path.py119370644editdlrm
process.py18780644editdlrm
py3compat.py16020644editdlrm
PyColorize.py108750644editdlrm
sentinel.py4210644editdlrm
shimmodule.py26690644editdlrm
signatures.py4740644editdlrm
strdispatch.py18380644editdlrm
sysinfo.py43650644editdlrm
syspathcontext.py19520644editdlrm
tempdir.py18670644editdlrm
terminal.py32060644editdlrm
text.py244280644editdlrm
timing.py42750644editdlrm
tokenutil.py50830644editdlrm
traitlets.py1430644editdlrm
tz.py13800644editdlrm
ulinecache.py6840644editdlrm
version.py12230644editdlrm
wildcard.py46120644editdlrm
_process_cli.py20200644editdlrm
_process_common.py70030644editdlrm
_process_posix.py86660644editdlrm
_process_win32.py61320644editdlrm
_process_win32_controller.py213290644editdlrm
_sysinfo.py450644editdlrm
__init__.py00644editdlrm
Edit: /opt/imh-python/lib/python3.9/site-packages/IPython/utils/contexts.py (1619B)
# encoding: utf-8 """Miscellaneous context managers. """ import warnings # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. class preserve_keys(object): """Preserve a set of keys in a dictionary. Upon entering the context manager the current values of the keys will be saved. Upon exiting, the dictionary will be updated to restore the original value of the preserved keys. Preserved keys which did not exist when entering the context manager will be deleted. Examples -------- >>> d = {'a': 1, 'b': 2, 'c': 3} >>> with preserve_keys(d, 'b', 'c', 'd'): ... del d['a'] ... del d['b'] # will be reset to 2 ... d['c'] = None # will be reset to 3 ... d['d'] = 4 # will be deleted ... d['e'] = 5 ... print(sorted(d.items())) ... [('c', None), ('d', 4), ('e', 5)] >>> print(sorted(d.items())) [('b', 2), ('c', 3), ('e', 5)] """ def __init__(self, dictionary, *keys): self.dictionary = dictionary self.keys = keys def __enter__(self): # Actions to perform upon exiting. to_delete = [] to_update = {} d = self.dictionary for k in self.keys: if k in d: to_update[k] = d[k] else: to_delete.append(k) self.to_delete = to_delete self.to_update = to_update def __exit__(self, *exc_info): d = self.dictionary for k in self.to_delete: d.pop(k, None) d.update(self.to_update)