ó
P'—^c           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d d l	 m
 Z
 d d l m Z m Z m Z d d	 d
 d d d d d d d d d d g Z d Z d d „ Z e e e e d „ ƒ Z e e e d „ Z e j e _ e e d „ ƒ Z e d „ Z e e e e d „ ƒ Z e e e d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e e ƒ Z d  „  Z  i e  d! 6d" „  d# 6d$ „  d% 6d& „  d' 6d( „  d) 6Z! d e f d* „  ƒ  YZ" e" e ƒ Z# d d! d+ „ Z$ d d! d, „ Z% e d- „ Z& e d. „ Z' e d/ „ Z( d S(0   iÿÿÿÿ(   t   print_functionN(   t   chain(   t   partiali   (   t
   basestring(   t	   decoratort   wrapst   Callt   tapt	   log_callst   print_callst
   log_enterst   print_enterst	   log_exitst   print_exitst
   log_errorst   print_errorst   log_durationst   print_durationst   log_iter_durationst   print_iter_durationsi   c         C  s+   | r t  d | |  f ƒ n
 t  |  ƒ |  S(   s   Prints x and then returns it.s   %s: %s(   t   print(   t   xt   label(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR      s    
c         C  sŽ   t  |  | ƒ } y? | d | ƒ |  ƒ  } | d t | d d ƒ| f ƒ | SWn9 t k
 r‰ } | rƒ | d t | | | ƒ ƒ n  ‚  n Xd S(   s]   Logs or prints all function calls,
       including arguments, results and raised exceptions.s   Call %ss   -> %s from %st   max_lens   -> N(   t   signature_reprt
   smart_reprt   Nonet   BaseExceptiont   _format_error(   t   callt
   print_funct   errorst   stackt   repr_lent	   signaturet   resultt   e(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   #   s    	 c         C  s3   t  |  ƒ r t t ƒ |  ƒ St t |  | | ƒ Sd  S(   N(   t   callableR   R   (   R   R    R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR	   3   s    c         C  s   | d t  |  | ƒ ƒ |  ƒ  S(   s!   Logs each entrance to a function.s   Call %s(   R   (   R   R   R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR
   ;   s    c         C  s-   t  |  ƒ r t t ƒ |  ƒ St t |  ƒ Sd S(   s&   Prints on each entrance to a function.N(   R%   R
   R   (   R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   B   s    c         C  s€   t  |  | ƒ } y1 |  ƒ  } | d t | d d ƒ| f ƒ | SWn9 t k
 r{ } | ru | d t | | | ƒ ƒ n  ‚  n Xd S(   s   Logs exits from a function.s   -> %s from %sR   s   -> N(   R   R   R   R   R   (   R   R   R   R    R!   R"   R#   R$   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   J   s    	 c         C  s3   t  |  ƒ r t t ƒ |  ƒ St t |  | | ƒ Sd S(   s    Prints on exits from a function.N(   R%   R   R   (   R   R    R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   X   s    t   LabeledContextDecoratorc           B  s2   e  Z d  Z d e d „ Z d d „ Z d „  Z RS(   s_   
    A context manager which also works as decorator, passing call signature as its label.
    c         C  s   | |  _  | |  _ | |  _ d  S(   N(   R   R   R!   (   t   selfR   R   R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   __init__d   s    		c         K  s3   t  | ƒ r |  j | ƒ S|  j |  j | |  Sd  S(   N(   R%   R   t	   __class__R   (   R'   R   t   kwargs(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   __call__i   s    c           s"   t  ˆ  ƒ ‡  ‡ f d †  ƒ } | S(   Nc            sg   ˆ j  j ˆ j  ƒ } | j j ˆ j ƒ t t ˆ  |  | ƒ ˆ j ƒ | _ |  ˆ  |  | Ž  SWd  QXd  S(   N(   R)   t   __new__t   __dict__t   updateR   R   R!   R   (   t   argsR*   t   cm(   t   funcR'   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   innerp   s
    !(   R   (   R'   R1   R2   (    (   R1   R'   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   o   s    N(   t   __name__t
   __module__t   __doc__R   t   REPR_LENR(   R+   R   (    (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR&   `   s   c           B  s2   e  Z d  Z d e e d „ Z d „  Z d „  Z RS(   s5   Logs or prints all errors within a function or block.c         C  s)   t  j |  | d | d | ƒ| |  _ d  S(   NR   R!   (   R&   R(   R    (   R'   R   R   R    R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR(   }   s    c         C  s   |  S(   N(    (   R'   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt	   __enter__   s    c         C  si   | re |  j  r0 d j t j | | | ƒ ƒ } n d | j | f } |  j t |  j | |  j  ƒ ƒ n  d  S(   Nt    s   %s: %s(   R    t   joint	   tracebackt   format_exceptionR3   R   R   R   (   R'   t   exc_typet	   exc_valuet   tbt   exc_message(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   __exit__„   s
    	!N(	   R3   R4   R5   R   t   TrueR6   R(   R7   R@   (    (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   {   s   	c         C  sT   |  d k  r d |  d S|  d k  r0 d |  d S|  d k  rH d |  d	 Sd
 |  Sd  S(   Ngíµ ÷Æ°>s   %8.2f nsg    eÍÍAgü©ñÒMbP?s	   %8.2f mksg    €„.Ai   s   %8.2f msg     @@s   %8.2f s(    (   t   sec(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   format_time‘   s    t   autoc         C  s   d |  d S(   Ns   %8.2f nsg    eÍÍA(    (   RB   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   <lambda>   R8   t   nsc         C  s   d |  d S(   Ns	   %8.2f mksg    €„.A(    (   RB   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyRE   ž   R8   t   mksc         C  s   d |  d S(   Ns   %8.2f msg     @@(    (   RB   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyRE   Ÿ   R8   t   msc         C  s   d |  S(   Ns   %8.2f s(    (   RB   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyRE       R8   t   sc           B  s5   e  Z d  Z d d d e d „ Z d „  Z d „  Z RS(   s,   Times each function call or block execution.RD   iÿÿÿÿc         C  sU   t  j |  | d | d | ƒ| t k r; t d | ƒ ‚ n  t | |  _ | |  _ d  S(   NR   R!   s;   Unknown time unit: %s. It should be ns, mks, ms, s or auto.(   R&   R(   t   time_formatterst
   ValueErrorRC   t	   threshold(   R'   R   R   t   unitRL   R!   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR(   ¦   s
    c         C  s   t  j  ƒ  |  _ |  S(   N(   t   timet   start(   R'   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR7   ­   s    c         G  sa   t  j  ƒ  |  j } | |  j k r] |  j | ƒ } |  j |  j rS d | |  j f n | ƒ n  d  S(   Ns   %s in %s(   RN   RO   RL   RC   R   R   (   R'   t   exct   durationt   duration_str(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR@   ±   s    N(   R3   R4   R5   R   R6   R(   R7   R@   (    (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   ¤   s   	c         c  sª   | t  k r t d | ƒ ‚ n  t  | } | r9 d | n d } t |  ƒ } xX t | ƒ D]J \ } } t j ƒ  }	 | V| t j ƒ  |	 ƒ }
 | d |
 | | f ƒ qX Wd S(   s%   Times processing of each item in seq.s;   Unknown time unit: %s. It should be ns, mks, ms, s or auto.s    of %sR8   s   %s in iteration %d%sN(   RJ   RK   t   itert	   enumerateRN   (   t   seqR   R   RM   t   _format_timet   suffixt   itt   it   itemRO   RQ   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   º   s    
c         C  s   t  |  t | d | ƒS(   s%   Times processing of each item in seq.RM   (   R   R   (   RU   R   RM   (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   Ç   s    c         C  sq   t  | t ƒ r= | r$ t j ƒ  } qC d | j j | f } n | } |  ri | rU d n d } | | |  f S| Sd  S(   Ns   %s: %ss   %s    raised in %ss   %s raised in %s(   t
   isinstancet	   ExceptionR:   t
   format_excR)   R3   (   R   R$   R    t	   e_messaget   template(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   Î   s    c           s³   t  |  j t ƒ rF t |  j j d ƒ r= d |  j j j } q[ d } n t |  j d d ƒ } ‡  f d †  |  j Dƒ } ‡  f d †  |  j j	 ƒ  Dƒ } d | d j
 t | | ƒ ƒ f S(	   NR3   s   <%s partial>s   <unknown partial>s	   <unknown>c         3  s   |  ] } t  | ˆ  ƒ Vq d  S(   N(   R   (   t   .0t   arg(   R!   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pys	   <genexpr>è   s    c         3  s.   |  ]$ \ } } d  | t  | ˆ  ƒ f Vq d S(   s   %s=%sN(   R   (   R`   t   keyt   value(   R!   (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pys	   <genexpr>é   s   s   %s(%s)s   , (   R[   t   _funcR   t   hasattrR1   R3   t   getattrt   _argst   _kwargst   itemsR9   R   (   R   R!   t   namet	   args_reprt   kwargs_repr(    (   R!   s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   à   s    	c         C  sp   t  |  t ƒ r t |  ƒ } n t |  ƒ } t j d d | ƒ } | rl t | ƒ | k rl | | d  d } n  | S(   Ns   \s+t    i   s   ...(   R[   R   t   reprt   strt   ret   subt   len(   Rc   R   t   res(    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyR   í   s    ()   t
   __future__R    Rp   RN   R:   t	   itertoolsR   t	   functoolsR   t   compatR   t
   decoratorsR   R   R   t   __all__R6   R   R   RA   R   R	   R5   R
   R   R   R   t   objectR&   R   R   R   RC   RJ   R   R   R   R   R   R   R   (    (    (    s-   /tmp/pip-unpacked-wheel-WgnHs6/funcy/debug.pyt   <module>   sV   		



