o
    ]~#g                     @  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# fddZd$ddZd%ddZ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     t jt| ddS )Nbluefgclickstylestr
level_name r   t/var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/uvicorn/logging.py<lambda>       zColourizedFormatter.<lambda>c                 C  r   )Ncyanr	   r   r   r   r   r   r      r   c                 C  r   Ngreenr	   r   r   r   r   r   r      r   c                 C  r   Nyellowr	   r   r   r   r   r   r      r   c                 C  r   Nredr	   r   r   r   r   r   r      r   c                 C  r   N
bright_redr	   r   r   r   r   r   r      r   N%fmt
str | Nonedatefmtr   Literal['%', '{', '$']
use_colorsbool | Nonec                   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   r   level_nointreturnc                 C  s    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)r   r   r/   r   )level_name_colorsget)r*   r   r-   r1   funcr   r   r   color_level_name-   s   
z$ColourizedFormatter.color_level_nameboolc                 C  s   dS )NTr   r*   r   r   r   should_use_colors4      z%ColourizedFormatter.should_use_colorsrecordlogging.LogRecordc                   sv   t |}|j}ddt|j  }| jr,| ||j}d|jv r,|jd |_| |jd< |d | |jd< t	 
|S )N    color_messagemessage:levelprefix)r   	levelnamelenr#   r5   levelno__dict__msg
getMessager(   formatMessage)r*   r:   
recordcopyrB   	seperatorr+   r   r   rH   7   s   
z!ColourizedFormatter.formatMessage)NNr   N)r   r    r!   r    r   r"   r#   r$   )r   r   r-   r.   r/   r   r/   r6   r:   r;   r/   r   )__name__
__module____qualname____doc__TRACE_LOG_LEVELloggingDEBUGINFOWARNINGERRORCRITICALr2   r)   r5   r8   rH   __classcell__r   r   r+   r   r      s"    	






r   c                   @  s   e Zd ZdddZdS )DefaultFormatterr/   r6   c                 C  s
   t j S r0   )r%   stderrr'   r7   r   r   r   r8   E   s   
z"DefaultFormatter.should_use_colorsNrK   )rM   rN   rO   r8   r   r   r   r   rY   D   s    rY   c                      sL   e Zd Zdd dd dd dd dd dZdddZd fddZ  ZS )AccessFormatterc                 C  r   )Nbright_whiter	   r   coder   r   r   r   K   r   zAccessFormatter.<lambda>c                 C  r   r   r   r]   r   r   r   r   L   r   c                 C  r   r   r   r]   r   r   r   r   M   r   c                 C  r   r   r   r]   r   r   r   r   N   r   c                 C  r   r   r   r]   r   r   r   r   O   r   )            r   status_coder.   r/   r   c                   sh   zt |j}W n ty   d}Y nw | d|  | jr2d
 fdd}| j|d	 |}| S  S )N r<   r^   r.   r/   r   c                   s    S r0   r   r]   status_and_phraser   r   r1   Z   r9   z0AccessFormatter.get_status_code.<locals>.defaultd   )r^   r.   r/   r   )http
HTTPStatusphrase
ValueErrorr#   status_code_coloursr3   )r*   rc   status_phraser1   r4   r   re   r   get_status_codeR   s   zAccessFormatter.get_status_coder:   r;   c           	        sn   t |}|j\}}}}}| t|}| d| d| }| jr'tj|dd}|j|||d t	 
|S )Nr<   z HTTP/T)bold)client_addrrequest_linerc   )r   argsrn   r.   r#   r   r   rE   updater(   rH   )	r*   r:   rI   rp   method	full_pathhttp_versionrc   rq   r+   r   r   rH   a   s&   zAccessFormatter.formatMessage)rc   r.   r/   r   rL   )rM   rN   rO   rl   rn   rH   rX   r   r   r+   r   r[   I   s    
r[   )
__future__r   rh   rR   r%   r   typingr   r   rQ   	Formatterr   rY   r[   r   r   r   r   <module>   s    6