ó
è¾bc           @   s‰   d  Z  d d l Z d d l m Z d d l m Z d d d g Z d e f d	 „  ƒ  YZ d
 „  Z	 e	 d „  ƒ Z
 d e f d „  ƒ  YZ d S(   s4   Utilities for with-statement contexts.  See PEP 343.iÿÿÿÿN(   t   wraps(   t   warnt   contextmanagert   nestedt   closingt   GeneratorContextManagerc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s%   Helper for @contextmanager decorator.c         C   s   | |  _  d  S(   N(   t   gen(   t   selfR   (    (    s    /usr/lib/python2.7/contextlib.pyt   __init__   s    c         C   s5   y |  j  j ƒ  SWn t k
 r0 t d ƒ ‚ n Xd  S(   Ns   generator didn't yield(   R   t   nextt   StopIterationt   RuntimeError(   R   (    (    s    /usr/lib/python2.7/contextlib.pyt	   __enter__   s    c         C   sÂ   | d  k rA y |  j j ƒ  Wn t k
 r1 d  SXt d ƒ ‚ n} | d  k rY | ƒ  } n  y& |  j j | | | ƒ t d ƒ ‚ Wn< t k
 r› } | | k	 St j ƒ  d | k	 r¾ ‚  q¾ n Xd  S(   Ns   generator didn't stops#   generator didn't stop after throw()i   (   t   NoneR   R	   R
   R   t   throwt   syst   exc_info(   R   t   typet   valuet	   tracebackt   exc(    (    s    /usr/lib/python2.7/contextlib.pyt   __exit__   s     
(   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s    /usr/lib/python2.7/contextlib.pyR   	   s   		c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   sÜ  @contextmanager decorator.

    Typical usage:

        @contextmanager
        def some_generator(<arguments>):
            <setup>
            try:
                yield <value>
            finally:
                <cleanup>

    This makes this:

        with some_generator(<arguments>) as <variable>:
            <body>

    equivalent to this:

        <setup>
        try:
            <variable> = <value>
            <body>
        finally:
            <cleanup>

    c             s   t  ˆ  |  | Ž  ƒ S(   N(   R   (   t   argst   kwds(   t   func(    s    /usr/lib/python2.7/contextlib.pyt   helperR   s    (   R    (   R   R   (    (   R   s    /usr/lib/python2.7/contextlib.pyR   6   s    c          g   sü   t  d t d ƒ g  } g  } d } zc yI x= |  D]5 } | j } | j } | j | ƒ  ƒ | j | ƒ q/ W| VWn t j ƒ  } n XWd xE | rÏ | j ƒ  } y | | Œ  rµ d } n  Wq‹ t j ƒ  } q‹ Xq‹ W| d	 k r÷ | d | d | d ‚ n  Xd S(
   sµ  Combine multiple context managers into a single nested context manager.

   This function has been deprecated in favour of the multiple manager form
   of the with statement.

   The one advantage of this function over the multiple manager form of the
   with statement is that argument unpacking allows it to be
   used with a variable number of context managers as follows:

      with nested(*managers):
          do_something()

    s>   With-statements now directly support multiple context managersi   Ni    i   i   (   NNN(   NNN(   NNN(	   R   t   DeprecationWarningR   R   R   t   appendR   R   t   pop(   t   managerst   exitst   varsR   t   mgrt   exitt   enter(    (    s    /usr/lib/python2.7/contextlib.pyR   X   s0    
 				c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s2  Context to automatically close something at the end of a block.

    Code like this:

        with closing(<module>.open(<arguments>)) as f:
            <block>

    is equivalent to this:

        f = <module>.open(<arguments>)
        try:
            <block>
        finally:
            f.close()

    c         C   s   | |  _  d  S(   N(   t   thing(   R   R&   (    (    s    /usr/lib/python2.7/contextlib.pyR   •   s    c         C   s   |  j  S(   N(   R&   (   R   (    (    s    /usr/lib/python2.7/contextlib.pyR   —   s    c         G   s   |  j  j ƒ  d  S(   N(   R&   t   close(   R   R   (    (    s    /usr/lib/python2.7/contextlib.pyR   ™   s    (   R   R   R   R   R   R   (    (    (    s    /usr/lib/python2.7/contextlib.pyR   „   s   		(   R   R   t	   functoolsR    t   warningsR   t   __all__t   objectR   R   R   R   (    (    (    s    /usr/lib/python2.7/contextlib.pyt   <module>   s   -	",