
    wBf9                      ^   d 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 ddlmZm	Z	m
Z
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mZ dd
lmZ  ee      Zeee
eedZ ej8                  ddde        G d de      Z G d de      Z ed      d        Zd Z e	fdZ!efdZ"efdZ# ed      dedfd       Z$ eddd      de%fd       Z&de%fdZ' edd d!      d"        Z( ejR                  ed#       e(ejT                  _(        ejT                  jV                  ejT                  _,        y)$zConfigure logging for conda.    N)datetime)	lru_cachepartial)DEBUGERRORINFOWARNFilter	FormatterStreamHandler	getLogger   )
CondaError)TRACE)
_FORMATTERattach_stderr_handler)
deprecated)r      r         z24.3z24.9VERBOSITY_LEVELSc                   \    e Zd Z ej                  d      Z eej                  d      Zd Z	y)TokenURLFilterz(|https?://)(|\s|(?:(?:\d{1,3}\.){3}\d{1,3})|(?:(?:[a-zA-Z0-9-]{1,20}\.){0,10}(?:[a-zA-Z]{2}[a-zA-Z0-9-]{0,18})))(|:\d{1,5})?/t/[a-z0-9A-Z-]+/z\1\2\3/t/<TOKEN>/c                       j                  |j                        |_        |j                  r9t         fd|j                  D              }|j                  |z  |_        d|_        y)a>  
        Since Python 2's getMessage() is incapable of handling any
        strings that are not unicode when it interpolates the message
        with the arguments, we fix that here by doing it ourselves.

        At the same time we replace tokens in the arguments which was
        not happening until now.
        c              3   d   K   | ]'  }t        |t              rj                  |      n| ) y wN)
isinstancestrTOKEN_REPLACE).0argselfs     6lib/python3.12/site-packages/conda/gateways/logging.py	<genexpr>z(TokenURLFilter.filter.<locals>.<genexpr>?   s2       ,6c3+?""3'SHs   -0NT)r   msgargstuple)r"   recordnew_argss   `  r#   filterzTokenURLFilter.filter4   sY     ''

3
;; !;; H  h.FJFK    N)
__name__
__module____qualname__recompileTOKEN_URL_PATTERNr   subr   r*    r+   r#   r   r   &   s3    "

	
 -113GHMr+   r   c                   8     e Zd ZdZdZ fdZ fdZ	 d Z xZS )StdStreamHandlerz?Log StreamHandler that always writes to the current sys stream.
c                 R    t         |   t        t        |             || _        | `y)zr
        Args:
            sys_stream: stream name, either "stdout" or "stderr" (attribute of module sys)
        N)super__init__getattrsys
sys_streamstream)r"   r<   	__class__s     r#   r9   zStdStreamHandler.__init__M   s%    
 	j12$Kr+   c                 `    |dk(  rt        t        | j                        S t        |   |      S )Nr=   )r:   r;   r<   r8   __getattribute__)r"   attrr>   s     r#   __getattr__zStdStreamHandler.__getattr__V   s,    8300w'--r+   c                    	 | j                  |      }| j                  }d}|j                  ||z         t        |d| j                        }|j                  |       | j                          y# t        $ r | j                  |       Y yw xY w)a  
        Emit a record.

        If a formatter is specified, it is used to format the record.
        The record is then written to the stream with a trailing newline.  If
        exception information is present, it is formatted using
        traceback.print_exception and appended to the stream.  If the stream
        has an 'encoding' attribute, it is used to determine how to do the
        output to the stream.
        z%s
terminatorN)formatr=   writer:   rD   flush	ExceptionhandleError)r"   r(   r%   r=   fsrD   s         r#   emitzStdStreamHandler.emito   sy    	%++f%C[[FBLLc" tGJLL$JJL  	%V$	%s   A+A. .B
B)	r,   r-   r.   __doc__rD   r9   rB   rK   __classcell__)r>   s   @r#   r5   r5   H   s    IJ.&%r+   r5   )maxsizec                  @    t                t                t                y r   )initialize_root_loggerset_conda_log_levelinitialize_std_loggersr3   r+   r#   initialize_loggingrS      s     r+   c                     t        d      } dD ]	  }t        d|z        }g |_        |j                  t               t        |      }|j                  t               |j                  |        |j                  |       |j                  t                      d|_
        t        d|z        }g |_        |j                  t               t        |      }d|_        |j                  t               |j                  |        |j                  |       d|_
         t        d      }g |_        |j                  t               t        d      }|j                  t               |j                  |        |j                  |       d|_
        y )	Nz%(message)s)stdoutstderrzconda.%sFzconda.%slog zconda.stdout.verboserU   )r   r   handlerssetLevelr   r5   setFormatter
addHandler	addFilterr   	propagater   rD   )	formatterr=   loggerhandlerstdlog_loggerstdlog_handlerverbose_loggerverbose_handlers           r#   rR   rR      sT    -(I& (:./"6*Y''")* !-&"89!#u%)&1$&!&##I.  0"''(* 56N ND!&x0OT"  +o.$Nr+   c                     t        |        y )Nlevel)r   rf   s    r#   rP   rP      s
    &r+   c                     t        d      }|j                  t        j                         t	        | d       d|_        y )Nconda)rg   logger_nameF)r   rY   loggingNOTSETr   r]   )rg   conda_loggers     r#   rQ   rQ      s0    W%L'..)7;"Lr+   c                     | t         k\  rt        d      nd }t        | |       t        |        t        | d       t        | d       y )Nz%(message)s
)r^   requestszrequests.packages.urllib3)r   r   r   rQ   )rg   r^   s     r#   set_all_logger_levelrp      s=    .3tm	/*I%95 %,%!<=r+   c                    |)t        j                         j                  d      }d| d}t        |       }t	        j
                  |      }|j                  t               |j                  |       |j                  |       y )Nz%Y%m%d-%H%M%Sz.conda.z.log)
r   utcnowstrftimer   rk   FileHandlerrZ   r   rY   r[   )rj   rg   path	timestamprm   r`   s         r#   set_file_loggingrw      sp    |OO%..?	4([)L!!$'G$UG$r+   z3Use `conda.gateways.logging.set_log_level` instead.)addendum	verbosityc                 b    	 t        t        |           y # t        $ r t        d|        d w xY w)NzInvalid verbosity level: )set_log_level_VERBOSITY_LEVELSKeyErrorr   )ry   s    r#   set_verbosityr~      s<    L'	23 L4YK@AtKLs    .	log_levelc                 F    t        |        t        j                  d|        y )Nzlog_level set to %d)rp   logdebug)r   s    r#   r{   r{      s    #II#Y/r+   z25.3zMUse `logging.getLogger(__name__)(conda.common.constants.TRACE, ...)` instead.c                 b    | j                  t              r | j                  t        ||fi | y y r   )isEnabledForr   _log)r"   messager&   kwargss       r#   tracer      s.     		%$1&1  r+   r   )-rL   rk   r/   r;   r   	functoolsr   r   r   r   r   r	   r
   r   r   r   rW   r   common.constantsr   	common.ior   r   deprecationsr   r,   r   r|   constantr   r5   rS   rR   rP   rQ   rp   rw   intr~   r{   r   addLevelNameLoggerwarningwarnr3   r+   r#   <module>r      s|   #  	 
  (	 	 	  $ 9 %   
  FF$68I JV D>%} >%L 4 !%H "' ' # #  % > 4!%U 	% 	% 

B
LS L
L0S 0
 

\
2
2
   UG $  nn,, r+   