Format: application/x-python-code
1 o
2
3 ��hS � @ s d Z ddlZG dd� de�ZdS )z Miscellaneous context managers.
4 � Nc @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �
5 preserve_keysa
6 Preserve a set of keys in a dictionary.
7
8 Upon entering the context manager the current values of the keys
9 will be saved. Upon exiting, the dictionary will be updated to
10 restore the original value of the preserved keys. Preserved keys
11 which did not exist when entering the context manager will be
12 deleted.
13
14 Examples
15 --------
16
17 >>> d = {'a': 1, 'b': 2, 'c': 3}
18 >>> with preserve_keys(d, 'b', 'c', 'd'):
19 ... del d['a']
20 ... del d['b'] # will be reset to 2
21 ... d['c'] = None # will be reset to 3
22 ... d['d'] = 4 # will be deleted
23 ... d['e'] = 5
24 ... print(sorted(d.items()))
25 ...
26 [('c', None), ('d', 4), ('e', 5)]
27 >>> print(sorted(d.items()))
28 [('b', 2), ('c', 3), ('e', 5)]
29 c G s || _ || _d S �N)�
30 dictionary�keys)�selfr r � r �Lc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/contexts.py�__init__% s
31 zpreserve_keys.__init__c C sJ g }i }| j }| jD ]}||v r|| ||<