
    *Gj'!                         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 ddlmZ ddlmZ ddlmZ  G d d	e          Z G d
 de          ZdS )    N)Iterable)CallableClassVar
NamedTuple   )AbstractAccessLogger)BaseRequest)StreamResponsec                   P    e Zd ZU eeeef         z  ed<   eeee	gef         ed<   dS )	KeyMethodkeymethodN)
__name__
__module____qualname__strtuple__annotations__r   r	   r
   float     W/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/aiohttp/web_log.pyr   r      sH         	uS#X	k>593>??????r   r   c                       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<   dZeej        dz           ed<   dZee         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j        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f         z  ef                  fd+Z-e.de/fd,            Z0dedededdfd-Z1 xZ2S ).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_CACHEN
_cached_tzg        _cached_tz_expireslogger
log_formatreturnc                     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.

        )r5   N)super__init__r   r1   getcompile_format_log_format_methods)selfr4   r5   _compiled_format	__class__s       r   r9   zAccessLogger.__init__E   sv     	J777'599*EE 	F#22:>>5EL&z2*:'$---r   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)r>   r5   methodsatomformat_key1m
key_methodformat_key2s           r   r;   zAccessLogger.compile_formatU   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""r   r   requestresponsetimec                 @    |dS |j                             | d          S )Nz(no headers)-headersr:   r   rT   rU   rV   s       r   	_format_izAccessLogger._format_i~   s(     ?!> ""3,,,r   c                 8    |j                             | d          S NrX   rY   r[   s       r   	_format_ozAccessLogger._format_o   s    
 ##C---r   c                 $    | dS | j         }||ndS r^   )remote)rT   rU   rV   ips       r   	_format_azAccessLogger._format_a   s!    ?3^^rr,r   c                 
   | j         t          j                    | j        k    rt          j                    j        }t          j        t          j        |                    x| _         }t          j        	                    |          }|t          j        d          z   }|
                    |j        dk    rdnddd          }|                                | _        |S t          j        	                    | j                   S )Nseconds   )minutesr   )minutesecondmicrosecond)r2   time_modrV   r3   	localtime	tm_gmtoffdatetimetimezone	timedeltanowreplaceri   	timestamp)clsgmtofftzrr   ds        r   _get_local_timezAccessLogger._get_local_time   s    >!X]__8N%N%N'))3F"*"3H4Fv4V4V4V"W"WWCNR#''++Ch(4444A		qx2~~1QTU	VVA%&[[]]C"J $$S^444r   c                     t                                           }|t          j        |          z
  }|                    d          S )Nre   z[%d/%b/%Y:%H:%M:%S %z])r   ry   ro   rq   strftime)rT   rU   rV   rr   
start_times        r   	_format_tzAccessLogger._format_t   s@    **,,8-d;;;;
""#;<<<r   c                 .    dt          j                    z  S )Nz<%s>)osgetpidrT   rU   rV   s      r   	_format_PzAccessLogger._format_P   s    	##r   c                 `    | dS | j          d| j         d| j        j         d| j        j         S )NrX    z HTTP/.)r   path_qsversionmajorminorr   s      r   	_format_rzAccessLogger._format_r   s@    ?3.ii7?ii'/:OiiRYRaRgiiir   c                     |j         S N)statusr   s      r   	_format_szAccessLogger._format_s   s
    r   c                     |j         S r   )body_lengthr   s      r   	_format_bzAccessLogger._format_b   s    ##r   c                 :    t          t          |                    S r   r   roundr   s      r   	_format_TzAccessLogger._format_T   s    5;;r   c                     d|z  S )Nz%06fr   r   s      r   
_format_TfzAccessLogger._format_Tf   s    }r   c                 @    t          t          |dz                      S )Ni@B r   r   s      r   	_format_DzAccessLogger._format_D   s    5(()))r   c                 2    fd| j         D             S )Nc                 4    g | ]\  }}| |          fS r   r   ).0r   r   rT   rU   rV   s      r   
<listcomp>z-AccessLogger._format_line.<locals>.<listcomp>   s0    XXX;3ffWh556XXXr   )r=   )r>   rT   rU   rV   s    ```r   _format_linezAccessLogger._format_line   s*     YXXXXX$-XXXXr   c                 J    | j                             t          j                  S )zCheck if logger is enabled.)r4   isEnabledForloggingINFO)r>   s    r   enabledzAccessLogger.enabled   s     {''555r   c                    	 |                      |||          }t                      }t                      }|D ]Z\  }}|                    |           t	          |t
                    r|||<   5|\  }	}
|                    |	i           }|||
<   |||	<   [| j                            | j	        t          |          z  |           d S # t          $ r | j                            d           Y d S w xY w)N)extrazError in logging)r   rD   dictrK   
isinstancer   r:   r4   infor<   r   	Exception	exception)r>   rT   rU   rV   fmt_infovaluesr   r   valuek1k2dcts               r   logzAccessLogger.log   s   	6(((DAAHVVF59VVE& 	$ 	$
Ue$$$c3'' $!&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   CC $C-,C-)3r   r   r   __doc__rG   
LOG_FORMATrecompilerE   rM   r1   r   r   r   rD   r   r   r2   r   ro   rp   r3   r   r   Loggerr9   r;   staticmethodr	   r
   r\   r_   rc   classmethodry   r}   r   r   intr   r   r   r   r   r   r   propertyboolr   r   __classcell__)r@   s   @r   r   r      s         6 !!!! N CJ
LMMIJ''J<>M4U3Y#7889>>>59J*T12999*----AK ; ;w~ ;3 ;PT ; ; ; ; ; ; '# '#sDO7K1L '# '# '# '#R --&-2@-HM-	- - - \- ..&.2@.HM.	. . . \. -; -. - -RU - - - \- 5 1 5 5 5 [5 =; =. = =RU = = = \=
 $; $. $ $RU $ $ $ \$ j; j. j jRU j j j \j
 ; .  RU    \ $; $. $ $RU $ $ $ \$  ;  .    RU       \  K >  SV    \ *; *. * *RU * * * \*Y"Y.<YDIY	%eCHo-s23	4Y Y Y Y
 6 6 6 6 X6
6; 6. 6 6RV 6 6 6 6 6 6 6 6r   r   )ro   rI   r   r   r   rV   rl   collections.abcr   typingr   r   r   abcr   web_requestr	   web_responser
   r   r   r   r   r   <module>r      s         				 				     $ $ $ $ $ $ 1 1 1 1 1 1 1 1 1 1 % % % % % % $ $ $ $ $ $ ( ( ( ( ( (@ @ @ @ @
 @ @ @
S6 S6 S6 S6 S6' S6 S6 S6 S6 S6r   