ó
’›V]c           @   s~   d  Z  d d l m Z e ƒ  Z e ƒ  Z e e e d „ Z e d „ Z e d „ Z	 d „  Z
 d e f d „  ƒ  YZ d	 „  Z d
 S(   s³   
- the popular ``_memoize_default`` works like a typical memoize and returns the
  default otherwise.
- ``CachedMetaClass`` uses ``_memoize_default`` to do the same with classes.
iÿÿÿÿ(   t   debugc            s   ‡  ‡ ‡ f d †  } | S(   sO   This is a typical memoization decorator, BUT there is one difference:
    To prevent recursion it sets defaults.

    Preventing recursion is in this case the much bigger use than speed. I
    don't think, that there is a big speed difference, but there are many cases
    where recursion could happen (think about a = b; b = a).
    c            s   ‡ ‡ ‡  ‡ f d †  } | S(   Nc            sÐ   ˆ r |  j  } n" ˆ r( | d j  } n |  j j  } y | ˆ } Wn t k
 rc i  | ˆ <} n X|  | t | j ƒ  ƒ f } | | k r“ | | Sˆ  t k	 r¬ ˆ  | | <n  ˆ |  | | Ž } | | | <| Sd  S(   Ni    (   t   memoize_cachet	   evaluatort   KeyErrort	   frozensett   itemst   _NO_DEFAULT(   t   objt   argst   kwargst   cachet   memot   keyt   rv(   t   defaultt   evaluator_is_first_argt   functiont   second_arg_is_evaluator(    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   wrapper   s"    
(    (   R   R   (   R   R   R   (   R   s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   func   s    (    (   R   R   R   R   (    (   R   R   R   s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   _memoize_default   s    c            s   ‡  f d †  } | S(   Nc            s   t  d ˆ  d t ƒ |  ƒ S(   NR   R   (   R   t   True(   R   (   R   (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt	   decorator3   s    (    (   R   R   (    (   R   s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   evaluator_function_cache2   s    c            s   ‡  f d †  } | S(   Nc            s   t  d ˆ  ƒ |  ƒ S(   NR   (   R   (   R   (   R   (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyR   :   s    (    (   R   R   (    (   R   s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   evaluator_method_cache9   s    c          C   s   d „  }  |  S(   Nc         S   s   t  d t ƒ |  ƒ S(   NR   (   R   R   (   t   call(    (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyR   A   s    (    (   R   (    (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   evaluator_as_method_param_cache@   s    	t   CachedMetaClassc           B   s    e  Z d  Z e ƒ  d „  ƒ Z RS(   sÞ   
    This is basically almost the same than the decorator above, it just caches
    class initializations. Either you do it this way or with decorators, but
    with decorators you lose class access (isinstance, etc).
    c         O   s   t  t |  ƒ j | | Ž  S(   N(   t   superR   t   __call__(   t   selfR   R	   (    (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyR   M   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyR   G   s   c          C   s   d „  }  |  S(   sœ   
    This is a special memoizer. It memoizes generators and also checks for
    recursion errors and returns no further iterator elemends in that case.
    c            s   ‡  f d †  } | S(   Nc   
      ?   sG  |  j  j } y | ˆ  } Wn t k
 r; i  | ˆ  <} n X|  | t | j ƒ  ƒ f } | | k rv | | \ } } n( ˆ  |  | | Ž } g  } | | f | | <d } xœ t rBy/ | | }	 |	 t k rÛ t j d |  ƒ d  SWnQ t	 k
 r/| j
 t ƒ t | d  ƒ }	 |	 d  k r"| j ƒ  d  S|	 | d <n X|	 V| d 7} q§ Wd  S(   Ni    s"   Found a generator recursion for %siÿÿÿÿi   (   R   R   R   R   R   R   t   _RECURSION_SENTINELR    t   warningt
   IndexErrort   appendt   nextt   Nonet   pop(
   R   R   R	   R
   R   R   t   actual_generatort
   cached_lstt   it   next_element(   R   (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyR   X   s6    	

(    (   R   R   (    (   R   s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyR   W   s    !(    (   R   (    (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt    evaluator_method_generator_cacheR   s    	$N(   R!   t   jediR    t   objectR   R"   t   FalseR   R   R   R   t   typeR   R-   (    (    (    s2   lib/python2.7/site-packages/jedi/evaluate/cache.pyt   <module>   s   		%	