ó
&9_[c           @   sB   d  Z  d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s    Miscellaneous context managers.
iÿÿÿÿNt   preserve_keysc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s  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(   t
   dictionaryt   keys(   t   selfR   R   (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyt   __init__$   s    	c         C   si   g  } i  } |  j  } x; |  j D]0 } | | k rB | | | | <q | j | ƒ q W| |  _ | |  _ d  S(   N(   R   R   t   appendt	   to_deletet	   to_update(   R   R   R   t   dt   k(    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyt	   __enter__(   s    		c         G   sA   |  j  } x! |  j D] } | j | d  ƒ q W| j |  j ƒ d  S(   N(   R   R   t   popt   Nonet   updateR   (   R   t   exc_infoR   R	   (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyt   __exit__7   s    	(   t   __name__t
   __module__t   __doc__R   R
   R   (    (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyR    
   s   		t   NoOpContextc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s;   
    Deprecated
    
    Context manager that does nothing.c         C   s   t  j d t d d ƒd  S(   Ns,   NoOpContext is deprecated since IPython 5.0 t
   stackleveli   (   t   warningst   warnt   DeprecationWarning(   R   (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyR   E   s    	c         C   s   d  S(   N(    (   R   (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyR
   I   s    c         C   s   d  S(   N(    (   R   t   typet   valuet	   traceback(    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyR   J   s    (   R   R   R   R   R
   R   (    (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyR   ?   s   		(   R   R   t   objectR    R   (    (    (    s5   lib/python2.7/site-packages/IPython/utils/contexts.pyt   <module>   s   5