
    i!                         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
  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)Iterable)CallableClassVarDictListOptionalTuple   )AbstractAccessLogger)BaseRequest)StreamResponse	KeyMethodz
key methodc                   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r\\   \S'   \4S\R4                  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r0\1S\24S- j5       r3S\S\S\SS4S. jr4S/r5U =r6$ )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.

)r-   N)super__init__r   r)   getcompile_format_log_format_methods)selfr,   r-   _compiled_format	__class__s       </app/mltbenv/lib/python3.13/site-packages/aiohttp/web_log.pyr1   AccessLogger.__init__C   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)r6   r-   methodsatomformat_key1m
key_methodformat_key2s           r9   r3   AccessLogger.compile_formatS   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;   keyrequestresponsetimec                 B    Uc  gUR                   R                  U S5      $ )Nz(no headers)-headersr2   rP   rQ   rR   rS   s       r9   	_format_iAccessLogger._format_i|   s%     ?! ""3,,r;   c                 :    UR                   R                  U S5      $ NrU   rV   rX   s       r9   	_format_oAccessLogger._format_o   s    
 ##C--r;   c                 0    U c  gU R                   nUb  U$ S$ r\   )remote)rQ   rR   rS   ips       r9   	_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)r*   time_modrS   r+   	localtime	tm_gmtoffdatetimetimezone	timedeltanowreplaceri   	timestamp)clsgmtofftzrr   ds        r9   _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      $ )Nre   z[%d/%b/%Y:%H:%M:%S %z])r   ry   ro   rq   strftime)rQ   rR   rS   rr   
start_times        r9   	_format_tAccessLogger._format_t   s7    **,8--d;;
""#;<<r;   c                 2    S[         R                  " 5       -  $ )Nz<%s>)osgetpidrQ   rR   rS   s      r9   	_format_PAccessLogger._format_P   s    		##r;   c                     U c  gSR                  U R                  U R                  U R                  R                  U R                  R
                  5      $ )NrU   z{} {} HTTP/{}.{})formatmethodpath_qsversionmajorminorr   s      r9   	_format_rAccessLogger._format_r   sE    ?!((NNOOOO!!OO!!	
 	
r;   c                     UR                   $ N)statusr   s      r9   	_format_sAccessLogger._format_s   s    r;   c                     UR                   $ r   )body_lengthr   s      r9   	_format_bAccessLogger._format_b   s    ###r;   c                 *    [        [        U5      5      $ r   strroundr   s      r9   	_format_TAccessLogger._format_T   s    5;r;   c                     SU-  $ )Nz%06f r   s      r9   
_format_TfAccessLogger._format_Tf   s    }r;   c                 0    [        [        US-  5      5      $ )Ni@B r   r   s      r9   	_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   )r5   )r6   rQ   rR   rS   rP   r   s         r9   _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)r6   s    r9   enabledAccessLogger.enabled   s     {{''55r;   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?   dictrF   r8   r   r2   r,   infor4   tuple	Exception	exception)r6   rQ   rR   rS   fmt_infovaluesr   rP   valuek1k2dcts               r9   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)r4   r5   )7__name__
__module____qualname____firstlineno____doc__rB   
LOG_FORMATrecompiler@   rH   r)   r   r   r
   r   r   __annotations__r*   r   r	   ro   rp   r+   floatr   Loggerr1   r3   staticmethodr   r   rY   r]   rb   classmethodry   r~   r   r   intr   r   r   r   r   r   r   r   propertyboolr   r   __static_attributes____classcell__)r8   s   @r9   r   r      s   6 !!!!N CJ

LMIJ'J<>M4U3Y#7889>8<J("3"345<*--AK ;w~~ ;3 ;PT ; ; '# '#sDO7K1L '#R --&-2@-HM-	- - ..&.2@.HM.	. . -; -. - -RU - - 5 1 1 5 5 =; =. = =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 6r;   r   )ro   rD   r   r   r   rS   rl   collectionsr   collections.abcr   typingr   r   r   r   r	   r
   abcr   web_requestr   web_responser   r   r   r   r;   r9   <module>r      sG       	 	  " $ B B % $ ({L1	X6' X6r;   