ó
P'—^c           @   sÑ   d  d l  m  Z  m Z d  d l Z d d l m Z d d l m Z d d d d	 g Z d
 e f d „  ƒ  YZ	 d „  Z
 e	 e
 _ d „  Z e e ƒ Z e e ƒ Z d e _ d d „ Z e rÄ d „  Z n	 d „  Z d S(   iÿÿÿÿ(   t   datetimet	   timedeltaNi   (   t   wraps(   t   PY2t   memoizet   make_lookupert   silent_lookupert   cachet   SkipMemoizationc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR      s   c             s‚   |  r< t  |  ƒ d k s t ‚ | s+ t ‚ t ƒ  |  d ƒ S| j d d ƒ ‰  | ro t d d j | ƒ ƒ ‚ n  ‡  f d †  } | S(   s  @memoize(key_func=None). Makes decorated function memoize its results.

    If key_func is specified uses key_func(*func_args, **func_kwargs) as memory key.
    Otherwise uses args + tuple(sorted(kwargs.items()))

    Exposes its memory via .memory attribute.
    i   i    t   key_funcs.   memoize() got unexpected keyword arguments: %ss   , c            s4   i  ‰ t  ˆ  ƒ ‡  ‡ ‡ f d †  ƒ } ˆ | _ | S(   Nc             s«   ˆ r ˆ |  | Ž  n% | r7 |  t  t | j ƒ  ƒ ƒ n |  } y ˆ | SWn[ t k
 r¦ y ˆ  |  | Ž  } ˆ | <| SWq§ t k
 r¢ } | j rž | j d Sd  SXn Xd  S(   Ni    (   t   tuplet   sortedt   itemst   KeyErrorR   t   argst   None(   R   t   kwargst   keyt   valuet   e(   t   funcR   t   memory(    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt   wrapper"   s    ((   R   R   (   R   R   (   R   (   R   R   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt	   decorator   s    !	N(   t   lent   AssertionErrorR   t   popR   t	   TypeErrort   join(   R   R   R   (    (   R   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR      s    c            s   ‡  ‡ f d †  ‰  ˆ  S(   Nc            sq   t  ˆ  ƒ \ } } | s% t d ƒ ‚ | rF t ‡  ‡ f d †  ƒ } n i  ‰ ‡  ‡ ‡ f d †  } t ˆ  ƒ | ƒ S(   sO  
        Creates a single argument function looking up result in a memory.

        Decorated function is called once on first lookup and should return all available
        arg-value pairs.

        Resulting function will raise LookupError when using @make_lookuper
        or simply return None when using @silent_lookuper.
        s@   Lookup table building function should not have keyword argumentsc             sD   ‡  ‡ f d †  } d ˆ j  d j t t ˆ  ƒ ƒ f | _  ˆ | ƒ S(   Nc              s
   ˆ ˆ  Œ  S(   N(    (    (   R   R   (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt   <lambda>J   t    s   %s(%s)s   , (   R	   R   t   mapt   str(   R   t   f(   R   R   (   R   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   H   s    (c            sj   ˆ s& d  ˆ t ƒ  <ˆ j ˆ  ƒ  ƒ n  ˆ r9 ˆ j |  ƒ S|  ˆ k rM ˆ |  St d ˆ  j |  f ƒ ‚ d  S(   Ns   Failed to look up %s(%s)(   R   t   objectt   updatet   gett   LookupErrorR	   (   t   arg(   R   R   t   silent(    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   P   s    (   t   has_arg_typesR   R   R   (   R   t   has_argst   has_keysR   (   R   R)   (   R   R   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   9   s    

	(    (   R)   (    (   R   R)   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt   _make_lookuper8   s    $c            sO   t  ˆ t ƒ r! t d ˆ ƒ ‰ n  ˆ  d k r9 d „  ‰  n  ‡  ‡ f d †  } | S(   s.   Caches a function results for timeout seconds.t   secondsc          _   s$   | r  |  t  t | j ƒ  ƒ ƒ S|  S(   N(   R   R   R   (   t   at   kw(    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   j   R    c            sa   i  ‰  t  ˆ ƒ ‡  ‡ ‡ ‡ f d †  ƒ } ‡  ‡ f d †  } | | _ ‡  f d †  } | | _ | S(   Nc             sx   ˆ |  | Ž  } | ˆ  k rO ˆ  | \ } } t  j ƒ  | ˆ k  rE | Sˆ  | =n  ˆ |  | Ž  } | t  j ƒ  f ˆ  | <| S(   N(   R    t   now(   R   R   R   t   resultt	   timestamp(   R   R   R   t   timeout(    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   o   s    
c             s   ˆ  j  ˆ |  | Ž  ƒ d  S(   N(   R   (   R   R   (   R   R   (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt
   invalidate}   s    c              s   ˆ  j  ƒ  d  S(   N(   t   clear(    (   R   (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt   invalidate_all   s    (   R   R5   R7   (   R   R   R5   R7   (   R   R4   (   R   R   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   l   s    $		N(   t
   isinstancet   intR   R   (   R4   R   R   (    (   R   R4   s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR   d   s    c         C   s4   t  j |  ƒ } t | j p! | j ƒ t | j ƒ f S(   N(   t   inspectt
   getargspect   boolR   t   varargst   keywords(   R   t   spec(    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR*   Š   s    c         C   sB   t  j |  ƒ j j ƒ  } t d „  | Dƒ ƒ t d „  | Dƒ ƒ f S(   Nc         s   s0   |  ]& } | j  | j | j | j f k Vq d  S(   N(   t   kindt   POSITIONAL_ONLYt   POSITIONAL_OR_KEYWORDt   VAR_POSITIONAL(   t   .0t   p(    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pys	   <genexpr>   s   c         s   s*   |  ]  } | j  | j | j f k Vq d  S(   N(   R@   t   KEYWORD_ONLYt   VAR_KEYWORD(   RD   RE   (    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pys	   <genexpr>’   s    (   R:   t	   signaturet
   parameterst   valuest   any(   R   t   params(    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyR*   Ž   s    	
(   R    R   R:   t
   decoratorsR   t   compatR   t   __all__t	   ExceptionR   R   t   skipR-   t   FalseR   t   TrueR   R	   R   R   R*   (    (    (    s,   /tmp/pip-unpacked-wheel-WgnHs6/funcy/calc.pyt   <module>   s   	&		'	%