ó
î%![c           @   sc   d  Z  d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   sI   Various context related utilities, including inference and call contexts.iÿÿÿÿNt   InferenceContextc           B   sY   e  Z d  Z d Z d d d „ Z d „  Z d „  Z d	 „  Z e	 j
 d
 „  ƒ Z d „  Z RS(   s›   Provide context for inference

    Store already inferred nodes to save time
    Account for already visited nodes to infinite stop infinite recursion
    t   patht
   lookupnamet   callcontextt	   boundnodet   inferredc         C   s@   | p t  ƒ  |  _ d  |  _ d  |  _ d  |  _ | p6 i  |  _ d  S(   N(   t   setR   t   NoneR   R   R   R   (   t   selfR   R   (    (    s.   lib/python2.7/site-packages/astroid/context.pyt   __init__   s    			c         C   s<   |  j  } | | f |  j k r" t S|  j j | | f ƒ t S(   sâ   Push node into inference path

        :return: True if node is already in context path else False
        :rtype: bool

        Allows one to see if the given node has already
        been looked at for this inference context(   R   R   t   Truet   addt   False(   R   t   nodet   name(    (    s.   lib/python2.7/site-packages/astroid/context.pyt   push'   s
    	c         C   s=   t  t j |  j ƒ d |  j ƒ} |  j | _ |  j | _ | S(   sÐ   Clone inference path

        For example, each side of a binary operation (BinOp)
        starts with the same context but diverge as each side is inferred
        so the InferenceContext will need be clonedR   (   R    t   copyR   R   R   R   (   R   t   clone(    (    s.   lib/python2.7/site-packages/astroid/context.pyR   6   s    !c         c   s@   g  } x  | D] } | j  | ƒ | Vq Wt | ƒ |  j | <d S(   sR   Cache result of generator into dictionary

        Used to cache inference resultsN(   t   appendt   tupleR   (   R   t   keyt	   generatort   resultst   result(    (    s.   lib/python2.7/site-packages/astroid/context.pyt   cache_generatorB   s
    	c         c   s!   t  |  j ƒ } d  V| |  _ d  S(   N(   R   R   (   R   R   (    (    s.   lib/python2.7/site-packages/astroid/context.pyt   restore_pathM   s    c            s9   ‡  f d †  ˆ  j  Dƒ } d t ˆ  ƒ j d j | ƒ f S(   Nc      	   3   sA   |  ]7 } d  | t  j t ˆ  | ƒ d d t | ƒ ƒf Vq d S(   s   %s=%st   widthiP   N(   t   pprintt   pformatt   getattrt   len(   t   .0t   field(   R   (    s.   lib/python2.7/site-packages/astroid/context.pys	   <genexpr>T   s   s   %s(%s)s   ,
    (   t	   __slots__t   typet   __name__t   join(   R   t   state(    (   R   s.   lib/python2.7/site-packages/astroid/context.pyt   __str__S   s    (   R   R   R   R   R   N(   R#   t
   __module__t   __doc__R!   R   R	   R   R   R   t
   contextlibt   contextmanagerR   R&   (    (    (    s.   lib/python2.7/site-packages/astroid/context.pyR       s   			t   CallContextc           B   s    e  Z d  Z d Z d d „ Z RS(   s"   Holds information for a call site.t   argst   keywordsc         C   sJ   | |  _  | r7 g  | D] } | j | j f ^ q } n g  } | |  _ d  S(   N(   R,   t   argt   valueR-   (   R   R,   R-   R.   (    (    s.   lib/python2.7/site-packages/astroid/context.pyR	   _   s
    	((   R,   R-   N(   R#   R'   R(   R!   R   R	   (    (    (    s.   lib/python2.7/site-packages/astroid/context.pyR+   Z   s   c         C   s   |  d  k	 r |  j ƒ  St ƒ  S(   N(   R   R   R    (   t   context(    (    s.   lib/python2.7/site-packages/astroid/context.pyt   copy_contexth   s    
(   R(   R)   R   R   t   objectR    R+   R1   (    (    (    s.   lib/python2.7/site-packages/astroid/context.pyt   <module>   s   L