
    h                         d dl Z d dl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
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  edd	          Z G d
 de          ZdS )    N)
namedtuple)AnyCallableDictIterableListTuple   )AbstractAccessLogger)BaseRequest)StreamResponse	KeyMethodz
key methodc                   D    e Zd ZU dZdddddddd	d
dddZdZ ej        d          Z ej        d          Z	i Z
eeeeee         f         f         ed<   efdej        deddf fdZdedeeee         f         fdZedededededef
d            Zedededededef
d            Zededededefd            Zededededefd            Zededededefd             Zededededefd!            Zededededefd"            Z ededededefd#            Z!ededededefd$            Z"ededededefd%            Z#ededededefd&            Z$dededede%eee&eeegef         f                  fd'Z'e(de)fd(            Z*dedededdfd)Z+ xZ,S )*AccessLoggera  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                                          ||           t          j                            |          }|s$|                     |          }|t          j        |<   |\  | _        | _        dS )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       Q/var/www/html/prod/cognitive/venv/lib/python3.11/site-packages/aiohttp/web_log.pyr-   zAccessLogger.__init__?   sv     	J777'599*EE 	F#22:>>5EL&z2*:'$---    c           	      V   t                      }| j                            |          D ]}|d         dk    rB| j        |d                  }t	          t
          d|d         z            }t          ||          }nb| j        |d                  |d         f}t	          t
          d|d         z            }t          |t          j        ||d                             }|	                    |           | j        
                    d|          }| j        
                    d|          }||fS )a  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)r2   r)   methodsatomformat_key1m
key_methodformat_key2s           r5   r/   zAccessLogger.compile_formatO   s   . &&N**:66 
	' 
	'DAw"}}"1$q':L,a*@AA&{A66

#247;T!WEL,a*@AA&{I4Eaa4Q4QRR
NN:&&&&^''z::
_((<<
7""r6   keyrequestresponsetimec                 @    |dS |j                             | d          S )Nz(no headers)-headersr.   rJ   rK   rL   rM   s       r5   	_format_izAccessLogger._format_ix   s(     ?!> ""3,,,r6   c                 8    |j                             | d          S NrO   rP   rR   s       r5   	_format_ozAccessLogger._format_o   s    
 ##C---r6   c                 $    | dS | j         }||ndS rU   )remote)rK   rL   rM   ips       r5   	_format_azAccessLogger._format_a   s!    ?3^^rr,r6   c                     t          j        t          j        t          j                             }t           j                             |          }|t          j        |          z
  }|                    d          S )N)secondsz[%d/%b/%Y:%H:%M:%S %z])datetimetimezone	timedeltatime_modnowstrftime)rK   rL   rM   tzra   
start_times         r5   	_format_tzAccessLogger._format_t   si    x18;L:LMMMNN##B''8-d;;;;
""#;<<<r6   c                 .    dt          j                    z  S )Nz<%s>)osgetpidrK   rL   rM   s      r5   	_format_PzAccessLogger._format_P   s    	##r6   c                 v    | dS d                     | j        | j        | j        j        | j        j                  S )NrO   z{} {} HTTP/{}.{})formatmethodpath_qsversionmajorminorri   s      r5   	_format_rzAccessLogger._format_r   s>    ?3!((NOO!O!	
 
 	
r6   c                     |j         S N)statusri   s      r5   	_format_szAccessLogger._format_s   s
    r6   c                     |j         S rt   )body_lengthri   s      r5   	_format_bzAccessLogger._format_b   s    ##r6   c                 :    t          t          |                    S rt   strroundri   s      r5   	_format_TzAccessLogger._format_T   s    5;;r6   c                     d|z  S )Nz%06f ri   s      r5   
_format_TfzAccessLogger._format_Tf   s    }r6   c                 @    t          t          |dz                      S )Ni@B r{   ri   s      r5   	_format_DzAccessLogger._format_D   s    5(()))r6   c                 2    fd| j         D             S )Nc                 4    g | ]\  }}| |          fS r   r   ).0rJ   rm   rK   rL   rM   s      r5   
<listcomp>z-AccessLogger._format_line.<locals>.<listcomp>   s0    XXX;3ffWh556XXXr6   )r1   )r2   rK   rL   rM   s    ```r5   _format_linezAccessLogger._format_line   s*     YXXXXX$-XXXXr6   c                 J    | j                             t          j                  S )zCheck if logger is enabled.)r(   isEnabledForloggingINFO)r2   s    r5   enabledzAccessLogger.enabled   s     {''555r6   c                    	 |                      |||          }t                      }t                      }|D ]S\  }}|                    |           |j        t
          u r|||<   .|\  }	}
|                    |	i           }|||
<   |||	<   T| j                            | j	        t          |          z  |           d S # t          $ r | j                            d           Y d S w xY w)N)extrazError in logging)r   r:   dictrA   r4   r|   r.   r(   infor0   tuple	Exception	exception)r2   rK   rL   rM   fmt_infovaluesr   rJ   valuek1k2dcts               r5   logzAccessLogger.log   s   	6(((DAAHVVFFFE& 	$ 	$
Ue$$$=C''!&E#JJ FB))B++C#CG #E"IIKT-f=UKKKKK 	6 	6 	6K!!"4555555	6s   B:B> >$C&%C&)-__name__
__module____qualname____doc__r=   
LOG_FORMATrecompiler;   rC   r'   r   r|   r	   r   r   __annotations__r   Loggerr-   r/   staticmethodr   r   floatrS   rV   rZ   re   rj   rr   intrv   ry   r~   r   r   r   r   r   propertyboolr   r   __classcell__)r4   s   @r5   r   r      s         6 !!!! N CJ
LM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 Y Y Y
 6 6 6 6 X6
6; 6. 6 6RV 6 6 6 6 6 6 6 6r6   r   )r]   r?   r   rg   r   rM   r`   collectionsr   typingr   r   r   r   r   r	   abcr   web_requestr   web_responser   r   r   r   r6   r5   <module>r      s	         				 				     " " " " " " = = = = = = = = = = = = = = = = % % % % % % $ $ $ $ $ $ ( ( ( ( ( (J{L11	G6 G6 G6 G6 G6' G6 G6 G6 G6 G6r6   