
    }i!                         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
 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y)    N)
namedtuple)Iterable)CallableClassVarDictListOptionalTuple   )AbstractAccessLogger)BaseRequest)StreamResponse	KeyMethodz
key methodc                   J    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ej*                        ed<   dZee   ed<   efdej2                  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egef   f      fd+Z/e0de1fd,       Z2dedededdfd-Z3 xZ4S ).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                  j	                  |      }|s$| j                  |      }|t        j                  |<   |\  | _        | _        y)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       B/var/www/files/kim/lib/python3.12/site-packages/aiohttp/web_log.pyr0   zAccessLogger.__init__C   sa     	J7'5599*E#22:>5EL&&z2*:'$-    c           	      
   t               }| j                  j                  |      D ]  }|d   dk(  r5| j                  |d      }t	        t
        d|d   z        }t        ||      }nP| j                  |d      |d   f}t	        t
        d|d   z        }t        |t        j                  ||d               }|j                  |        | j                  j                  d|      }| j                  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)r5   r,   methodsatomformat_key1m
key_methodformat_key2s           r8   r2   zAccessLogger.compile_formatS   s    . &NN**:6 
	'DAw"}"11$q':L,a*@A&{A6
#2247;T!WEL,a*@A&{I4E4Eaa4QR
NN:&
	' ^^''z:
__((<
7""r9   keyrequestresponsetimec                 @    |y|j                   j                  | d      S )Nz(no headers)-headersr1   rM   rN   rO   rP   s       r8   	_format_izAccessLogger._format_i|   s%     ?! ""3,,r9   c                 :    |j                   j                  | d      S NrR   rS   rU   s       r8   	_format_ozAccessLogger._format_o   s    
 ##C--r9   c                 ,    | y| j                   }||S dS rX   )remote)rN   rO   rP   ips       r8   	_format_azAccessLogger._format_a   s"    ?^^^r,,r9   c                 2   | j                   !t        j                         | j                  k\  rt        j                         j
                  }t        j                  t        j                  |            x| _         }t        j                  j                  |      }|t        j                  d      z   }|j                  |j                  dk\  rdnddd      }|j                         | _        |S t        j                  j                  | j                         S )Nseconds   )minutesr   )minutesecondmicrosecond)r)   time_modrP   r*   	localtime	tm_gmtoffdatetimetimezone	timedeltanowreplacerc   	timestamp)clsgmtofftzrl   ds        r8   _get_local_timez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4r9   c                 ~    t         j                         }|t        j                  |      z
  }|j	                  d      S )Nr_   z[%d/%b/%Y:%H:%M:%S %z])r   rs   ri   rk   strftime)rN   rO   rP   rl   
start_times        r8   	_format_tzAccessLogger._format_t   s7    **,8--d;;
""#;<<r9   c                 0    dt        j                         z  S )Nz<%s>)osgetpidrN   rO   rP   s      r8   	_format_PzAccessLogger._format_P   s    		##r9   c                     | ydj                  | j                  | j                  | j                  j                  | j                  j
                        S )NrR   z{} {} HTTP/{}.{})formatmethodpath_qsversionmajorminorr{   s      r8   	_format_rzAccessLogger._format_r   sE    ?!((NNOOOO!!OO!!	
 	
r9   c                     |j                   S N)statusr{   s      r8   	_format_szAccessLogger._format_s   s    r9   c                     |j                   S r   )body_lengthr{   s      r8   	_format_bzAccessLogger._format_b   s    ###r9   c                 *    t        t        |            S r   strroundr{   s      r8   	_format_TzAccessLogger._format_T   s    5;r9   c                     d|z  S )Nz%06f r{   s      r8   
_format_TfzAccessLogger._format_Tf   s    }r9   c                 0    t        t        |dz              S )Ni@B r   r{   s      r8   	_format_DzAccessLogger._format_D   s    5())r9   c           
      `    | j                   D cg c]  \  }}| ||||      f c}}S c c}}w r   )r4   )r5   rN   rO   rP   rM   r   s         r8   _format_linezAccessLogger._format_line   s0     KO--X;3fWh56XXXs   *c                 T    | j                   j                  t        j                        S )zCheck if logger is enabled.)r+   isEnabledForloggingINFO)r5   s    r8   enabledzAccessLogger.enabled   s     {{''55r9   c                    	 | j                  |||      }t               }t               }|D ]O  \  }}|j                  |       |j                  t
        u r|||<   /|\  }	}
|j                  |	i       }|||
<   |||	<   Q | j                  j                  | j                  t        |      z  |       y # t        $ r | j                  j                  d       Y y w xY w)N)extrazError in logging)r   r=   dictrD   r7   r   r1   r+   infor3   tuple	Exception	exception)r5   rN   rO   rP   fmt_infovaluesr   rM   valuek1k2dcts               r8   logzAccessLogger.log   s    	6(((DAHVFFE& 	$
Ue$==C'!&E#J FB))B+C#CG #E"I	$ KKT--f=UK 	6KK!!"45	6s   B.B1 1$CC)5__name__
__module____qualname____doc__r@   
LOG_FORMATrecompiler>   rF   r(   r   r   r
   r   r   __annotations__r)   r   r	   ri   rj   r*   floatr   Loggerr0   r2   staticmethodr   r   rV   rY   r]   classmethodrs   rw   r|   r   intr   r   r   r   r   r   r   r   propertyboolr   r   __classcell__)r7   s   @r8   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 6r9   r   )ri   rB   r   ry   r   rP   rf   collectionsr   collections.abcr   typingr   r   r   r   r	   r
   abcr   web_requestr   web_responser   r   r   r   r9   r8   <module>r      sG       	 	  " $ B B % $ ({L1	X6' X6r9   