o
    jN1                  	   @  s  d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
mZmZmZmZmZmZ e
rPddlmZ dd	lmZmZ dd
lmZ ddlmZ d dlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! G dd deZ"e#dkrd dl$m%Z% dZ&ej'de&de"dddgd e(dZ)e)*d e)*d e%d e)*d e)*d e)*d  e)+d! e%d e),d"d#d$g d%d&gd'd(d#ddd'd) e),d* e)-d+ e)*d, e)*d- e)+d. d8d1d2Z.e.  e%d e)/d3 e)*d4 e)j*d5e0dd6d7 dS dS )9    )annotationsN)datetime)Handler	LogRecord)
ModuleType)TYPE_CHECKINGClassVarIterableListOptionalTypeUnion   )FormatTimeCallable)ConsoleConsoleRenderable)Highlighter	Traceback)NullFile)get_console)	LogRender)ReprHighlighter)Textc                      s   e Zd ZU dZg dZded< eZded< ej	dfddddddd	d	dd
dddd	ddddddddG fd4d5Z
dHd9d:ZdId;d<ZdJd@dAZdKdEdFZ  ZS )LRichHandlera  A logging handler that renders output with Rich. The time / level / message and file are displayed in columns.
    The level is color coded, and the message is syntax highlighted.

    Note:
        Be careful when enabling console markup in log messages if you have configured logging for libraries not
        under your control. If a dependency writes messages containing square brackets, it may not produce the intended output.

    Args:
        level (Union[int, str], optional): Log level. Defaults to logging.NOTSET.
        console (:class:`~rich.console.Console`, optional): Optional console instance to write logs.
            Default will use a global console instance writing to stdout.
        show_time (bool, optional): Show a column for the time. Defaults to True.
        omit_repeated_times (bool, optional): Omit repetition of the same time. Defaults to True.
        show_level (bool, optional): Show a column for the level. Defaults to True.
        show_path (bool, optional): Show the path to the original log call. Defaults to True.
        enable_link_path (bool, optional): Enable terminal link of path column to file. Defaults to True.
        highlighter (Highlighter, optional): Highlighter to style log messages, or None to use ReprHighlighter. Defaults to None.
        markup (bool, optional): Enable console markup in log messages. Defaults to False.
        rich_tracebacks (bool, optional): Enable rich tracebacks with syntax highlighting and formatting. Defaults to False.
        tracebacks_width (Optional[int], optional): Number of characters used to render tracebacks, or None for full width. Defaults to None.
        tracebacks_code_width (int, optional): Number of code characters used to render tracebacks, or None for full width. Defaults to 88.
        tracebacks_extra_lines (int, optional): Additional lines of code to render tracebacks, or None for full width. Defaults to None.
        tracebacks_theme (str, optional): Override pygments theme used in traceback.
        tracebacks_word_wrap (bool, optional): Enable word wrapping of long tracebacks lines. Defaults to True.
        tracebacks_show_locals (bool, optional): Enable display of locals in tracebacks. Defaults to False.
        tracebacks_suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
        tracebacks_max_frames (int, optional): Optional maximum number of frames returned by traceback.
        locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to 10.
        locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
        log_time_format (Union[str, TimeFormatterCallable], optional): If ``log_time`` is enabled, either string for strftime or callable that formats the time. Defaults to "[%x %X] ".
        keywords (List[str], optional): List of words to highlight instead of ``RichHandler.KEYWORDS``.
    )GETPOSTHEADPUTDELETEOPTIONSTRACEPATCHzClassVar[Optional[List[str]]]KEYWORDSzClassVar[Type[Highlighter]]HIGHLIGHTER_CLASSNTFX       d   
   P   z[%x %X])	show_timeomit_repeated_times
show_level	show_pathenable_link_pathhighlightermarkuprich_tracebackstracebacks_widthtracebacks_code_widthtracebacks_extra_linestracebacks_themetracebacks_word_wraptracebacks_show_localstracebacks_suppresstracebacks_max_frameslocals_max_lengthlocals_max_stringlog_time_formatkeywordslevelUnion[int, str]consoleOptional[Console]r+   boolr,   r-   r.   r/   r0   Optional[Highlighter]r1   r2   r3   Optional[int]r4   r5   intr6   Optional[str]r7   r8   r9    Iterable[Union[str, ModuleType]]r:   r;   r<   r=   Union[str, FormatTimeCallable]r>   Optional[List[str]]returnNonec                  s   t  j|d |pt | _|p|  | _t|||||d d| _|| _|	| _	|
| _
|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _d S )N)r?   )r+   r-   r.   time_formatr,   level_width)super__init__r   rA   r$   r0   r   _log_renderr/   r1   r2   r3   r5   r6   r7   r8   r9   r:   r4   r;   r<   r>   )selfr?   rA   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   	__class__r'   R/var/www/html/fyndo/pharma/fyndo/venv/lib/python3.10/site-packages/rich/logging.pyrP   G   s2   
zRichHandler.__init__recordr   r   c                 C  s&   |j }t|dd|  }|S )zGet the level name from the record.

        Args:
            record (LogRecord): LogRecord instance.

        Returns:
            Text: A tuple of the style and level name.
           zlogging.level.)	levelnamer   styledljustlower)rR   rV   
level_name
level_textr'   r'   rU   get_level_text{   s
   	zRichHandler.get_level_textc                 C  s@  |  |}d}| jrk|jrk|jdkrk|j\}}}|dusJ |dus$J ddlm} |j|||| j| j| j| j	| j
| j| j| j| j| jd}| }| jrk| |_| j}t|drf| rf|||j|_||}| ||}	| j|||	d}
t| jjtr| | dS z	| j |
 W dS  t!y   | | Y dS w )zInvoked by logging.N)NNNr   r   )
width
code_widthextra_linestheme	word_wrapshow_localsr;   r<   suppress
max_framesusesTime)rV   	tracebackmessage_renderable)"formatr2   exc_inforh   r   from_exceptionr3   r4   r5   r6   r7   r8   r;   r<   r9   r:   
getMessage	formattermessagehasattrrg   
formatTimedatefmtasctimeformatMessagerender_messagerender
isinstancerA   filer   handleErrorprint	Exception)rR   rV   ro   rh   exc_type	exc_valueexc_tracebackr   rn   ri   log_renderabler'   r'   rU   emit   sX   



zRichHandler.emitro   strr   c                 C  sh   t |d| j}|rt|nt|}t |d| j}|r||}| jdu r(| j| _| jr2|| jd |S )zRender message text in to Text.

        Args:
            record (LogRecord): logging Record.
            message (str): String containing log message.

        Returns:
            ConsoleRenderable: Renderable to display log message.
        r1   r0   Nzlogging.keyword)getattrr1   r   from_markupr0   r>   r#   highlight_words)rR   rV   ro   
use_markupmessage_textr0   r'   r'   rU   ru      s   

zRichHandler.render_messagerh   Optional[Traceback]ri   c          	   
   C  sv   t j|j}| |}| jdu rdn| jj}t|j	}| j
| j|s&|gn||g|||||j| jr5|jndd}|S )av  Render log for display.

        Args:
            record (LogRecord): logging Record.
            traceback (Optional[Traceback]): Traceback instance or None for no Traceback.
            message_renderable (ConsoleRenderable): Renderable (typically Text) containing log message contents.

        Returns:
            ConsoleRenderable: Renderable to display log.
        N)log_timerM   r?   pathline_no	link_path)osr   basenamepathnamer^   rn   rr   r   fromtimestampcreatedrQ   rA   linenor/   )	rR   rV   rh   ri   r   r?   rM   r   r   r'   r'   rU   rv      s   

zRichHandler.render).r?   r@   rA   rB   r+   rC   r,   rC   r-   rC   r.   rC   r/   rC   r0   rD   r1   rC   r2   rC   r3   rE   r4   rE   r5   rF   r6   rG   r7   rC   r8   rC   r9   rH   r:   rF   r;   rF   r<   rF   r=   rI   r>   rJ   rK   rL   )rV   r   rK   r   )rV   r   rK   rL   )rV   r   ro   r   rK   r   )rV   r   rh   r   ri   r   rK   r   )__name__
__module____qualname____doc__r#   __annotations__r   r$   loggingNOTSETrP   r^   r   ru   rv   __classcell__r'   r'   rS   rU   r      s@   
 "

4

4r   __main__)sleepz%(message)sr   z[%X]T)r2   r8   )r?   rj   rr   handlersrichzServer starting...z"Listening on http://127.0.0.1:8080zGET /index.html 200 1298z)GET /imgs/backgrounds/back1.jpg 200 54386zGET /css/styles.css 200 54386zGET /favicon.ico 404 242zJSONRPC request
--> %r
<-- %rz1.1confirmFruitPurchase)appleorangemangoespomelog+?	194521489)versionmethodparamsid)r   resulterrorr   zrLoading configuration file /adasd/asdasd/qeqwe/qwrqwrqwr/sdgsdgsdg/werwerwer/dfgerert/ertertert/ertetert/werwerwerz$Unable to find 'pomelo' in database!zPOST /jsonrpc/ 200 65532zPOST /admin/ 401 42234z%password was rejected for admin site.rK   rL   c                  C  sB   d} d}dgd }t d z| |  W d S    t d Y d S )Nr   r   foor(   z	in dividezAn error of some kind occurred!)logdebug	exception)numberdivisorfoosr'   r'   rU   divide#  s   

r   zOut of memory!zServer exited with code=-1z[bold]EXITING...[/bold])r1   )extra)rK   rL   )1
__future__r   r   r   r   r   r   typesr   typingr   r   r	   r
   r   r   r   rQ   r   rA   r   r   r0   r   rh   r   rich._null_filer    r   r   r   textr   r   r   timer   FORMATbasicConfig	getLoggerr   infowarningr   r   r   criticaldictr'   r'   r'   rU   <module>   sx    $ 
c
















