
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
U
    'â7`J  ã                   @   s–   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„ deƒZdS )é    N)Ú
namedtuple)ÚAnyÚCallableÚDictÚIterableÚListÚTupleé   )ÚAbstractAccessLogger)ÚBaseRequest)ÚStreamResponseÚ	KeyMethodz
key methodc                       sÒ  e Zd ZdZdddddddd	d
dddœZdZe d¡Ze d¡Z	i Z
efejeddœ‡ fdd„Zeeeee f dœdd„Zeeeeeedœdd„ƒZeeeeeedœdd„ƒZeeeeedœdd„ƒZeeeeedœd d!„ƒZeeeeedœd"d#„ƒZeeeeedœd$d%„ƒZeeeeedœd&d'„ƒZeeeeedœd(d)„ƒZeeeeedœd*d+„ƒZ eeeeedœd,d-„ƒZ!eeeeedœd.d/„ƒZ"eeee#eee$eeegef f  dœd0d1„Z%eeeddœd2d3„Z&‡  Z'S )4Ú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']

    Zremote_addressZrequest_start_timeZ
process_idZfirst_request_lineZresponse_statusZresponse_sizeZrequest_timeZrequest_time_fracZrequest_time_microZrequest_headerZresponse_header)ÚaÚtÚPÚrÚsÚbÚTZTfÚDÚiÚoz/%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"z.%(\{([A-Za-z0-9\-_]+)\}([ioe])|[atPrsbOD]|Tf?)z(%[^s])N)ÚloggerÚ
log_formatÚreturnc                    sD   t ƒ j||d� tj |¡}|s4|  |¡}|tj|< |\| _| _dS )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__r   Ú_FORMAT_CACHEÚgetÚcompile_formatÚ_log_formatÚ_methods)Úselfr   r   Z_compiled_format©Ú	__class__© úB/opt/alt/python38/lib64/python3.8/site-packages/aiohttp/web_log.pyr   >   s    

zAccessLogger.__init__)r   r   c                 C   s¼   t ƒ }| j |¡D ]„}|d dkrN| j|d  }ttd|d  ƒ}t||ƒ}n>| j|d  |d f}ttd|d  ƒ}t|t ||d ¡ƒ}| 	|¡ q| 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#   r   ÚmethodsZatomZformat_key1ÚmZ
key_methodZformat_key2r&   r&   r'   r    N   s    zAccessLogger.compile_format)ÚkeyÚrequestÚresponseÚtimer   c                 C   s   |d krdS |j  | d¡S )Nz(no headers)ú-©Úheadersr   ©r6   r7   r8   r9   r&   r&   r'   Ú	_format_iw   s    zAccessLogger._format_ic                 C   s   |j  | d¡S ©Nr:   r;   r=   r&   r&   r'   Ú	_format_o�   s    zAccessLogger._format_o)r7   r8   r9   r   c                 C   s"   | d krdS | j }|d k	r|S dS r?   )Zremote)r7   r8   r9   Zipr&   r&   r'   Ú	_format_aˆ   s    zAccessLogger._format_ac                 C   s$   t j  ¡ }|t j|d� }| d¡S )N)Úsecondsz[%d/%b/%Y:%H:%M:%S +0000])ÚdatetimeÚutcnowÚ	timedeltaÚstrftime)r7   r8   r9   ÚnowZ
start_timer&   r&   r'   Ú	_format_t�   s    
zAccessLogger._format_tc                 C   s   dt  ¡  S )Nz<%s>)ÚosÚgetpid©r7   r8   r9   r&   r&   r'   Ú	_format_P•   s    zAccessLogger._format_Pc                 C   s(   | d krdS d  | j| j| jj| jj¡S )Nr:   z{} {} HTTP/{}.{})ÚformatÚmethodZpath_qsÚversionÚmajorÚminorrK   r&   r&   r'   Ú	_format_r™   s    üzAccessLogger._format_rc                 C   s   |j S ©N)ÚstatusrK   r&   r&   r'   Ú	_format_s¤   s    zAccessLogger._format_sc                 C   s   |j S rS   )Úbody_lengthrK   r&   r&   r'   Ú	_format_b¨   s    zAccessLogger._format_bc                 C   s   t t|ƒƒS rS   ©ÚstrÚroundrK   r&   r&   r'   Ú	_format_T¬   s    zAccessLogger._format_Tc                 C   s   d| S )Nz%06fr&   rK   r&   r&   r'   Ú
_format_Tf°   s    zAccessLogger._format_Tfc                 C   s   t t|d ƒƒS )Ni@B rX   rK   r&   r&   r'   Ú	_format_D´   s    zAccessLogger._format_Dc                    s   ‡ ‡‡fdd„| j D ƒS )Nc                    s    g | ]\}}||ˆ ˆˆƒf‘qS r&   r&   )Ú.0r6   rN   rK   r&   r'   Ú
<listcomp>»   s     z-AccessLogger._format_line.<locals>.<listcomp>)r"   )r#   r7   r8   r9   r&   rK   r'   Ú_format_line¸   s    zAccessLogger._format_linec                 C   s®   zˆ|   |||¡}tƒ }tƒ }|D ]J\}}| |¡ |jtkrF|||< q |\}	}
| |	i ¡}|||
< |||	< q | jj| j	t
|ƒ |d� W n  tk
r¨   | j d¡ Y nX d S )N)ÚextrazError in logging)r`   r*   Údictr1   r%   rY   r   r   Úinfor!   ÚtupleÚ	ExceptionÚ	exception)r#   r7   r8   r9   Zfmt_infoÚvaluesra   r6   ÚvalueZk1Zk2Údctr&   r&   r'   Úlog½   s    



zAccessLogger.log)(Ú__name__Ú
__module__Ú__qualname__Ú__doc__r-   Z
LOG_FORMATÚreÚcompiler+   r3   r   ÚloggingÚLoggerrY   r   r   r   r   r    Ústaticmethodr   r   Úfloatr>   r@   rA   rH   rL   rR   ÚintrU   rW   r[   r\   r]   r   r   r`   rj   Ú__classcell__r&   r&   r$   r'   r      sr   õ

)   þ	   þ
  þr   )rC   r/   rq   rI   ro   Úcollectionsr   Útypingr   r   r   r   r   r   Úabcr
   Zweb_requestr   Zweb_responser   r   r   r&   r&   r&   r'   Ú<module>   s    
