HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/aiohttp/__pycache__/web_log.cpython-310.pyc
o

���g��@s�ddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
mZmZddlmZddlmZddlmZedd	�ZGd
d�de�ZdS)�N)�
namedtuple)�Any�Callable�Dict�Iterable�List�Tuple�)�AbstractAccessLogger)�BaseRequest)�StreamResponse�	KeyMethodz
key methodcsZeZdZUdZdddddddd	d
ddd
�ZdZe�d�Ze�d�Z	iZ
eee
eeeffed<efdejdeddf�fdd�
Zdede
eeeffdd�Zedededededef
dd��Zedededededef
d d!��Zededededefd"d#��Zededededefd$d%��Zededededefd&d'��Zededededefd(d)��Zededededefd*d+��Z ededededefd,d-��Z!ededededefd.d/��Z"ededededefd0d1��Z#ededededefd2d3��Z$dededede%e
ee&eeegefffd4d5�Z'e(de)fd6d7��Z*dedededdfd8d9�Z+�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�returnNcsDt�j||d�tj�|�}|s|�|�}|tj|<|\|_|_dS)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.

        )r'N)�super�__init__rr%�get�compile_format�_log_format�_methods)�selfr&r'�_compiled_format��	__class__��:/usr/local/lib/python3.10/dist-packages/aiohttp/web_log.pyr*?s

zAccessLogger.__init__cCs�t�}|j�|�D]B}|ddkr'|j|d}ttd|d�}t||�}n|j|d|df}ttd|d�}t|t�||d��}|�	|�q	|j�
d|�}|j�
d|�}||fS)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	�rz
_format_%s�z%sz%\1)�list�	FORMAT_RE�findall�LOG_FORMAT_MAP�getattrrr
�	functools�partial�append�sub�
CLEANUP_RE)r/r'�methods�atom�format_key1�m�
key_method�format_key2r3r3r4r,OszAccessLogger.compile_format�key�request�response�timecCs|durdS|j�|d�S)Nz(no headers)�-��headersr+�rGrHrIrJr3r3r4�	_format_ixszAccessLogger._format_icCs|j�|d�S�NrKrLrNr3r3r4�	_format_o�szAccessLogger._format_ocCs"|durdS|j}|dur|SdSrP)�remote)rHrIrJ�ipr3r3r4�	_format_a�szAccessLogger._format_acCs<t�tjtjd��}tj�|�}|tj|d�}|�d�S)N)�secondsz[%d/%b/%Y:%H:%M:%S %z])�datetime�timezone�	timedelta�time_mod�now�strftime)rHrIrJ�tzrZ�
start_timer3r3r4�	_format_t�s
zAccessLogger._format_tcCsdt��S)Nz<%s>)�os�getpid�rHrIrJr3r3r4�	_format_P��zAccessLogger._format_PcCs(|durdSd�|j|j|jj|jj�S)NrKz{} {} HTTP/{}.{})�format�method�path_qs�version�major�minorrar3r3r4�	_format_r�s�zAccessLogger._format_rcC�|jS�N)�statusrar3r3r4�	_format_s��zAccessLogger._format_scCrkrl)�body_lengthrar3r3r4�	_format_b�rozAccessLogger._format_bcCstt|��Srl��str�roundrar3r3r4�	_format_T�rczAccessLogger._format_TcCsd|S)Nz%06fr3rar3r3r4�
_format_Tf�szAccessLogger._format_TfcCstt|d��S)Ni@Brrrar3r3r4�	_format_D�szAccessLogger._format_Dcs���fdd�|jD�S)Ncs g|]\}}||����f�qSr3r3)�.0rGrerar3r4�
<listcomp>�s z-AccessLogger._format_line.<locals>.<listcomp>)r.)r/rHrIrJr3rar4�_format_line�szAccessLogger._format_linecCs|j�tj�S)zCheck if logger is enabled.)r&�isEnabledFor�logging�INFO)r/r3r3r4�enabled�szAccessLogger.enabledcCs�zE|�|||�}t�}t�}|D]%\}}|�|�|jtur#|||<q|\}	}
|�|	i�}|||
<|||	<q|jj|j	t
|�|d�WdStyU|j�d�YdSw)N)�extrazError in logging)
rzr7�dictr>r2rsr+r&�infor-�tuple�	Exception�	exception)r/rHrIrJ�fmt_info�valuesrrG�value�k1�k2�dctr3r3r4�log�s 



 �zAccessLogger.log)-�__name__�
__module__�__qualname__�__doc__r:�
LOG_FORMAT�re�compiler8r@r%rrsrrr
�__annotations__r|�Loggerr*r,�staticmethodrr�floatrOrQrTr^rbrj�intrnrqrurvrwrrrz�property�boolr~r��
__classcell__r3r3r1r4rs�
�

  )�����	�����
���
�"r)rVr<r|r_r�rJrY�collectionsr�typingrrrrrr�abcr
�web_requestr�web_responserr
rr3r3r3r4�<module>s