ó
’›V]c           @   s|   d  Z  d d l Z d d l m Z d d l m Z d d l m Z i  a d „  Z	 e
 d „ Z d „  Z d	 „  Z d
 „  Z d S(   s7  
This caching is very important for speed and memory optimizations. There's
nothing really spectacular, just some decorators. The following cache types are
available:

- ``time_cache`` can be used to cache something for just a limited time span,
  which can be useful if there's user interaction and the user cannot react
  faster than a certain time.

This module is one of the reasons why |jedi| is not thread-safe. As you can see
there are global variables, which are holding the cache information. Some of
these variables are being cleaned after every API usage.
iÿÿÿÿN(   t   wraps(   t   settings(   t   parser_cachec            s#   d ˆ  j  ‰ ‡  ‡ f d †  } | S(   sn  
    Decorator for methods::

        class A(object):
            def x(self):
                if self._x:
                    self._x = 10
                return self._x

    Becomes::

        class A(object):
            @underscore_memoization
            def x(self):
                return 10

    A now has an attribute ``_x`` written by this decorator.
    t   _c            sF   y t  |  ˆ ƒ SWn. t k
 rA ˆ  |  ƒ } t |  ˆ | ƒ | SXd  S(   N(   t   getattrt   AttributeErrort   setattr(   t   selft   result(   t   funct   name(    s)   lib/python2.7/site-packages/jedi/cache.pyt   wrapper,   s    (   t   __name__(   R	   R   (    (   R	   R
   s)   lib/python2.7/site-packages/jedi/cache.pyt   underscore_memoization   s    c         C   s”   |  r4 x t  j ƒ  D] } | j ƒ  q Wt j ƒ  n\ xY t  j ƒ  D]K } xB t | j ƒ  ƒ D]. \ } \ } } | t j ƒ  k  rZ | | =qZ qZ WqA Wd S(   sê    Jedi caches many things, that should be completed after each completion
    finishes.

    :param delete_all: Deletes also the cache that is normally not deleted,
        like parser cache, which is important for faster parsing.
    N(   t   _time_cachest   valuest   clearR   t   listt   itemst   time(   t
   delete_allt   cachet   tct   keyt   tt   value(    (    s)   lib/python2.7/site-packages/jedi/cache.pyt   clear_time_caches7   s    	%c            s   ‡  f d †  } | S(   s\  
    This decorator works as follows: Call it with a setting and after that
    use the function with a callable that returns the key.
    But: This function is only called if the key is not available. After a
    certain amount of time (`time_add_setting`) the cache is invalid.

    If the given key is None, the function will not be cached.
    c            s)   i  ‰  ˆ  t  ˆ <‡  ‡ ‡ f d †  } | S(   Nc             s¡   ˆ |  | Ž  } t  | ƒ } y* ˆ  | \ } } | t j ƒ  k rD | SWn t k
 rX n Xt  | ƒ } t t ˆ ƒ } | d  k	 r t j ƒ  | | f ˆ  | <n  | S(   N(   t   nextR   t   KeyErrorR   R   t   None(   t   argst   kwargst	   generatorR   t   expiryR   t   time_add(   t   dctt   key_funct   time_add_setting(    s)   lib/python2.7/site-packages/jedi/cache.pyR   [   s    (   R   (   R$   R   (   R%   (   R#   R$   s)   lib/python2.7/site-packages/jedi/cache.pyt   _tempW   s    
(    (   R%   R&   (    (   R%   s)   lib/python2.7/site-packages/jedi/cache.pyt   call_signature_time_cacheN   s    	c            s   ‡  f d †  } | S(   Nc            s=   i  ‰  t  ˆ ƒ ‡  ‡ ‡ f d †  ƒ } ‡  f d †  | _ | S(   Nc             sƒ   |  t  | j ƒ  ƒ f } y. ˆ  | \ } } t j ƒ  | ˆ k  rE | SWn t k
 rY n Xˆ |  | Ž  } t j ƒ  | f ˆ  | <| S(   N(   t	   frozensetR   R   R   (   R   R   R   t   createdR   (   R   R	   t   seconds(    s)   lib/python2.7/site-packages/jedi/cache.pyR   r   s    c              s
   ˆ  j  ƒ  S(   N(   R   (    (   R   (    s)   lib/python2.7/site-packages/jedi/cache.pyt   <lambda>   t    (   R    t   clear_cache(   R	   R   (   R*   (   R   R	   s)   lib/python2.7/site-packages/jedi/cache.pyt	   decoratoro   s    !(    (   R*   R.   (    (   R*   s)   lib/python2.7/site-packages/jedi/cache.pyt
   time_cachen   s    c            s   t  ˆ  ƒ ‡  f d †  ƒ } | S(   s   A normal memoize function.c            s€   |  j  j d i  ƒ } | j ˆ  i  ƒ } | t | j ƒ  ƒ f } y | | SWn. t k
 r{ ˆ  |  | | Ž } | | | <| SXd  S(   Nt   _memoize_method_dct(   t   __dict__t
   setdefaultR(   R   R   (   R   R   R   t
   cache_dictR#   R   R   (   t   method(    s)   lib/python2.7/site-packages/jedi/cache.pyR   ‡   s    
(   R    (   R4   R   (    (   R4   s)   lib/python2.7/site-packages/jedi/cache.pyt   memoize_method…   s    (   t   __doc__R   t	   functoolsR    t   jediR   t   parso.cacheR   R   R   t   FalseR   R'   R/   R5   (    (    (    s)   lib/python2.7/site-packages/jedi/cache.pyt   <module>   s   	 	 	