
    9Cg                        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ej
                  Z G d d	e          Z G d
 de          ZdS )    )annotationsN)copy)Literal   c                       e Zd ZdZed ej        d ej        d ej        d ej	        d ej
        d iZ	 	 	 	 dd fdZddZd dZd! fdZ x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                H    t          j        t          |           d          S )Nbluefgclickstylestr
level_names    A/var/www/api/venv/lib/python3.11/site-packages/uvicorn/logging.py<lambda>zColourizedFormatter.<lambda>   s    EKJF,S,S,S     c                H    t          j        t          |           d          S )Ncyanr   r   r   s    r   r   zColourizedFormatter.<lambda>   s    %+c*oo&*Q*Q*Q r   c                H    t          j        t          |           d          S Ngreenr   r   r   s    r   r   zColourizedFormatter.<lambda>   s    S__)Q)Q)Q r   c                H    t          j        t          |           d          S Nyellowr   r   r   s    r   r   zColourizedFormatter.<lambda>   s    EKJH,U,U,U r   c                H    t          j        t          |           d          S Nredr   r   r   s    r   r   zColourizedFormatter.<lambda>   s    %+c*oo%*P*P*P r   c                H    t          j        t          |           d          S N
bright_redr   r   r   s    r   r   zColourizedFormatter.<lambda>   s    U[Z\-Z-Z-Z r   N%fmt
str | Nonedatefmtr   Literal['%', '{', '$']
use_colorsbool | Nonec                    |dv r|| _         n#t          j                                        | _         t	                                          |||           d S )N)TF)r%   r'   r   )r)   sysstdoutisattysuper__init__)selfr%   r'   r   r)   	__class__s        r   r0   zColourizedFormatter.__init__    sS     &&(DOO!j//11DOS'?????r   r   r   level_nointreturnc                V    dd}| j                             ||          } ||          S )Nr   r   r5   c                     t          |           S N)r   r   s    r   defaultz5ColourizedFormatter.color_level_name.<locals>.default.   s    z??"r   )r   r   r5   r   )level_name_colorsget)r1   r   r3   r9   funcs        r   color_level_namez$ColourizedFormatter.color_level_name-   s@    	# 	# 	# 	# %))(G<<tJr   boolc                    dS )NT r1   s    r   should_use_colorsz%ColourizedFormatter.should_use_colors4   s    tr   recordlogging.LogRecordc                x   t          |          }|j        }ddt          |j                  z
  z  }| j        rR|                     ||j                  }d|j        v r.|j        d         |_        |                                |j        d<   |dz   |z   |j        d<   t                      
                    |          S )N    color_messagemessage:levelprefix)r   	levelnamelenr)   r=   levelno__dict__msg
getMessager/   formatMessage)r1   rC   
recordcopyrL   	seperatorr2   s        r   rR   z!ColourizedFormatter.formatMessage7   s    &\\
(	1s:#78889	? 	I--i9KLLI*"555!+!4_!E
1;1F1F1H1H
#I.-6_y-H
M*ww$$Z000r   )NNr$   N)r%   r&   r'   r&   r   r(   r)   r*   )r   r   r3   r4   r5   r   r5   r>   rC   rD   r5   r   )__name__
__module____qualname____doc__TRACE_LOG_LEVELloggingDEBUGINFOWARNINGERRORCRITICALr:   r0   r=   rB   rR   __classcell__r2   s   @r   r   r      s          	SSQQQQUUPPZZ "(+"&@ @ @ @ @ @ @          
1 
1 
1 
1 
1 
1 
1 
1 
1 
1r   r   c                      e Zd ZddZdS )DefaultFormatterr5   r>   c                >    t           j                                        S r8   )r,   stderrr.   rA   s    r   rB   z"DefaultFormatter.should_use_colorsE   s    z  """r   NrU   )rW   rX   rY   rB   r@   r   r   re   re   D   s(        # # # # # #r   re   c                  B     e Zd Zd d d d d dZddZd fdZ xZS )AccessFormatterc                H    t          j        t          |           d          S )Nbright_whiter   r   codes    r   r   zAccessFormatter.<lambda>K   s    CII.AAA r   c                H    t          j        t          |           d          S r   r   rl   s    r   r   zAccessFormatter.<lambda>L   s    CII'::: r   c                H    t          j        t          |           d          S r   r   rl   s    r   r   zAccessFormatter.<lambda>M   s    CII(;;; r   c                H    t          j        t          |           d          S r   r   rl   s    r   r   zAccessFormatter.<lambda>N   s    CII%888 r   c                H    t          j        t          |           d          S r"   r   rl   s    r   r   zAccessFormatter.<lambda>O   s    CII,??? r   )            r   status_coder4   r5   r   c                    	 t          j        |          j        }n# t          $ r d}Y nw xY w| d| | j        r/d	fd}| j                            |dz  |          } |          S S )
N rF   rm   r4   r5   r   c                    S r8   r@   )rm   status_and_phrases    r   r9   z0AccessFormatter.get_status_code.<locals>.defaultZ   s	    ((r   d   )rm   r4   r5   r   )http
HTTPStatusphrase
ValueErrorr)   status_code_coloursr;   )r1   rv   status_phraser9   r<   rz   s        @r   get_status_codezAccessFormatter.get_status_codeR   s    	 OK88?MM 	 	 	MMM	*<<]<<? 	+) ) ) ) ) ) +//s0BGLLD4)***  s    ,,rC   rD   c                L   t          |          }|j        \  }}}}}|                     t          |                    }| d| d| }| j        rt          j        |d          }|j                            |||d           t                      
                    |          S )NrF   z HTTP/T)bold)client_addrrequest_linerv   )r   argsr   r4   r)   r   r   rO   updater/   rR   )
r1   rC   rS   r   method	full_pathhttp_versionrv   r   r2   s
            r   rR   zAccessFormatter.formatMessagea   s    &\\
 O	
**3{+;+;<< BB9BBLBB? 	@ ;|$???L""* ,* 	
 	
 	
 ww$$Z000r   )rv   r4   r5   r   rV   )rW   rX   rY   r   r   rR   rb   rc   s   @r   ri   ri   I   s|        AA::;;88?? ! ! ! !1 1 1 1 1 1 1 1 1 1r   ri   )
__future__r   r|   r\   r,   r   typingr   r   r[   	Formatterr   re   ri   r@   r   r   <module>r      s    " " " " " "   



             31 31 31 31 31'+ 31 31 31l# # # # #* # # #
,1 ,1 ,1 ,1 ,1) ,1 ,1 ,1 ,1 ,1r   