a
    d                     @   sv   d dl Z d dlZd dlZd dlmZ d dlmZ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 )    N)copy)LiteralOptional   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ee ee ed ee d fddZeeedddZedddZeje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 )NZblueZfgclickstylestr
level_name r   X/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/uvicorn/logging.py<lambda>       zColourizedFormatter.<lambda>c                 C   s   t jt| ddS )NZcyanr   r   r   r   r   r   r      r   c                 C   s   t jt| ddS NZgreenr   r   r   r   r   r   r      r   c                 C   s   t jt| ddS NZyellowr   r   r   r   r   r   r      r   c                 C   s   t jt| ddS NZredr   r   r   r   r   r   r      r   c                 C   s   t jt| ddS NZ
bright_redr   r   r   r   r   r   r      s   N%)r   {$)fmtdatefmtr
   
use_colorsc                    s2   |dv 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   level_noreturnc                 C   s&   t t ddd}| j||}||S )N)r   r%   c                 S   s   t | S N)r   r   r   r   r   default.   s    z5ColourizedFormatter.color_level_name.<locals>.default)r   level_name_colorsget)r!   r   r$   r'   funcr   r   r   color_level_name-   s    z$ColourizedFormatter.color_level_namer%   c                 C   s   dS )NTr   r!   r   r   r   should_use_colors4   s    z%ColourizedFormatter.should_use_colorsrecordr%   c                    sv   t |}|j}ddt|j  }| jrX| ||j}d|jv rX|jd |_| |jd< |d | |jd< t	 
|S )N    Zcolor_messagemessage:Zlevelprefix)r   	levelnamelenr   r+   levelno__dict__msg
getMessager   formatMessage)r!   r0   
recordcopyr5   Z	seperatorr"   r   r   r;   7   s    
z!ColourizedFormatter.formatMessage)NNr   N)__name__
__module____qualname____doc__TRACE_LOG_LEVELloggingDEBUGINFOWARNINGERRORCRITICALr(   r   r   r   boolr    intr+   r.   	LogRecordr;   __classcell__r   r   r"   r   r      s*   	




    r   c                   @   s   e Zd ZedddZdS )DefaultFormatterr,   c                 C   s
   t j S r&   )r   stderrr   r-   r   r   r   r.   E   s    z"DefaultFormatter.should_use_colorsN)r=   r>   r?   rH   r.   r   r   r   r   rL   D   s   rL   c                       sZ   e Zd Zdd dd dd dd dd dZeedd	d
Zejed fddZ	  Z
S )AccessFormatterc                 C   s   t jt| ddS )NZbright_whiter   r   coder   r   r   r   K   r   zAccessFormatter.<lambda>c                 C   s   t jt| ddS r   r   rO   r   r   r   r   L   r   c                 C   s   t jt| ddS r   r   rO   r   r   r   r   M   r   c                 C   s   t jt| ddS r   r   rO   r   r   r   r   N   r   c                 C   s   t jt| ddS r   r   rO   r   r   r   r   O   r   )            r   )status_coder%   c                    sl   zt |j}W n ty&   d}Y n0 d||f  | jrhttd fdd}| j|d |}| S  S )N z%s %s)rP   r%   c                    s    S r&   r   rO   Zstatus_and_phraser   r   r'   Z   s    z0AccessFormatter.get_status_code.<locals>.defaultd   )	http
HTTPStatusphrase
ValueErrorr   rI   r   status_code_coloursr)   )r!   rU   Zstatus_phraser'   r*   r   rW   r   get_status_codeR   s    
zAccessFormatter.get_status_coder/   c           	         sh   t |}|j\}}}}}| t|}d|||f }| jrHtj|dd}|j|||d t	 
|S )Nz%s %s HTTP/%sT)Zbold)client_addrrequest_linerU   )r   argsr^   rI   r   r	   r
   r8   updater   r;   )	r!   r0   r<   r_   method	full_pathhttp_versionrU   r`   r"   r   r   r;   a   s&    zAccessFormatter.formatMessage)r=   r>   r?   r]   rI   r   r^   rB   rJ   r;   rK   r   r   r"   r   rN   I   s   rN   )rY   rB   r   r   typingr   r   r	   rA   	Formatterr   rL   rN   r   r   r   r   <module>   s   8