Ë
    Eü´j'!  ã                   ó¤   — 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y)é    N)ÚIterable)ÚCallableÚClassVarÚ
NamedTupleé   )ÚAbstractAccessLogger)ÚBaseRequest)ÚStreamResponsec                   óB   — e Zd ZU eeeef   z  ed<   eeee	gef   ed<   y)Ú	KeyMethodÚkeyÚmethodN)
Ú__name__Ú
__module__Ú__qualname__ÚstrÚtupleÚ__annotations__r   r	   r
   Úfloat© ó    úM/root/workspace/ytshorts/venv/lib/python3.12/site-packages/aiohttp/web_log.pyr   r      s,   … Ø	ˆu�S˜#�X‰Ñ	ÓØ�k >°5Ð9¸3Ð>Ñ?Ô?r   r   c                   ó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j(                  dz     ed<   dZee   ed<   efdej0                  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                  j	                  |«      }|s$| j                  |«      }|t        j                  |<   |\  | _        | _        y)z©Initialise 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   sa   ø€ ô 	‰Ñ˜¨JÐÔ7ä'×5Ñ5×9Ñ9¸*ÓEÐÙØ#×2Ñ2°:Ó>ÐØ5EŒL×&Ñ& zÑ2à*:Ñ'ˆÔ˜$�-r   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)r>   r5   ÚmethodsÚatomÚformat_key1ÚmÚ
key_methodÚformat_key2s           r   r;   zAccessLogger.compile_formatU   sý   € ô. “&ˆà—N‘N×*Ñ*¨:Ó6ò 
	'ˆDØ�A‰w˜"Š}Ø"×1Ñ1°$°q±'Ñ:�ÜœL¨,¸¸a¹Ñ*@ÓA�Ü& {°AÓ6‘
à#×2Ñ2°4¸±7Ñ;¸TÀ!¹WÐE�ÜœL¨,¸¸a¹Ñ*@ÓA�Ü& {´I×4EÑ4EÀaÈÈaÉÓ4QÓR�
à�N‰N˜:Õ&ð
	'ð —^‘^×'Ñ'¨¨zÓ:ˆ
Ø—_‘_×(Ñ(¨°Ó<ˆ
Ø˜7Ð"Ð"r   r   ÚrequestÚresponseÚtimec                 ó@   — |€y|j                   j                  | d«      S )Nz(no headers)ú-©Úheadersr:   ©r   rT   rU   rV   s       r   Ú	_format_izAccessLogger._format_i~   s%   € ð ˆ?Ø!ð �‰×"Ñ" 3¨Ó,Ð,r   c                 ó:   — |j                   j                  | d«      S ©NrX   rY   r[   s       r   Ú	_format_ozAccessLogger._format_oˆ   s   € ð
 ×Ñ×#Ñ# C¨Ó-Ð-r   c                 ó,   — | €y| j                   }|�|S dS r^   )Úremote)rT   rU   rV   Úips       r   Ú	_format_azAccessLogger._format_a�   s"   € àˆ?ØØ�^‰^ˆØ�^ˆrÐ,¨Ð,r   c                 ó2  — | j                   �!t        j                  «       | j                  k\  rÂt        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)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Ñ8NÒ%NÜ×'Ñ'Ó)×3Ñ3ˆFÜ"*×"3Ñ"3´H×4FÑ4FÈvÔ4VÓ"WÐWˆCŒN˜Rä×#Ñ#×'Ñ'¨Ó+ˆCà”h×(Ñ(°Ô4Ñ4ˆAØ—	‘	 q§x¡x°2¢~¡¸1ÀQÐTU�	ÓVˆAØ%&§[¡[£]ˆCÔ"ØˆJä× Ñ ×$Ñ$ S§^¡^Ó4Ð4r   c                 ó~   — t         j                  «       }|t        j                  |¬«      z
  }|j	                  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¥   s7   € ä×*Ñ*Ó,ˆØœ8×-Ñ-°dÔ;Ñ;ˆ
Ø×"Ñ"Ð#;Ó<Ð<r   c                 ó0   — dt        j                  «       z  S )Nz<%s>)ÚosÚgetpid©rT   rU   rV   s      r   Ú	_format_PzAccessLogger._format_P«   s   € àœŸ	™	›Ñ#Ð#r   c                 óš   — | €y| 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¯   sK   € àˆ?ØØ—.‘.Ð!  7§?¡?Ð"3°6¸'¿/¹/×:OÑ:OÐ9PÐPQÐRY×RaÑRa×RgÑRgÐQhÐ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                 ó0   — t        t        |dz  «      «      S )Ni@B r“   r�   s      r   Ú	_format_DzAccessLogger._format_DÅ   s   € ä”5˜ ™Ó(Ó)Ð)r   c           
      ó`   — | j                   D ��cg c]  \  }}| ||||«      f‘Œ c}}S c c}}w rŒ   )r=   )r>   rT   rU   rV   r   r   s         r   Ú_format_linezAccessLogger._format_lineÉ   s0   € ð KOÏ-É-×X¹;¸3À�‘f˜W h°Ó5Ò6ÓXÐXùÓXs   �*c                 óT   — | j                   j                  t        j                  «      S )zCheck if logger is enabled.)r4   ÚisEnabledForÚloggingÚINFO)r>   s    r   ÚenabledzAccessLogger.enabledÎ   s   € ð �{‰{×'Ñ'¬¯©Ó5Ð5r   c                 ó²  — 	 | j                  |||«      }t        «       }t        «       }|D ]M  \  }}|j                  |«       t	        |t
        «      r|||<   Œ-|\  }	}
|j                  |	i «      }|||
<   |||	<   ŒO | j                  j                  | j                  t        |«      z  |¬«       y # t        $ r | j                  j                  d«       Y y 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ˆHä“VˆFÜ59³VˆEØ&ò 	$‘
��UØ—‘˜eÔ$ä˜c¤3Ô'Ø!&�E˜#’Jà ‘F�B˜Ø*/¯)©)°B¸Ó*;�CØ#�C˜‘GØ #�E˜"’Ið	$ð �K‰K×Ñ˜T×-Ñ-´°f³Ñ=ÀUÐÕKøÜò 	6Ø�K‰K×!Ñ!Ð"4Ö5ð	6ús   ‚B,B/ Â/$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€IØ�—‘˜JÓ'€JØ<>€M�4˜˜U 3¨¨Y©Ð#7Ñ8Ð8Ñ9Ó>à59€J�˜×*Ñ*¨TÑ1Ñ2Ó9Ø*-Ð˜ ™Ó-àAKñ ;˜wŸ~™~ð ;¸3ð ;ÐPTõ ;ð '#¨ð '#°°s¸DÀ¹OÐ7KÑ1Ló '#ðR ð-Øð-Ø&ð-Ø2@ð-ØHMð-à	ò-ó ð-ð ð.Øð.Ø&ð.Ø2@ð.ØHMð.à	ò.ó ð.ð ð-˜;ð -°.ð -Èð -ÐRUò -ó ð-ð ð5 × 1Ñ 1ò 5ó ð5ð ð=˜;ð =°.ð =Èð =ÐRUò =ó ð=ð
 ð$˜;ð $°.ð $Èð $ÐRUò $ó ð$ð ðj˜;ð j°.ð jÈð jÐRUò jó ðjð
 ð˜;ð °.ð Èð ÐRUò ó ðð ð$˜;ð $°.ð $Èð $ÐRUò $ó ð$ð ð ˜;ð  °.ð  Èð  ÐRUò  ó ð ð ð˜Kð °>ð Èð ÐSVò ó ðð ð*˜;ð *°.ð *Èð *ÐRUò *ó ð*ðYØ"ðYØ.<ðYØDIðYà	�%˜˜e C¨ H™oÑ-¨sÐ2Ñ3Ñ	4óYð
 ð6˜ò 6ó ð6ð
6˜;ð 6°.ð 6Èð 6ÐRV÷ 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¿      sF   ðÛ Û Û Û 	Û 	Û Ý $ß 1Ñ 1å %Ý $Ý (ô@�
ô @ô
S6Ð'õ S6r   