
    h                         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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)
namedtuple)AnyCallableDictIterableListTuple   )AbstractAccessLogger)BaseRequest)StreamResponse	KeyMethodz
key methodc                   
  ^  \ 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'   \4S\R&                  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\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\*4S) j5       r+S\S\S\SS4S* jr,S+r-U =r.$ ),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_CACHElogger
log_formatreturnNc                    > [         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.

)r*   N)super__init__r   r(   getcompile_format_log_format_methods)selfr)   r*   _compiled_format	__class__s       A/var/www/html/env/lib/python3.13/site-packages/aiohttp/web_log.pyr.   AccessLogger.__init__?   s_     	7'5599*E#22:>5EL&&z2*:'$-    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)r3   r*   methodsatomformat_key1m
key_methodformat_key2s           r6   r0   AccessLogger.compile_formatO   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:
__((<
""r8   keyrequestresponsetimec                 B    Uc  gUR                   R                  U S5      $ )Nz(no headers)-headersr/   rM   rN   rO   rP   s       r6   	_format_iAccessLogger._format_ix   s%     ?! ""3,,r8   c                 :    UR                   R                  U S5      $ NrR   rS   rU   s       r6   	_format_oAccessLogger._format_o   s    
 ##C--r8   c                 0    U c  gU R                   nUb  U$ S$ rY   )remote)rN   rO   rP   ips       r6   	_format_aAccessLogger._format_a   s"    ?^^^r,,r8   c                     [         R                  " [         R                  " [        R                  * S95      n[         R                   R	                  U5      nU[         R                  " US9-
  nUR                  S5      $ )N)secondsz[%d/%b/%Y:%H:%M:%S %z])datetimetimezone	timedeltatime_modnowstrftime)rN   rO   rP   tzrg   
start_times         r6   	_format_tAccessLogger._format_t   sc    x118;L;L:LMN##B'8--d;;
""#;<<r8   c                 2    S[         R                  " 5       -  $ )Nz<%s>)osgetpidrN   rO   rP   s      r6   	_format_PAccessLogger._format_P   s    		##r8   c                     U c  gSR                  U R                  U R                  U R                  R                  U R                  R
                  5      $ )NrR   z{} {} HTTP/{}.{})formatmethodpath_qsversionmajorminorrp   s      r6   	_format_rAccessLogger._format_r   sE    ?!((NNOOOO!!OO!!	
 	
r8   c                     UR                   $ N)statusrp   s      r6   	_format_sAccessLogger._format_s   s    r8   c                     UR                   $ r}   )body_lengthrp   s      r6   	_format_bAccessLogger._format_b   s    ###r8   c                 *    [        [        U5      5      $ r}   strroundrp   s      r6   	_format_TAccessLogger._format_T   s    5;r8   c                     SU-  $ )Nz%06f rp   s      r6   
_format_TfAccessLogger._format_Tf   s    }r8   c                 0    [        [        US-  5      5      $ )Ni@B r   rp   s      r6   	_format_DAccessLogger._format_D   s    5())r8   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}   )r2   )r3   rN   rO   rP   rM   ru   s         r6   _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.)r)   isEnabledForloggingINFO)r3   s    r6   enabledAccessLogger.enabled   s     {{''55r8   c                     U R                  XU5      n[        5       n[        5       nU HM  u  pxUR                  U5        UR                  [
        L a  XU'   M/  Uu  pUR                  U	0 5      nXU
'   XU	'   MO     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   r<   dictrC   r5   r   r/   r)   infor1   tuple	Exception	exception)r3   rN   rO   rP   fmt_infovaluesr   rM   valuek1k2dcts               r6   logAccessLogger.log   s    	6((DAHVFFE&
e$==C'!&#J FB))B+C#G #"I ' KKT--f=UK 	6KK!!"45	6s   B)B, ,%CC)r1   r2   )/__name__
__module____qualname____firstlineno____doc__r?   
LOG_FORMATrecompiler=   rE   r(   r   r   r	   r   r   __annotations__r   Loggerr.   r0   staticmethodr   r   floatrV   rZ   r_   rk   rq   rz   intr   r   r   r   r   r   r   r   propertyboolr   r   __static_attributes____classcell__)r5   s   @r6   r   r      s   6 !!!!N CJ

LMIJ'J<>M4U3Y#7889>AK ;w~~ ;3 ;PT ; ; '# '#sDO7K1L '#R --&-2@-HM-	- - ..&.2@.HM.	. . -; -. - -RU - - =; =. = =RU = = $; $. $ $RU $ $ 
; 
. 
 
RU 
 
 ; .  RU   $; $. $ $RU $ $  ;  .    RU     K >  SV   *; *. * *RU * *Y"Y.<YDIY	%X{NE&JC&OPPQ	RY
 6 6 6
6; 6. 6 6RV 6 6r8   r   )rc   rA   r   rn   r   rP   rf   collectionsr   typingr   r   r   r   r   r	   abcr   web_requestr   web_responser   r   r   r   r8   r6   <module>r      sD       	 	  " = = % $ ({L1	G6' G6r8   