Ñò
mÈKc           @   sy   d  Z  d d k Z d d k l 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   wrapst   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.6/contextlib.pyt   __init__   s    c         C   s7   y |  i  i ƒ  SWn t j
 o t d ƒ ‚ n Xd  S(   Ns   generator didn't yield(   R   t   nextt   StopIterationt   RuntimeError(   R   (    (    s    /usr/lib/python2.6/contextlib.pyt	   __enter__   s    c         C   sÌ   | d  j o8 y |  i i ƒ  Wn t j
 o d  SXt d ƒ ‚ n„ | d  j o | ƒ  } n y& |  i i | | | ƒ t d ƒ ‚ Wn@ t j
 o } | | j	 St i ƒ  d | j	 o ‚  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.6/contextlib.pyt   __exit__   s     (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s    /usr/lib/python2.6/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.6/contextlib.pyt   helperQ   s    (   R    (   R   R   (    (   R   s    /usr/lib/python2.6/contextlib.pyR   5   s    c          g   sò   g  } g  } d } zc yI x= |  D]5 } | i } | i } | i | ƒ  ƒ | i | ƒ q W| VWn t i ƒ  } n XWd xI | oA | i ƒ  } y | | Œ  o
 d } n Wq{ t i ƒ  } q{ Xq{ W| d j o | d | d | d ‚ n Xd S(   s  Support multiple context managers in a single with-statement.

    Code like this:

        with nested(A, B, C) as (X, Y, Z):
            <body>

    is equivalent to this:

        with A as X:
            with B as Y:
                with C as Z:
                    <body>

    Ni    i   i   (   NNN(   NNN(   NNN(   R   R   R   t   appendR   R   t   pop(   t   managerst   exitst   varsR   t   mgrt   exitt   enter(    (    s    /usr/lib/python2.6/contextlib.pyR   W   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.6/contextlib.pyR   ”   s    c         C   s   |  i  S(   N(   R$   (   R   (    (    s    /usr/lib/python2.6/contextlib.pyR   –   s    c         G   s   |  i  i ƒ  d  S(   N(   R$   t   close(   R   R   (    (    s    /usr/lib/python2.6/contextlib.pyR   ˜   s    (   R   R   R   R   R   R   (    (    (    s    /usr/lib/python2.6/contextlib.pyR   ƒ   s   		(
   R   R   t	   functoolsR    t   __all__t   objectR   R   R   R   (    (    (    s    /usr/lib/python2.6/contextlib.pyt   <module>   s   -	",