ó
î%![c           @   s§   d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m Z e j d    Z	 d e
 f d     YZ d	   Z e j d
    Z e j d    Z d S(   s)    A few useful function/method decorators.i˙˙˙˙N(   t   context(   t
   exceptions(   t   utilc         C   sj   t  | d d  } | d k r. i  | _ } n  y | |  SWn) t k
 re |  | |   | |  <} | SXd S(   s>   Simple decorator to cache result of method calls without args.t   __cacheN(   t   getattrt   NoneR   t   KeyError(   t   funct   instancet   argst   kwargst   cachet   result(    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   cached   s    t   cachedpropertyc           B   s8   e  Z d  Z d Z d   Z e d    Z d d  Z RS(   s´   Provides a cached property equivalent to the stacking of
    @cached and @property, but more efficient.

    After first usage, the <property_name> becomes part of the object's
    __dict__. Doing:

      del obj.<property_name> empties the cache.

    Idea taken from the pyramid_ framework and the mercurial_ project.

    .. _pyramid: http://pypi.python.org/pypi/pyramid
    .. _mercurial: http://pypi.python.org/pypi/Mercurial
    t   wrappedc         C   sC   y | j  Wn( t k
 r5 t j t d |   n X| |  _ d  S(   Ns!   %s must have a __name__ attribute(   t   __name__t   AttributeErrorR   t   reraiset	   TypeErrorR   (   t   selfR   (    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   __init__0   s    c         C   s-   t  |  j d d   } d | r( d | n d S(   Nt   __doc__s+   <wrapped by the cachedproperty decorator>%ss   
%st    (   R   R   R   (   R   t   doc(    (    s1   lib/python2.7/site-packages/astroid/decorators.pyR   8   s    c         C   s9   | d  k r |  S|  j |  } t | |  j j |  | S(   N(   R   R   t   setattrR   (   R   t   instt   objtypet   val(    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   __get__>   s
    (   R   N(   R   t
   __module__R   t	   __slots__R   t   propertyR   R   (    (    (    s1   lib/python2.7/site-packages/astroid/decorators.pyR       s
   	c         C   s"   t  j |   d |  d   } | S(   sĂ   return the given infer function wrapped to handle the path

    Used to stop inference if the node has already been looked
    at for a given `InferenceContext` to prevent infinite recursion
    c   	      {   sę   | d k r t j   } n  | j |   r. d St   } | |  | |  } yb x[ t rŠ t |  } | j j d k r | j	 } n | } | | k rO | V| j
 |  qO qO WWn8 t k
 rĺ } | j rÜ t | j d   qć t  n Xd S(   s!   wrapper function handling contextNt   Instancei    (   R   t
   contextmodt   InferenceContextt   pusht   sett   Truet   nextt	   __class__R   t   _proxiedt   addt   StopIterationR	   (	   t   nodeR    t   _funcR
   t   yieldedt	   generatort   rest   arest   error(    (    s1   lib/python2.7/site-packages/astroid/decorators.pyR   M   s&    			N(   t	   functoolst   wrapsR   (   R   R   (    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   path_wrapperF   s    c         c   s@   t  } x" |  | |   D] } t } | Vq W| s< t j Vn  d  S(   N(   t   FalseR&   R   t   Uninferable(   R   R   R	   R
   t   inferredR,   (    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   yes_if_nothing_inferredm   s    	c         c   s   t  } y1 |  | |   } x t r5 t |  Vt } q WWnM t k
 r } | s | j rq t j | j d    q t j d   q n Xd S(   sŽ   All generators wrapped with raise_if_nothing_inferred *must*
    explicitly raise StopIteration with information to create an
    appropriate structured InferenceError.

    i    s3   StopIteration raised without any error information.N(   R6   R&   R'   R+   R	   R   t   InferenceError(   R   R   R	   R
   R8   R/   R2   (    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   raise_if_nothing_inferredw   s    		(   R   R3   t   wraptt   astroidR    R"   R   R   t	   decoratorR   t   objectR   R5   R9   R;   (    (    (    s1   lib/python2.7/site-packages/astroid/decorators.pyt   <module>   s   &	'
