
    @OOfl              
      >   d dl m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	 d dl
mZ d dlmZ ej                  rd dlmZ ej"                  dz   Z	  ej&                  ed	       g d
Zej*                  dej,                  dediZ G d dej0                        Z G d dej4                        Z G d d      Z G d d      Zej*                  dej,                  dej"                  dedej<                  diZ G d de      Z e G d de	jB                               Z"d Z#y)     )annotationsN)	dataclass)hooks)click)humanmaster   ALERTerrorwarninfoalertdebugredyellowmagentac                  0     e Zd Zd fdZdZdZddZ xZS )MitmFormatterc                    t         |           || _        d}d}|r0t        j                  |dd      }t        j                  |dd      }| | d| _        | d| _        y )Nz[%s]cyanT)fgdimr   z %s)super__init__colorize	miniclickstylewith_clientwithout_client)selfr   timeclient	__class__s       N/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/log.pyr   zMitmFormatter.__init__%   sg     ??4F=D__VdCF"VF83/!%cl    z%H:%M:%Sz%s.%03dc                   | j                  |      }|j                         }|j                  r | d| j                  |j                         }| j                  r4t        j                  |t        j                  |j                              }t        |dd       x}r't        j                  |      }| j                  |||fz  S | j                  ||fz  S )N
)r   r$   )
formatTime
getMessageexc_infoformatExceptionr   r   r   
LOG_COLORSgetlevelnogetattrr   format_addressr    r!   )r"   recordr#   messager$   s        r&   formatzMitmFormatter.format4   s    v&##%?? 	D$8$8$I#JKG==oo>>&..1G
 VXt4464))&1F##tVW&===&&$88r'   )r   bool)r3   logging.LogRecordreturnstr)__name__
__module____qualname__r   default_time_formatdefault_msec_formatr5   __classcell__r%   s   @r&   r   r   $   s    
+ %#9r'   r   c                  :     e Zd Z fdZd fdZddZddZ xZS )MitmLogHandlerc                l    t        |   |i | t        j                  j	                  d      | _        y NPYTEST_CURRENT_TEST)r   r   osenvironr/   _initiated_in_test)r"   argskwargsr%   s      r&   r   zMitmLogHandler.__init__G   s+    $)&)"$**..1F"Gr'   c                    t        t        | 	  |      xr; | j                   xs, | j                  t        j
                  j                  d      k(        S rD   )r6   r   filterrH   rF   rG   r/   )r"   r3   r%   s     r&   rL   zMitmLogHandler.filterK   sO    GN6" +++ T**bjjnn=R.SS	
 	
r'   c                0   | j                   rgt        t        j                         j                        D ]=  }t        |t              s|j                   | j                   k7  s.|j                          ? t        j                         j                  |        y N)	rH   listlogging	getLoggerhandlers
isinstancerB   	uninstall
addHandler)r"   hs     r&   installzMitmLogHandler.installU   sn    ""'++-667 "q.1,,0G0GGKKM" 	&&t,r'   c                J    t        j                         j                  |        y rN   )rP   rQ   removeHandlerr"   s    r&   rT   zMitmLogHandler.uninstall`   s    ))$/r'   )r3   r7   r8   r6   )r8   None)r:   r;   r<   r   rL   rW   rT   r?   r@   s   @r&   rB   rB   F   s    H
	-0r'   rB   c                      e Zd Zd Zd Zd Zy)LogEntryc                2    t        |      | _        || _        y rN   )r9   msglevel)r"   r_   r`   s      r&   r   zLogEntry.__init__h   s     s8
r'   c                V    t        |t              r| j                  |j                  k(  S y)NF)rS   r]   __dict__)r"   others     r&   __eq__zLogEntry.__eq__n   s"    eX&==ENN22r'   c                <    d| j                    d| j                   dS )Nz	LogEntry(z, )r_   r`   rZ   s    r&   __repr__zLogEntry.__repr__s   s    488*Btzzl!44r'   N)r:   r;   r<   r   rd   rh    r'   r&   r]   r]   g   s    
5r'   r]   c                  <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d
dZ
y	)Logz
    The central logger, exposed to scripts as mitmproxy.ctx.log.

    Deprecated: Please use the standard Python logging module instead.
    c                    || _         y rN   r   )r"   r	   s     r&   r   zLog.__init__~   s	    r'   c                    t        j                  dt        d       t        j                         j                  |       y)z'
        Log with level debug.
        zamitmproxy's ctx.log.debug() is deprecated. Please use the standard Python logging module instead.   
stacklevelN)warningsr   DeprecationWarningrP   rQ   r   r"   txts     r&   r   z	Log.debug   2     	o	

 	!!#&r'   c                    t        j                  dt        d       t        j                         j                  |       y)z&
        Log with level info.
        z`mitmproxy's ctx.log.info() is deprecated. Please use the standard Python logging module instead.rn   ro   N)rq   r   rr   rP   rQ   r   rs   s     r&   r   zLog.info   s2     	n	

 	  %r'   c                    t        j                  dt        d       t        j                         j                  t        |       y)z
        Log with level alert. Alerts have the same urgency as info, but
        signals to interactive tools that the user's attention should be
        drawn to the output even if they're not currently looking at the
        event log.
        zamitmproxy's ctx.log.alert() is deprecated. Please use the standard Python logging module instead.rn   ro   N)rq   r   rr   rP   rQ   logr   rs   s     r&   r   z	Log.alert   s4     	o	

 	s+r'   c                    t        j                  dt        d       t        j                         j                  |       y)z&
        Log with level warn.
        z`mitmproxy's ctx.log.warn() is deprecated. Please use the standard Python logging module instead.rn   ro   N)rq   r   rr   rP   rQ   warningrs   s     r&   r   zLog.warn   s2     	n	

 	##C(r'   c                    t        j                  dt        d       t        j                         j                  |       y)z'
        Log with level error.
        zamitmproxy's ctx.log.error() is deprecated. Please use the standard Python logging module instead.rn   ro   N)rq   r   rr   rP   rQ   r   rs   s     r&   r   z	Log.error   ru   r'   c                    t        j                  dt        d       t        j                         j                  t        j                  |j                               |       y )Nz[mitmproxy's ctx.log() is deprecated. Please use the standard Python logging module instead.rn   ro   )r`   r_   )rq   r   rr   rP   rQ   rx   getLevelNameupper)r"   textr`   s      r&   __call__zLog.__call__   sF    i	

 	g&:&:5;;=&ItTr'   N)r   )r:   r;   r<   __doc__r   r   r   r   r   r   r   ri   r'   r&   rk   rk   w   s+    	'	&,	)	'Ur'   rk   r   r   r   r   r   c                  0     e Zd ZdZ	 	 d fdZddZ xZS )LegacyLogEventsz5Emit deprecated `add_log` events from stdlib logging.c                R    t         |           || _        t        d      | _        y )NF)r   )r   r   r	   r   	formatter)r"   r	   r%   s     r&   r   zLegacyLogEvents.__init__   s#     	&6r'   c                   t        | j                  |      t        j                  |j                  d            }| j
                  j                  j                  | j
                  j                  j                  t        |             y )Nr   rg   )r]   r5   LOGGING_LEVELS_TO_LOGENTRYr/   r0   r	   
event_loopcall_soon_threadsafeaddonstrigger
AddLogHook)r"   r3   entrys      r&   emitzLegacyLogEvents.emit   sa    F#,00I
 	33KK&&u	
r'   )r	   zmaster.Master)r3   r7   r8   r[   )r:   r;   r<   r   r   r   r?   r@   s   @r&   r   r      s    ?77
r'   r   c                      e Zd ZU dZded<   y)r   aQ  
    **Deprecated:** Starting with mitmproxy 9, users should use the standard Python logging module instead, for example
    by calling `logging.getLogger().addHandler()`.

    Called whenever a new log entry is created through the mitmproxy
    context. Be careful not to log from this event, which will cause an
    infinite loop!
    r]   r   N)r:   r;   r<   r   __annotations__ri   r'   r&   r   r      s     Or'   r   c                @    t        ddddd      j                  |       S )z
    Comparison method for "old" LogEntry log tiers.
    Ideally you should use the standard Python logging module instead.
    r   r
   rn      r   )dictr/   )r`   s    r&   log_tierr      s"    
 aaaq:>>uEEr'   )$
__future__r   rP   rF   typingrq   dataclassesr   	mitmproxyr   mitmproxy.contribr   r   mitmproxy.utilsr   TYPE_CHECKINGr	   INFOr   addLevelName	LogLevelsERRORWARNINGr.   	Formatterr   HandlerrB   r]   rk   DEBUGr   r   Hookr   r   ri   r'   r&   <module>r      s   "  	   !  0 !	 q   UG $	 mmUGOOXuiP
9G%% 9D0W__ 0B5 5 JU JU\ MM7OOVLL&	7MM7 
n 
, 
 
 
Fr'   