
    $TXg]                     J   d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZmZ ddlmZ ddlmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/m.Z. ddl0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=m>Z>  e#e?      Z@ eAej                  d      xr ej                  j                         ZD G d de!      ZE e5ej                  j                  d            r	 eEd      ZHn e!d      ZHdDdZI G d  d!      ZJ G d" d#eJ      ZK eK       ZL G d$ d%e      ZMedEd&       ZNedFd'       ZOedGd(       ZPeeMj                  eMj                  fd)       ZRed*        ZSed+        ZTed,        ZUedGd-       ZVe dd.ddfd/ZWdd0d1ZX e7d2d3d45       G d6 d7             ZY e7d2d3d85       G d9 d:             ZZ G d; d<e	      Z[ G d= d>e      Z\eZd? Z] G d@ dAeJ      Z^dB Z_e?dCk(  r e_        yy)HzCommon I/O utilities.    N)defaultdict)ExecutorFutureThreadPoolExecutor_baseas_completed)	_WorkItem)contextmanager)Enum)EPIPE	ESHUTDOWN)partialwraps)BytesIOStringIO)cycle)CRITICALWARN	FormatterStreamHandler	getLogger)dirnameisdirisfilejoin)EventLockRLockThread)sleeptime   )memoizemethod)NullHandler)boolify)
deprecated   )encode_environmenton_win)NULL)expandisattyc                   .     e Zd ZdZd fd	Z fdZ xZS )DeltaSecondsFormatteraw  
    Logging formatter with additional attributes for run time logging.

    Attributes:
      `delta_secs`:
        Elapsed seconds since last log/format call (or creation of logger).
      `relative_created_secs`:
        Like `relativeCreated`, time relative to the initialization of the
        `logging` module but conveniently scaled to seconds as a `float` value.
    c                 F    t               | _        t        |   ||       y )N)fmtdatefmt)r!   	prev_timesuper__init__)selfr0   r1   	__class__s      /lib/python3.12/site-packages/conda/common/io.pyr4   zDeltaSecondsFormatter.__init__0   s    S'2    c                     t               }| j                  }t        | j                  |      | _        ||z
  |_        |j                  dz  |_        t        |   |      S )Ni  )r!   r2   max
delta_secsrelativeCreatedrelative_created_secsr3   format)r5   recordnowr2   r6   s       r7   r>   zDeltaSecondsFormatter.format4   sS    fNN	T^^S1)O'-'='='D$w~f%%r8   NN)__name__
__module____qualname____doc__r4   r>   __classcell__r6   s   @r7   r.   r.   $   s    	3& &r8   r.   CONDA_TIMED_LOGGINGzm%(relative_created_secs) 7.2f %(delta_secs) 7.2f %(levelname)s %(name)s:%(funcName)s(%(lineno)d): %(message)sz<%(levelname)s %(name)s:%(funcName)s(%(lineno)d): %(message)sc                 8    dj                  fd| D              S )N c              3   L   K   | ]  }d dz  z   dz   t        |      z     yw)
 z- N)str).0xindents     r7   	<genexpr>zdashlist.<locals>.<genexpr>I   s)     I14#,&-A6s   !$)r   )iterablerQ   s    `r7   dashlistrT   H   s    77IIIIr8   c                       e Zd ZdZd Zy)ContextDecoratorzyBase class for a context manager class (implementing __enter__() and __exit__()) that also
    makes it a decorator.
    c                 2     t               fd       }|S )Nc                  D    5   | i |cd d d        S # 1 sw Y   y xY wN )argskwdsfr5   s     r7   	decoratedz,ContextDecorator.__call__.<locals>.decoratedT   s    $'$' s   )r   )r5   r]   r^   s   `` r7   __call__zContextDecorator.__call__S   s!    	q	( 
	( r8   N)rB   rC   rD   rE   r_   rZ   r8   r7   rV   rV   L   s    r8   rV   c                       e Zd Zd Zd Zy)SwallowBrokenPipec                      y rY   rZ   r5   s    r7   	__enter__zSwallowBrokenPipe.__enter__`   s    r8   c                 z    |r9t        |t              r(t        |dd       r|j                  t        t
        fv ryy y y y )NerrnoT)
isinstanceEnvironmentErrorgetattrrf   r   r   r5   exc_typeexc_valexc_tbs       r7   __exit__zSwallowBrokenPipe.__exit__c   sD    7$45$/%!33 4 0 6 r8   N)rB   rC   rD   rd   rn   rZ   r8   r7   ra   ra   \   s    r8   ra   c                       e Zd ZdZdZdZy)CaptureTargetzConstants used for contextmanager captured.

    Used similarly like the constants PIPE, STDOUT for stdlib's subprocess.Popen.
    N)rB   rC   rD   rE   STRINGSTDOUTrZ   r8   r7   rp   rp   p   s    
 FFr8   rp   c              #   p  K   | i } t        |       }i }|j                         D ]?  \  }}t        j                  j	                  |t
              ||<   |t        j                  |<   A 	 |r |        |r |d       d  |j                         D ]2  \  }}|t
        u rt        j                  |=  |t        j                  |<   4 |r |        |r	 |d       y y # |j                         D ]2  \  }}|t
        u rt        j                  |=  |t        j                  |<   4 |r |        |r	 |d       w w xY ww)NTF)r(   itemsosenvirongetr*   )var_mapcallbackstack_callbacknew_var_map
saved_varsnamevalues          r7   env_varsr   z   s    $W-KJ"((*e::>>$5
4 

4 +"J4 %++-KD%}JJt$#(

4 	 .
 J5!  &++-KD%}JJt$#(

4 	 .
 J5! s    A$D6'C >AD6AD33D6c              #   b   K   | |i}t        |||      5 }| d d d        y # 1 sw Y   y xY ww)N)r{   r|   r   )r   r   r{   r|   dess         r7   env_varr      s.     	uA	!h~	F" 
G	F	Fs   /#	/,/c              #   V   K   t        |       5 }| d d d        y # 1 sw Y   y xY ww)N)r{   r   )r{   r   s     r7   env_unmodifiedr      s      	8	$ 
%	$	$s   )	)&)c              #     K   d } G d d      }t         j                  t         j                  }}| t        j                  k(  r8t               }|j                  |_        t        ||      |_        |t         _        n| }||t         _        |t        j                  k(  r8t               }|j                  |_        t        ||      |_        |t         _        n0|t        j                  k(  r|xt         _        }n|}||t         _         |       }t        j                  d       	 | | t        j                  k(  r|j                         |_        n||_        |t        j                  k(  r|j                         |_        n"|t        j                  k(  rd|_        n||_        ||ct         _        t         _        t        j                  d       y# | t        j                  k(  r|j                         |_        n||_        |t        j                  k(  r|j                         |_        n"|t        j                  k(  rd|_        n||_        ||ct         _        t         _        t        j                  d       w xY ww)a  Capture outputs of sys.stdout and sys.stderr.

    If stdout is STRING, capture sys.stdout as a string,
    if stdout is None, do not capture sys.stdout, leaving it untouched,
    otherwise redirect sys.stdout to the file-like object given by stdout.

    Behave correspondingly for stderr with the exception that if stderr is STDOUT,
    redirect sys.stderr to stdout target and set stderr attribute of yielded object to None.

    .. code-block:: pycon

       >>> from conda.common.io import captured
       >>> with captured() as c:
       ...     print("hello world!")
       ...
       >>> c.stdout
       'hello world!\n'

    Args:
        stdout: capture target for sys.stdout, one of STRING, None, or file-like object
        stderr: capture target for sys.stderr, one of STRING, STDOUT, None, or file-like object

    Yields:
        CapturedText: has attributes stdout, stderr which are either strings, None or the
            corresponding file-like function argument.
    c                 x   t        | d      rd| j                  v rt        }nt        | t              rt        }nt
        }t        ||      s_t        |d      r#|j                  d      }| j                  |       y t        |d      r#|j                  d      }| j                  |       y y | j                  |       y )Nmodebdecodezutf-8encode)	hasattrr   bytesrg   r   rN   r   	old_writer   )r5   to_writewanteddecodedr   s        r7   write_wrapperzcaptured.<locals>.write_wrapper   s     4 SDII%5Fg&FF(F+x*"//'2w'8,OOG,q! - NN8$r8   c                       e Zd Zy)captured.<locals>.CapturedTextNrB   rC   rD   rZ   r8   r7   CapturedTextr      s    r8   r   Nzovertaking stderr and stdoutzstderr and stdout yielding back)sysstdoutstderrrp   rs   r   writer   r   rt   logdebuggetvalue)	r   r   r   r   saved_stdoutsaved_stderroutfileerrfilecs	            r7   capturedr      s    :%(  "%SZZ,L%%%*#MMw7
 CJ%%%*#MMw7
	=''	'&&
W CJAII,-5])))'')AHAH])))'')AH}+++AHAH!-|
CJ		34 ])))'')AHAH])))'')AH}+++AHAH!-|
CJ		34s    DI:"G &B(I:B)I77I:c              #      K   t         j                  }| t         _        	 d  |t         _        y # |t         _        w xY wwrY   )r   argv)	args_list
saved_argss     r7   r   r     s,     JCH:s   ?/ ?<?c               #      K   t        j                          	 d  t        j                          y # t        j                          w xY wwrY   )logging_acquireLock_releaseLockrZ   r8   r7   _logger_lockr     s2     s   A
1 A
AA
c              #   X  K   t        |       }|j                  |j                  |j                  }}}t	               }t               5  |j                  |       |j                  t        dz          d\  |_        |_        d d d        	 d  t               5  |j                  |       ||c|_        |_        ||_        d d d        y # 1 sw Y   IxY w# 1 sw Y   y xY w# t               5  |j                  |       ||c|_        |_        ||_        d d d        w # 1 sw Y   w xY wxY ww)Nr'   )TF)
r   leveldisabled	propagater$   r   
addHandlersetLevelr   removeHandler)logger_namelogr_lvl_dsbld_prpgtnull_handlers         r7   disable_loggerr     s     [!D::t}}dnn&&D=L	%hl#(3%t~ 
$^|,(,f%DJ#DN ^ 
 ^\^|,(,f%DJ#DN ^^sf   AD*9C?D*C 
D*(C>	D*CD*CD*D'*(D	D'D$ D''D*c              #     K   t        |      }|j                  |j                  |j                  |j                  f\  }}}}t        t        j                        }d|_        |j                  |        |j                  t               t               5  |j                  |        g ddc|_        |_        |_        |j                  |       |j                  |        d d d        	 d  t               5  |||c|_        |_        |_        ||_        d d d        y # 1 sw Y   ?xY w# 1 sw Y   y xY w# t               5  |||c|_        |_        |_        ||_        d d d        w # 1 sw Y   w xY wxY ww)Nr   F)r   handlersr   r   r   r   r   r   r   r   setFormatter
_FORMATTERr   r   )r   r   r   _hndlrsr   r   r   handlers           r7   stderr_log_levelr   '  s    [!D

	%!GT66 CJJ'GGLU$	e795%4t}dn e	 

$^7>f4DM4:t}#DN ^ 
 ^\^7>f4DM4:t}#DN ^^sg   BE2A
DE2$D1 (
E22D%	E2D"E2%D.*E21E/<E#	E/#E,(E//E2Fc                    t        |      }t        d |j                  D        d      }t        t        j
                        }d|_        |j                  |        |j                  |xs t               |xs dD ]  }|j                  |        t               5  |r|j                  |       |j                  |       | |j                         k  r|j                  |        ||_        ddd       y# 1 sw Y   yxY w)a[  Attach a new `stderr` handler to the given logger and configure both.

    This function creates a new StreamHandler that writes to `stderr` and attaches it
    to the logger given by `logger_name` (which maybe `None`, in which case the root
    logger is used). If the logger already has a handler by the name of `stderr`, it is
    removed first.

    The given `level` is set **for the handler**, not for the logger; however, this
    function also sets the level of the given logger to the minimum of its current
    effective level and the new handler level, ensuring that the handler will receive the
    required log records, while minimizing the number of unnecessary log events. It also
    sets the loggers `propagate` property according to the `propagate` argument.
    The `formatter` argument can be used to set the formatter of the handler.
    c              3   @   K   | ]  }|j                   d k(  s|  yw)r   N)r   )rO   r   s     r7   rR   z(attach_stderr_handler.<locals>.<genexpr>Y  s     JW1Is   Nr   rZ   )r   nextr   r   r   r   r   r   r   r   	addFilterr   r   r   getEffectiveLevelr   )	r   r   r   	formatterfiltersr   old_stderr_handlernew_stderr_handlerfilter_s	            r7   attach_stderr_handlerr   A  s    , [!DJJD
 'szz2&&##I$;<=b=$$W- ! 
12*+4))++MM% " 
s   AC22C;)default_returnc                D   t         r		  ||i |S  G d dt              fd}t        j                  t        j                  |       t        j
                  |        	  ||i |}t        j
                  d       |S # t        $ r |cY S w xY w# t        f$ r |cY S w xY w)z[Enforce a maximum time for a callable to complete.
    Not yet implemented on Windows.
    c                       e Zd Zy)!timeout.<locals>.TimeoutExceptionNr   rZ   r8   r7   TimeoutExceptionr   {  s    r8   r   c                             rY   rZ   )signumframer   s     r7   	interruptztimeout.<locals>.interrupt~  s    "$$r8   r   )r)   KeyboardInterrupt	ExceptionsignalSIGALRMalarm)timeout_secsfuncr   r[   kwargsr   retr   s          @r7   timeoutr   n  s     	"(((
	y 		% 	fnni0\"	"''CLLOJ! ! 	"!!	"" !"34 	"!!	"s#   A> B >BBBBz25.3z25.9z*Use `conda.reporters.get_spinner` instead.)addendumc                   P    e Zd ZdZ ed      Zd
dZd Zd Zd Z	e
d        Zd Zy	)Spinnera  
    Args:
        message (str):
            A message to prefix the spinner with. The string ': ' is automatically appended.
        enabled (bool):
            If False, usage is a no-op.
        json (bool):
           If True, will not output non-json to stdout.

    z/-\|c                 .   || _         || _        || _        t               | _        t        | j                        | _        t        t        | j                              dz   | _        t        j                  | _        |xr | xr t        | _        || _        y )N)targetr'   )messageenabledjsonr   _stop_runningr   _start_spinning_spinner_threadlenr   spinner_cycle_indicator_lengthr   r   fhIS_INTERACTIVE	show_spinfail_message)r5   r   r   r   r   s        r7   r4   zSpinner.__init__  sw    	"W%T-A-AB!$T$*<*<%=!>!B** @X@.(r8   c                     | j                   r| j                  j                          y | j                  s6| j                  j                  d       | j                  j                          y y )Nz...working... )r   r   startr   r   r   flushrc   s    r7   r   zSpinner.start  sE    >>  &&(GGMM*+GGMMO r8   c                     | j                   r<| j                  j                          | j                  j	                          d| _         y y NF)r   r   setr   r   rc   s    r7   stopzSpinner.stop  s9    >>""$  %%'"DN r8   c                    	 | j                   j                         s| j                  j                  t	        | j
                        dz          | j                  j                          t        d       | j                  j                  d| j                  z         | j                   j                         sy y # t        $ r4}|j                  t        t        fv r| j                          n Y d }~y d }~ww xY w)NrM   g?)r   is_setr   r   r   r   r   r    r   OSErrorrf   r   r   r   )r5   es     r7   r   zSpinner._start_spinning  s    
	((//1d4#5#56<=ddT%;%;;<	 ((//1
  	ww5),,		 	s   B2B7 7	C4 *C//C4c                     | j                   sJt        j                  j                  | j                   d       t        j                  j                          | j                          y )N: )r   r   r   r   r   r   r   rc   s    r7   rd   zSpinner.__enter__  s?    yyJJ~R01JJ

r8   c                 J   | j                          | j                  s{t        5  |s|r*t        j                  j                  | j                         nt        j                  j                  d       t        j                  j                          d d d        y y # 1 sw Y   y xY w)Nzdone
)r   r   swallow_broken_piper   r   r   r   r   rj   s       r7   rn   zSpinner.__exit__  sh    		yy$wJJ$$T%6%67JJ$$X.

  " %$ $$s   A,BB"N)TFzfailed
)rB   rC   rD   rE   r   r   r4   r   r   r   r  rd   rn   rZ   r8   r7   r   r     s?    	 'NM
)#  #r8   r   z/Use `conda.reporters.get_progress_bar` instead.c                   X    e Zd Zed        Z	 d	dZd Zd Zd Ze	d        Z
ed        Zy)
ProgressBarc                 P    t        | d      st               | _        | j                  S )N_lock)r   r   r  )clss    r7   get_lockzProgressBar.get_lock  s!     sG$CIyyr8   Nc           	      d   || _         || _        || _        |ry|r_t        r/d}	 | j	                  ||ddt
        j                  ||      | _        yd| _        t
        j                  j                  | d       yy# t        $ r+}|j                  t        t        fv rd| _        n Y d}~yd}~ww xY w)a  
        Args:
            description (str):
                The name of the progress bar, shown on left side of output.
            enabled (bool):
                If False, usage is a no-op.
            json (bool):
                If true, outputs json progress to stdout rather than a progress bar.
                Currently, the json format assumes this is only used for "fetch", which
                maintains backward compatibility with conda 4.3 and earlier behavior.
        z!{desc}{bar} | {percentage:3.0f}% Tr'   )desc
bar_formatasciitotalfilepositionleaveFNz ...working...)descriptionr   r   r   _tqdmr   r   pbarr   rf   r   r   r   )r5   r  r   r   r  r  r  r   s           r7   r4   zProgressBar.__init__  s     '	@
 $

(#-" ZZ!)# !+ !DI !	

  K=!?@)   ww5)"44', %s   +A; ;	B/!B**B/c                    	 | j                   r| j                  rK| j                         5  t        j                  j                  d| j                   d|dd       d d d        y t        r3| j                  j                  || j                  j                  z
         y |dk(  r t        j                  j                  d       y y y # 1 sw Y   y xY w# t        $ r+}|j                  t        t        fv rd| _         n Y d }~y d }~ww xY w)N
{"fetch":"z)","finished":false,"maxval":1,"progress":r]   z}
 r'    done
F)r   r   r
  r   r   r   r  r   r  updatenr   rf   r   r   )r5   fractionr   s      r7   	update_tozProgressBar.update_to  s    	||99

(()$*:*:);;demnodppvw ) $II$$X		%;<]JJ$$Y/ # (  	ww5),,$ 	s@   (C 2CC %8C $C C
C C 	D!D  Dc                 &    | j                  d       y )Nr'   )r  rc   s    r7   finishzProgressBar.finish!  s    qr8   c                 z    | j                   r/| j                  s"t        r| j                  j	                          yyyy)z-Force refresh i.e. once 100% has been reachedN)r   r   r   r  refreshrc   s    r7   r   zProgressBar.refresh$  s*    <<		nII /=	<r8   c                    | j                   r| j                  re| j                         5  t        j                  j                  d| j                   d       t        j                  j                          d d d        y t        r| j                  j                          y t        j                  j                  d       y y # 1 sw Y   y xY w)Nr  z,","finished":true,"maxval":1,"progress":1}
 r  )r   r   r
  r   r   r   r  r   r   r  closerc   s    r7   r"  zProgressBar.close)  s    <<yy]]_JJ$$%d&6&6%77fg JJ$$&	 %_
  		!

  + $_s   AC  C	c                      ddl m}  || i |S )z=Deferred import so it doesn't hit the `conda activate` paths.r   )tqdm)	tqdm.autor$  )r[   r   r$  s      r7   r  zProgressBar._tqdm7  s     	#T$V$$r8   )TFNT)rB   rC   rD   classmethodr
  r4   r  r  r   r  r"  staticmethodr  rZ   r8   r7   r  r    s[       KO(AT$ 
 , , % %r8   r  c                   &    e Zd Zd Zd Zd ZddZy)DummyExecutorc                 0    d| _         t               | _        y r   )	_shutdownr   _shutdownLockrc   s    r7   r4   zDummyExecutor.__init__A  s    !Vr8   c                    | j                   5  | j                  rt        d      t               }	  ||i |}|j	                  |       |cd d d        S # t
        $ r}|j                  |       Y d }~*d }~ww xY w# 1 sw Y   y xY w)N*cannot schedule new futures after shutdown)r,  r+  RuntimeErrorr   
set_resultBaseExceptionset_exception)r5   fnr[   r   r]   resultr   s          r7   submitzDummyExecutor.submitE  s|    ~~"#OPPA%T,V, V$   ! #""#  s3   "A;AA;	A8A3.A;3A88A;;Bc              '   <   K   |D ]  }|D ]  } ||         y wrY   rZ   )r5   r   	iterablesrS   things        r7   mapzDummyExecutor.mapT  s$     !H!5k! " "s   c                 T    | j                   5  d| _        d d d        y # 1 sw Y   y xY w)NT)r,  r+  )r5   waits     r7   shutdownzDummyExecutor.shutdownY  s    !DN  s   'N)T)rB   rC   rD   r4   r5  r9  r<  rZ   r8   r7   r)  r)  @  s    $"
"r8   r)  c                   &     e Zd Zd fd	Zd Z xZS )ThreadLimitedThreadPoolExecutorc                 $    t         |   |       y rY   )r3   r4   )r5   max_workersr6   s     r7   r4   z(ThreadLimitedThreadPoolExecutor.__init___  s    %r8   c                 f   | j                   5  | j                  rt        d      t        j                         }t        ||||      }| j                  j                  |       	 | j                          |cddd       S # t        $ r t        | j                        dkD  rn Y 0w xY w# 1 sw Y   yxY w)a  
        This is an exact reimplementation of the `submit()` method on the parent class, except
        with an added `try/except` around `self._adjust_thread_count()`.  So long as there is at
        least one living thread, this thread pool will not throw an exception if threads cannot
        be expanded to `max_workers`.

        In the implementation, we use "protected" attributes from concurrent.futures (`_base`
        and `_WorkItem`). Consider vendoring the whole concurrent.futures library
        as an alternative to these protected imports.

        https://github.com/agronholm/pythonfutures/blob/3.2.0/concurrent/futures/thread.py#L121-L131  # NOQA
        https://github.com/python/cpython/blob/v3.6.4/Lib/concurrent/futures/thread.py#L114-L124
        r.  r   N)_shutdown_lockr+  r/  r   r   r	   _work_queueput_adjust_thread_countr   _threads)r5   r3  r[   r   r]   ws         r7   r5  z&ThreadLimitedThreadPoolExecutor.submitb  s       ~~"#OPPA!Rv.A  #
))+ ' !     t}}%)   ! s0   AB'#A>3B'>#B$!B'#B$$B''B0)
   )rB   rC   rD   r4   r5  rF   rG   s   @r7   r>  r>  ^  s    &!r8   r>  c                  n    t        ddd      } t        t        j                  j	                  d|             S )N~z.condazinstrumentation-record.csv!CONDA_INSTRUMENTATION_RECORD_FILE)r   r+   rw   rx   ry   )default_record_files    r7   get_instrumentation_record_filerM    s3    sH.JK


:<OP r8   c                        e Zd Z e       ZdZ ee      Z ee	      Z
d	dZd Z fdZd Zd Zed        Zed        Z xZS )
time_recorderNc                      || _         || _        y rY   )
entry_namemodule_name)r5   rQ  rR  s      r7   r4   ztime_recorder.__init__  s    $&r8   c                     | j                   Yt        |d      r|j                  }nd|j                  z   }| j                  rdj                  | j                  |f      }|| _         y y )NrD   :.)rQ  r   rD   rB   rR  r   )r5   r]   rQ  s      r7   _set_entry_nameztime_recorder._set_entry_name  s[    ??"q.)^^
 1::-
 XXt'7'7&DE
(DO #r8   c                 D    | j                  |       t        | 	  |      S rY   )rV  r3   r_   )r5   r]   r6   s     r7   r_   ztime_recorder.__call__  s!    Qw""r8   c                 |    t         j                  j                  d      }|rt        |      rt	               | _        | S )NCONDA_INSTRUMENTATION_ENABLED)rw   rx   ry   r%   r!   
start_time)r5   r   s     r7   rd   ztime_recorder.__enter__  s-    **..!@Aww'"fDOr8   c                 j   | j                   r| j                  }t               }|| j                   z
  }| j                  |xx   dz  cc<   | j                  |xx   |z  cc<   | j                          t        | j                  d      5 }|j                  | d|dd       d d d        y y # 1 sw Y   y xY w)Nr'   a,r]   rL   )	rZ  rQ  r!   total_call_numtotal_run_time_ensure_diropenrecord_filer   )r5   rk   rl   rm   rQ  end_timerun_timer   s           r7   rn   ztime_recorder.__exit__  s    ??JvH$//1H
+q0+
+x7+d&&,J<q!B78 -,  -,s   B))B2c                 <   t         j                  j                  d      }|rt        |      sy t        j                  d       t        | j                  j                               D ]4  }t        j                  d| j                  |   | j                  |   |       6 y )NrY  z*=== time_recorder total time and calls ===zTOTAL %9.3f % 9d %s)
rw   rx   ry   r%   r   infosortedr_  keysr^  )r	  r   rQ  s      r7   
log_totalsztime_recorder.log_totals  s{    **..!@AGG,=> !3!3!8!8!:;JHH%"":."":.	 <r8   c                     t        t        | j                              s)t        j                  t        | j                               y y rY   )r   r   rb  rw   makedirsrc   s    r7   r`  ztime_recorder._ensure_dir  s1    WT--./KK 0 012 0r8   rA   )rB   rC   rD   rM  rb  rZ  r   intr^  floatr_  r4   rV  r_   rd   rn   r&  ri  r#   r`  rF   rG   s   @r7   rO  rO    se    13KJ %N 'N')#	9   3 3r8   rO  c                     t               } t        t              }i }t        |       sy t	        |       5 }|D ]A  }|j                         j                  d      \  }}||   j                  t        |             C 	 d d d        t        |      D ]+  }||   }t        |      }t        |      }||z  }	|||	d||<   - t        t        j                  |ddd             y # 1 sw Y   exY w)Nr]  )counts
total_timeaverage_timeTr"   )r]  r  )	sort_keysrQ   
separators)rM  r   listr   ra  stripsplitappendrm  rg  r   sumprintr   dumps)
rb  grouped_data
final_datar   linerQ  rp  	all_timesro  rq  s
             r7   print_instrumentation_datar    s    13Kt$LJ+	k	bD%)ZZ\%7%7%<"J
$++E*,=>  

 \*
 ,	Y^
!F*$("

: + 
$**Z4k
RS! 
	s   ACC(__main__)r"   )NNNrA   rY   )`rE   r   r   rw   r   r   collectionsr   concurrent.futuresr   r   r   r   r   concurrent.futures.threadr	   
contextlibr
   enumr   rf   r   r   	functoolsr   r   ior   r   	itertoolsr   r   r   r   r   r   os.pathr   r   r   r   	threadingr   r   r   r   r!   r    auxlib.decoratorsr#   auxlib.logzr$   auxlib.type_coercionr%   deprecationsr&   compatr(   r)   	constantsr*   pathr+   rB   r   r   r   r,   r   r.   rx   ry   r   rT   rV   ra   r  rp   r   r   r   rs   r   r   r   r   r   r   r   r   r  r)  r>  rM  rO  r  rZ   r8   r7   <module>r     s~      	  
 # X X / %  " $    G G 0 0 0 0  - % * % .  X.F3::3D3D3F&I &2 2::>>/01&	GJ
 FJ
J  ( " () D  " "6    
 !((1E1E [5 [5|     $ $" $ $4 *#Z 7; "< 

9
D# D#
D#N 

>
_% _%
_%F"H "<%&8 %P =3$ =3@T8 z  r8   