a
    ‹©lcS  ã                   @   s    d Z ddlZG dd„ deƒZdS )z Miscellaneous context managers.
é    Nc                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Úpreserve_keysa  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)]
    c                 G   s   || _ || _d S ©N)Ú
dictionaryÚkeys)Úselfr   r   © r   úR/var/www/html/django/DPS/env/lib/python3.9/site-packages/IPython/utils/contexts.pyÚ__init__%   s    zpreserve_keys.__init__c                 C   sJ   g }i }| j }| jD ]$}||v r.|| ||< q| |¡ q|| _|| _d S r   )r   r   ÚappendÚ	to_deleteÚ	to_update)r   r   r   ÚdÚkr   r   r   Ú	__enter__)   s    
zpreserve_keys.__enter__c                 G   s.   | j }| jD ]}| |d ¡ q| | j¡ d S r   )r   r   ÚpopÚupdater   )r   Úexc_infor   r   r   r   r   Ú__exit__8   s    
zpreserve_keys.__exit__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r      s   r   )r   ÚwarningsÚobjectr   r   r   r   r   Ú<module>   s   