
    PThA                         d dl Z d dlmZ ddlmZ ddlmZ ddlmZ ddZ	edd       Z
 G d	 d
e      Z G d de      Z G d de      Zy)    N)contextmanager   )
HumanCount)HumanDuration)HumanThroughputc                 8   ddg| t        t                    S t        |       r(t              5   | |i |}ddd       t              S 	 t	        |       fdd_        t              S # 1 sw Y   ;xY w# t
        $ r t        d      w xY w)a1  Measure timing and throughput of code blocks, with beautiful
    human friendly representations.

    There are three modes of operation: context manager, callable and
    throughput.

    1. Use it like a context manager:

    >>> with about_time() as t:
    ....    # code block.

    2. Use it with a callable:

    >>> def func(a, b): ...
    >>> t = about_time(func, 1, b=2)  # send arguments at will.

    3. Use it with an iterable or generator:

    >>> t = about_time(it)  # any iterable or generator.
    >>> for item in t:
    ....    # use item
    g        Nz%param should be callable or iterable.c               3      K   t              5  t        d      D ]  \  _        } |   	 d d d        y # 1 sw Y   y xY ww)Nr   )_context_timing	enumeratecount)elemit
it_closuretimingss    T/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/about_time/core.pyr   zabout_time.<locals>.it_closure3   sF     W% 	*3B*: &
 $
	 	 	s   A7	AA Ar   )	r
   HandlecallableHandleResultiter	TypeErrorUserWarningr   HandleStats)
func_or_itargskwargsresultr   r   r   s       @@@r   
about_timer   	   s    0 CjG ww88 
W% 	100F	1GV,,C*

 Jw
++!	1 	1  CABBCs   	A8B 8BBc              #   p   K   t        j                         | d<   | t        j                         | d<   y w)Nr   r   )timeperf_counter)r   handles     r   r
   r
   <   s/     ""$GAJ
L""$GAJs   46c                   >    e Zd Zd Zedefd       Zedefd       Zy)r   c                     || _         y N)_Handle__timings)selfr   s     r   __init__zHandle.__init__D   s	         returnc                 l    | j                   d   xs t        j                         | j                   d   z
  S )zReturn the actual duration in seconds.
        This is dynamically updated in real time.

        Returns:
            the number of seconds.

        r   r   )r%   r   r    r&   s    r   durationzHandle.durationG   s/     q!8T%6%6%8DNN1<MMMr(   c                 ,    t        | j                        S )zReturn a beautiful representation of the duration.
        It dynamically calculates the best unit to use.

        Returns:
            the human representation.

        )r   r,   r+   s    r   duration_humanzHandle.duration_humanR   s     T]]++r(   N)	__name__
__module____qualname__r'   propertyfloatr,   r   r.    r(   r   r   r   C   s@    ! N% N N , , ,r(   r   c                   .     e Zd Z fdZed        Z xZS )r   c                 :    t         t        |   |       || _        y r$   )superr   r'   _HandleResult__result)r&   r   r   	__class__s      r   r'   zHandleResult.__init___   s    lD*73r(   c                     | j                   S )zfReturn the result of the callable.

        Returns:
            the result of the callable.

        )r8   r+   s    r   r   zHandleResult.resultc   s     }}r(   )r/   r0   r1   r'   r2   r   __classcell__r9   s   @r   r   r   ^   s      r(   r   c                        e Zd Z fdZd Zedefd       Zedefd       Z	de
defdZedefd       Zedefd	       Zde
defd
Z xZS )r   c                 :    t         t        |   |       || _        y r$   )r7   r   r'   _HandleStats__it)r&   r   r   r9   s      r   r'   zHandleStats.__init__o   s    k4)'2	r(   c                 "    | j                         S r$   )r?   r+   s    r   __iter__zHandleStats.__iter__s   s    yy{r(   r)   c                 .    | j                   j                  S )zReturn the current iteration count.
        This is dynamically updated in real time.

        Returns:
            the current iteration count.

        )r?   r   r+   s    r   r   zHandleStats.countv   s     yyr(   c                 $    | j                  d      S )zReturn a beautiful representation of the current iteration count.
        This is dynamically updated in real time.

        Returns:
            the human representation.

         )count_human_asr+   s    r   count_humanzHandleStats.count_human   s     ""2&&r(   unitc                 .    t        | j                  |      S )zReturn a beautiful representation of the current iteration count.
        This is dynamically updated in real time.

        Args:
            unit: what is being measured

        Returns:
            the human representation.

        )r   r   r&   rG   s     r   rE   zHandleStats.count_human_as   s     $**d++r(   c                 j    	 | j                   | j                  z  S # t        $ r t        d      cY S w xY w)zReturn the current throughput in items per second.
        This is dynamically updated in real time.

        Returns:
            the number of items per second.

        nan)r   r,   ZeroDivisionErrorr3   r+   s    r   
throughputzHandleStats.throughput   s3    	 ::--  	 <	 s    22c                 $    | j                  d      S )zReturn a beautiful representation of the current throughput.
        It dynamically calculates the best unit to use.

        Returns:
            the human representation.

        rD   )throughput_human_asr+   s    r   throughput_humanzHandleStats.throughput_human   s     ''++r(   c                 .    t        | j                  |      S )zReturn a beautiful representation of the current throughput.
        It dynamically calculates the best unit to use.

        Args:
            unit: what is being measured

        Returns:
            the human representation.

        )r   rM   rI   s     r   rO   zHandleStats.throughput_human_as   s     t55r(   )r/   r0   r1   r'   rA   r2   intr   r   rF   strrE   r3   rM   r   rP   rO   r;   r<   s   @r   r   r   n   s     s   'Z ' ',3 ,: ,  E     ,/ , ,6 6 6r(   r   r$   )r   
contextlibr   human_countr   human_durationr   human_throughputr   r   r
   objectr   r   r   r4   r(   r   <module>rY      sT     % # ) -0,f % %,V ,66  O6& O6r(   