U
    	f                     @  s~   d dl m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ZdZ	G dd dej
ZG dd	 d	eZG d
d deZdS )    )annotationsN)copy)Literal   c                      s   e Zd ZdZedd ejdd ejdd ejdd ej	dd ej
dd iZdddddd fddZddddddZddddZddd fddZ  ZS )ColourizedFormatterz
    A custom log formatter class that:

    * Outputs the LOG_LEVEL with an appropriate color.
    * If a log call includes an `extras={"color_message": ...}` it will be used
      for formatting the output, instead of the plain text message.
    c                 C  s   t jt| ddS )Nbluefgclickstylestr
level_name r   R/var/www/html/apigroqsegura/apigroq/lib/python3.8/site-packages/uvicorn/logging.py<lambda>       zColourizedFormatter.<lambda>c                 C  s   t jt| ddS )Ncyanr   r
   r   r   r   r   r      r   c                 C  s   t jt| ddS Ngreenr   r
   r   r   r   r   r      r   c                 C  s   t jt| ddS Nyellowr   r
   r   r   r   r   r      r   c                 C  s   t jt| ddS Nredr   r
   r   r   r   r   r      r   c                 C  s   t jt| ddS N
bright_redr   r
   r   r   r   r   r      r   N%z
str | NonezLiteral[('%', '{', '$')]zbool | None)fmtdatefmtr   
use_colorsc                   s2   |dkr|| _ ntj | _ t j|||d d S )N)TF)r   r   r   )r    sysstdoutisattysuper__init__)selfr   r   r   r    	__class__r   r   r%       s    zColourizedFormatter.__init__r   int)r   level_noreturnc                 C  s&   ddddd}| j ||}||S )Nr   )r   r+   c                 S  s   t | S N)r   r   r   r   r   default.   s    z5ColourizedFormatter.color_level_name.<locals>.default)level_name_colorsget)r&   r   r*   r-   funcr   r   r   color_level_name-   s    z$ColourizedFormatter.color_level_nameboolr+   c                 C  s   dS )NTr   r&   r   r   r   should_use_colors4   s    z%ColourizedFormatter.should_use_colorslogging.LogRecordrecordr+   c                   sv   t |}|j}ddt|j  }| jrX| ||j}d|jkrX|jd |_| |jd< |d | |jd< t	 
|S )N    color_messagemessage:Zlevelprefix)r   	levelnamelenr    r1   levelno__dict__msg
getMessager$   formatMessage)r&   r8   
recordcopyr>   Z	seperatorr'   r   r   rD   7   s    
z!ColourizedFormatter.formatMessage)NNr   N)__name__
__module____qualname____doc__TRACE_LOG_LEVELloggingDEBUGINFOWARNINGERRORCRITICALr.   r%   r1   r5   rD   __classcell__r   r   r'   r   r      s,   	          r   c                   @  s   e Zd ZddddZdS )DefaultFormatterr2   r3   c                 C  s
   t j S r,   )r!   stderrr#   r4   r   r   r   r5   E   s    z"DefaultFormatter.should_use_colorsN)rF   rG   rH   r5   r   r   r   r   rR   D   s   rR   c                      sX   e Zd Zdd dd dd dd dd dZdd	d
ddZdd	d fddZ  ZS )AccessFormatterc                 C  s   t jt| ddS )Nbright_whiter   r
   coder   r   r   r   K   r   zAccessFormatter.<lambda>c                 C  s   t jt| ddS r   r
   rV   r   r   r   r   L   r   c                 C  s   t jt| ddS r   r
   rV   r   r   r   r   M   r   c                 C  s   t jt| ddS r   r
   rV   r   r   r   r   N   r   c                 C  s   t jt| ddS r   r
   rV   r   r   r   r   O   r   )            r   r)   r   )status_coder+   c                   sp   zt |j}W n tk
r(   d}Y nX | d|  | jrlddd fdd}| j|d |}| S  S )	N r9   r)   r   )rW   r+   c                   s    S r,   r   rV   Zstatus_and_phraser   r   r-   Z   s    z0AccessFormatter.get_status_code.<locals>.defaultd   )httpZ
HTTPStatusphrase
ValueErrorr    status_code_coloursr/   )r&   r\   Zstatus_phraser-   r0   r   r^   r   get_status_codeR   s    
zAccessFormatter.get_status_coder6   r7   c           	        sn   t |}|j\}}}}}| t|}| d| d| }| jrNtj|dd}|j|||d t	 
|S )Nr9   z HTTP/T)bold)client_addrrequest_liner\   )r   argsrd   r)   r    r   r   rA   updater$   rD   )	r&   r8   rE   rf   method	full_pathhttp_versionr\   rg   r'   r   r   rD   a   s&    zAccessFormatter.formatMessage)rF   rG   rH   rc   rd   rD   rQ   r   r   r'   r   rT   I   s   rT   )
__future__r   r`   rK   r!   r   typingr   r   rJ   	Formatterr   rR   rT   r   r   r   r   <module>   s   6