ó
º9—^c           @   sa   d  Z  d d l m Z d d l m Z d d l m Z e d d d d d	 g ƒ Z d
 d „ Z d S(   s²   
LRU cache implementation for Python 2.7

Ported from http://code.activestate.com/recipes/578078/ and simplified for our
use (only support maxsize > 0 and positional arguments).
iÿÿÿÿ(   t
   namedtuple(   t   update_wrapper(   t   RLockt	   CacheInfot   hitst   missest   maxsizet   currsizeid   c            s   ‡  f d †  } | S(   s¯   Least-recently-used cache decorator.

    Arguments to the cached function must be hashable.

    See:  http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used

    c            s#  t  ƒ  ‰ d d g ‰ d	 \ ‰  ‰ ˆ j ‰ t ‰ t ƒ  ‰	 g  } | | d  d  g | (| g ‰
 d
 \ ‰ ‰ ‰ ‰ ˆ r ˆ d k s t d ˆ ƒ ‚ ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡ ‡
 ‡ ‡ f d †  } ‡  ‡ ‡ ‡	 ‡ ‡ f d †  } ‡ ‡	 ‡
 ‡ f d †  } ˆ | _ | | _ | | _ t	 | ˆ ƒ S(   Ni    i   i   i   s   maxsize %s not supportedc    
   	      s‡  |  } ˆ	  ˆ | ƒ } | d  k	 r˜ ˆ \ } | \ } } } } | | ˆ <| | ˆ <| ˆ } | | ˆ <| ˆ <| | ˆ <| | ˆ <ˆ ˆ  c d 7<| SWd  QXˆ |  Œ  } ˆ	 Ñ ˆ \ } | ˆ k rÉ n¤ ˆ ˆ ƒ ˆ
 k r7| } | | ˆ <| | ˆ <| ˆ } ˆ d <| ˆ }	 d  | ˆ <| ˆ <ˆ |	 =| ˆ | <n6 | ˆ } | | | | g } | | ˆ <| ˆ <ˆ | <ˆ ˆ c d 7<Wd  QX| S(   Ni   i    (   t   None(
   t   argst   keyt   linkt   roott	   link_prevt	   link_nextt   resultt   lastt   oldroott   oldkey(   t   HITSt   KEYt   MISSESt   NEXTt   PREVt   RESULTt   _lent   cachet	   cache_gett   lockR   t   nonlocal_roott   statst   user_function(    s5   /tmp/pip-unpacked-wheel-WyN9Ij/psycopg2/_lru_cache.pyt   wrapper&   sB    	





	



c        
      s2   ˆ & t  ˆ ˆ  ˆ ˆ ˆ t ˆ ƒ ƒ SWd QXd S(   s   Report cache statisticsN(   t
   _CacheInfot   len(    (   R   R   R   R   R   R   (    s5   /tmp/pip-unpacked-wheel-WyN9Ij/psycopg2/_lru_cache.pyt
   cache_infoV   s    c             sE   ˆ 9 ˆ  j  ƒ  ˆ d }  |  |  d d g |  (d d g ˆ (Wd QXd S(   s$   Clear the cache and cache statisticsi    N(   t   clearR   (   R   (   R   R   R   R   (    s5   /tmp/pip-unpacked-wheel-WyN9Ij/psycopg2/_lru_cache.pyt   cache_clear[   s
    

(   i    i   (   i    i   i   i   (
   t   dictt   getR"   R   R   t   AssertionErrort   __wrapped__R#   R%   R   (   R   R   R    R#   R%   (   R   (   R   R   R   R   R   R   R   R   R   R   R   R   R   s5   /tmp/pip-unpacked-wheel-WyN9Ij/psycopg2/_lru_cache.pyt   decorating_function   s$    				"60			(    (   R   R*   (    (   R   s5   /tmp/pip-unpacked-wheel-WyN9Ij/psycopg2/_lru_cache.pyt	   lru_cache   s    QN(	   t   __doc__t   collectionsR    t	   functoolsR   t	   threadingR   R!   R+   (    (    (    s5   /tmp/pip-unpacked-wheel-WyN9Ij/psycopg2/_lru_cache.pyt   <module>   s
   