ó
±xYc           @  sr   d  d l  m Z d  d l m Z d  d l m Z d Z d e f d „  ƒ  YZ d	 e	 f d
 „  ƒ  YZ
 d d „ Z d S(   iÿÿÿÿ(   t   unicode_literals(   t   deque(   t   wrapsu   SimpleCacheu   FastDictCacheu   memoizedt   SimpleCachec           B  s,   e  Z d  Z d d „ Z d „  Z d „  Z RS(   u§   
    Very simple cache that discards the oldest item when the cache size is
    exceeded.

    :param maxsize: Maximum size of the cache. (Don't make it too big.)
    i   c         C  sC   t  | t ƒ r | d k s! t ‚ i  |  _ t ƒ  |  _ | |  _ d  S(   Ni    (   t
   isinstancet   intt   AssertionErrort   _dataR   t   _keyst   maxsize(   t   selfR	   (    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   __init__   s    !	c         C  s”   y |  j  | SWn~ t k
 r | ƒ  } | |  j  | <|  j j | ƒ t |  j  ƒ |  j k r‹ |  j j ƒ  } | |  j  k r‹ |  j  | =q‹ n  | SXd S(   uš   
        Get object from the cache.
        If not found, call `getter_func` to resolve it, and put that on the top
        of the cache instead.
        N(   R   t   KeyErrorR   t   appendt   lenR	   t   popleft(   R
   t   keyt   getter_funct   valuet   key_to_remove(    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   get   s    	c         C  s   i  |  _  t ƒ  |  _ d S(   u    Clear cache. N(   R   R   R   (   R
   (    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   clear1   s    	(   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyR      s   	t   FastDictCachec           B  s&   e  Z d  Z d d d „ Z d „  Z RS(   u¿  
    Fast, lightweight cache which keeps at most `size` items.
    It will discard the oldest items in the cache first.

    The cache is a dictionary, which doesn't keep track of access counts.
    It is perfect to cache little immutable objects which are not expensive to
    create, but where a dictionary lookup is still much faster than an object
    instantiation.

    :param get_value: Callable that's called in case of a missing key.
    i@B c         C  sU   t  | ƒ s t ‚ t | t ƒ r- | d k s3 t ‚ t ƒ  |  _ | |  _ | |  _ d  S(   Ni    (   t   callableR   R   R   R   R   t	   get_valuet   size(   R
   R   R   (    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyR   K   s
    !	c         C  sj   t  |  ƒ |  j k r= |  j j ƒ  } | |  k r= |  | =q= n  |  j | Œ  } | |  | <|  j j | ƒ | S(   N(   R   R   R   R   R   R   (   R
   R   R   t   result(    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   __missing__S   s    
N(   R   R   R   t   NoneR   R   (    (    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyR   7   s   	i   c           s"   t  d |  ƒ ‰  ‡  f d †  } | S(   uI   
    Momoization decorator for immutable classes and pure functions.
    R	   c           s"   t  ˆ  ƒ ‡ ‡  f d †  ƒ } | S(   Nc            s=   ‡  ‡ ‡ f d †  } ˆ  t  ˆ j ƒ  ƒ f } ˆ j | | ƒ S(   Nc             s   ˆ ˆ  ˆ Ž  S(   N(    (    (   t   at   kwt   obj(    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt
   create_newi   s    (   t   tuplet   itemsR   (   R    R!   R#   R   (   t   cacheR"   (   R    R!   s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   new_callableg   s    (   R   (   R"   R'   (   R&   (   R"   s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt	   decoratorf   s    (   R   (   R	   R(   (    (   R&   s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   memoized`   s    	N(   u   SimpleCacheu   FastDictCacheu   memoized(   t
   __future__R    t   collectionsR   t	   functoolsR   t   __all__t   objectR   t   dictR   R)   (    (    (    s3   lib/python2.7/site-packages/prompt_toolkit/cache.pyt   <module>   s     +)