
    rp0j'!                         S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
JrJr  SSKJr  SSKJr  SSKJr   " S S	\5      r " S
 S\5      rg)    N)Iterable)CallableClassVar
NamedTuple   )AbstractAccessLogger)BaseRequest)StreamResponsec                   J    \ rS rSr% \\\\4   -  \S'   \\\	\
/\4   \S'   Srg)	KeyMethod   keymethod N)__name__
__module____qualname____firstlineno__strtuple__annotations__r   r	   r
   float__static_attributes__r       I/home/wildlama/miniconda3/lib/python3.13/site-packages/aiohttp/web_log.pyr   r      s,    	uS#X	k>593>??r   r   c                   x  ^  \ rS rSr% SrSSSSSSS	S
SSSS.rSr\R                  " S5      r	\R                  " S5      r
0 r\\\\\\   4   4   \S'   Sr\\R*                  S-     \S'   Sr\\   \S'   \4S\R2                  S\SS4U 4S jjjrS\S\\\\   4   4S jr\S\S\S\S\S\4
S  j5       r\S\S\S\S\S\4
S! j5       r \S\S\S\S\4S" j5       r!\"S\R(                  4S# j5       r#\S\S\S\S\4S$ j5       r$\S\S\S\S\4S% j5       r%\S\S\S\S\4S& j5       r&\S\S\S\S\'4S' j5       r(\S\S\S\S\'4S( j5       r)\S\S\S\S\4S) j5       r*\S\S\S\S\4S* j5       r+\S\S\S\S\4S+ j5       r,S\S\S\S\-\\\\\4   -  \4      4S, jr.\/S\04S- j5       r1S\S\S\SS4S. jr2S/r3U =r4$ )0AccessLogger   aX  Helper object to log access.

Usage:
    log = logging.getLogger("spam")
    log_format = "%a %{User-Agent}i"
    access_logger = AccessLogger(log, log_format)
    access_logger.log(request, response, time)

Format:
    %%  The percent sign
    %a  Remote IP-address (IP-address of proxy if using reverse proxy)
    %t  Time when the request was started to process
    %P  The process ID of the child that serviced the request
    %r  First line of request
    %s  Response status code
    %b  Size of response in bytes, including HTTP headers
    %T  Time taken to serve the request, in seconds
    %Tf Time taken to serve the request, in seconds with floating fraction
        in .06f format
    %D  Time taken to serve the request, in microseconds
    %{FOO}i  request.headers['FOO']
    %{FOO}o  response.headers['FOO']
    %{FOO}e  os.environ['FOO']

remote_addressrequest_start_time
process_idfirst_request_lineresponse_statusresponse_sizerequest_timerequest_time_fracrequest_time_microrequest_headerresponse_header)atPrsbTTfDioz/%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"z.%(\{([A-Za-z0-9\-_]+)\}([ioe])|[atPrsbOD]|Tf?)z(%[^s])_FORMAT_CACHEN
_cached_tzg        _cached_tz_expireslogger
log_formatreturnc                    > [         TU ]  XS9  [        R                  R	                  U5      nU(       d$  U R                  U5      nU[        R                  U'   Uu  U l        U l        g)zInitialise the logger.

logger is a logger object to be used for logging.
log_format is a string with apache compatible log format description.

)r9   N)super__init__r   r5   getcompile_format_log_format_methods)selfr8   r9   _compiled_format	__class__s       r   r=   AccessLogger.__init__E   s_     	7'5599*E#22:>5EL&&z2*:'$-r   c           	         [        5       nU R                  R                  U5       H  nUS   S:X  a4  U R                  US      n[	        [
        SUS   -  5      n[        XE5      nOPU R                  US      US   4n[	        [
        SUS   -  5      n[        U[        R                  " XSS   5      5      nUR                  U5        M     U R                  R                  SU5      nU R                  R                  SU5      nX4$ )al  Translate log_format into form usable by modulo formatting

All known atoms will be replaced with %s
Also methods for formatting of those atoms will be added to
_methods in appropriate order

For example we have log_format = "%a %t"
This format will be translated to "%s %s"
Also contents of _methods will be
[self._format_a, self._format_t]
These method will be called and results will be passed
to translated string format.

Each _format_* method receive 'args' which is list of arguments
given to self.log

Exceptions are _format_e, _format_i and _format_o methods which
also receive key name (by functools.partial)

r    r   z
_format_%s   z%sz%\1)list	FORMAT_REfindallLOG_FORMAT_MAPgetattrr   r   	functoolspartialappendsub
CLEANUP_RE)rB   r9   methodsatomformat_key1m
key_methodformat_key2s           r   r?   AccessLogger.compile_formatU   s    . &NN**:6DAw"}"11$q':L,a*@A&{6
#2247;T!WEL,a*@A&{I4E4Eaa4QR
NN:& 7 ^^''z:
__((<
""r   r   requestresponsetimec                 B    Uc  gUR                   R                  U S5      $ )Nz(no headers)-headersr>   r   rZ   r[   r\   s       r   	_format_iAccessLogger._format_i~   s%     ?! ""3,,r   c                 :    UR                   R                  U S5      $ Nr^   r_   ra   s       r   	_format_oAccessLogger._format_o   s    
 ##C--r   c                 0    U c  gU R                   nUb  U$ S$ re   )remote)rZ   r[   r\   ips       r   	_format_aAccessLogger._format_a   s"    ?^^^r,,r   c                 0   U R                   b#  [        R                  " 5       U R                  :  a  [        R                  " 5       R
                  n[        R                  " [        R                  " US95      =U l         n[        R                  R                  U5      nU[        R                  " SS9-   nUR                  UR                  S:  a  SOSSSS9nUR                  5       U l        U$ [        R                  R                  U R                   5      $ )Nseconds   )minutesr   )minutesecondmicrosecond)r6   time_modr\   r7   	localtime	tm_gmtoffdatetimetimezone	timedeltanowreplacerr   	timestamp)clsgmtofftzr{   ds        r   _get_local_timeAccessLogger._get_local_time   s    >>!X]]_8N8N%N'')33F"*"3"3H4F4Fv4V"WWCNR##''+Ch((44A		qxx2~1QTU	VA%&[[]C"J  $$S^^44r   c                 z    [         R                  5       nU[        R                  " US9-
  nUR	                  S5      $ )Nrn   z[%d/%b/%Y:%H:%M:%S %z])r   r   rx   rz   strftime)rZ   r[   r\   r{   
start_times        r   	_format_tAccessLogger._format_t   s7    **,8--d;;
""#;<<r   c                 2    S[         R                  " 5       -  $ )Nz<%s>)osgetpidrZ   r[   r\   s      r   	_format_PAccessLogger._format_P   s    		##r   c                     U c  gU R                    SU R                   SU R                  R                   SU R                  R                   3$ )Nr^    z HTTP/.)r   path_qsversionmajorminorr   s      r   	_format_rAccessLogger._format_r   sK    ?..!7??"36'//:O:O9PPQRYRaRaRgRgQhiir   c                     UR                   $ N)statusr   s      r   	_format_sAccessLogger._format_s   s    r   c                     UR                   $ r   )body_lengthr   s      r   	_format_bAccessLogger._format_b   s    ###r   c                 *    [        [        U5      5      $ r   r   roundr   s      r   	_format_TAccessLogger._format_T   s    5;r   c                     SU-  $ )Nz%06fr   r   s      r   
_format_TfAccessLogger._format_Tf   s    }r   c                 0    [        [        US-  5      5      $ )Ni@B r   r   s      r   	_format_DAccessLogger._format_D   s    5())r   c           
      `    U R                    VVs/ s H  u  pEXE" XU5      4PM     snn$ s  snnf r   )rA   )rB   rZ   r[   r\   r   r   s         r   _format_lineAccessLogger._format_line   s0     KO--X-;3fW56-XXXs   *c                 T    U R                   R                  [        R                  5      $ )zCheck if logger is enabled.)r8   isEnabledForloggingINFO)rB   s    r   enabledAccessLogger.enabled   s     {{''55r   c                     U R                  XU5      n[        5       n[        5       nU HO  u  pxUR                  U5        [	        U[
        5      (       a  XU'   M1  Uu  pUR                  U	0 5      nXU
'   XU	'   MQ     U R                  R                  U R                  [        U5      -  US9  g ! [         a    U R                  R                  S5         g f = f)N)extrazError in logging)r   rI   dictrP   
isinstancer   r>   r8   infor@   r   	Exception	exception)rB   rZ   r[   r\   fmt_infovaluesr   r   valuek1k2dcts               r   logAccessLogger.log   s    	6((DAHVF59VE&
e$c3''!&#J FB*/))B*;C#G #"I ' KKT--f=UK 	6KK!!"45	6s   B+B. .%CC)r@   rA   )5r   r   r   r   __doc__rL   
LOG_FORMATrecompilerJ   rR   r5   r   r   r   rI   r   r   r6   r   rx   ry   r7   r   r   Loggerr=   r?   staticmethodr	   r
   rb   rf   rk   classmethodr   r   r   r   intr   r   r   r   r   r   r   propertyboolr   r   r   __classcell__)rD   s   @r   r   r      s   6 !!!!N CJ

LMIJ'J<>M4U3Y#7889>59J**T129*--AK ;w~~ ;3 ;PT ; ; '# '#sDO7K1L '#R --&-2@-HM-	- - ..&.2@.HM.	. . -; -. - -RU - - 5 1 1 5 5 =; =. = =RU = =
 $; $. $ $RU $ $ j; j. j jRU j j
 ; .  RU   $; $. $ $RU $ $  ;  .    RU     K >  SV   *; *. * *RU * *Y"Y.<YDIY	%eCHo-s23	4Y
 6 6 6
6; 6. 6 6RV 6 6r   r   )rx   rN   r   r   r   r\   ru   collections.abcr   typingr   r   r   abcr   web_requestr	   web_responser
   r   r   r   r   r   <module>r      sF       	 	  $ 1 1 % $ (@
 @
S6' S6r   