Format: application/x-python-code
⬇ Download File (1.8 KB)
   1  o
   2  
   3  ��hS�@s dZddlZGdd�de�ZdS)z Miscellaneous context managers.
   4  �Nc@s(eZdZdZdd�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      cGs||_||_dS�N)�
  30  dictionary�keys)�selfrr�r�Lc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/contexts.py�__init__%s
  31  zpreserve_keys.__init__cCsJg}i}|j}|jD]}||vr||||<q
  32  |�|�q
  33  ||_||_dSr)rr�append�	to_delete�	to_update)rrr�d�krrr�	__enter__)s
  34  
  35  zpreserve_keys.__enter__cGs.|j}|jD]}|�|d�q|�|j�dSr)rr�pop�updater)r�exc_infor
  36  rrrr�__exit__8s
  37  zpreserve_keys.__exit__N)�__name__�
  38  __module__�__qualname__�__doc__r	rrrrrrrs
  39  r)r�warnings�objectrrrrr�<module>s