a
    |Ä#d´  ã                   @   sÄ   d dl mZmZmZmZmZmZ er0d dlmZ ddl	m
Z
 ddlmZ ddlmZ erdd dlmZ dZG dd	„ d	ƒZG d
d„ dƒZee edœdd„Zee eddœdd„Zeeddœdd„ZdS )é    )ÚTYPE_CHECKINGÚAnyÚDictÚIterableÚListÚSequence)ÚConsoleRenderableé   )Úget_console)ÚSegment)ÚDEFAULT_TERMINAL_THEMEz“<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace">{code}</pre>
c                   @   sF   e Zd ZdZeeddœdd„Zee ee eeeef dœdd„Z	dS )	ÚJupyterRenderablez)A shim to write html to Jupyter notebook.N)ÚhtmlÚtextÚreturnc                 C   s   || _ || _d S )N)r   r   )Úselfr   r   © r   úO/var/www/html/gsl.tools/lib/python3.9/site-packages/pip/_vendor/rich/jupyter.pyÚ__init__   s    zJupyterRenderable.__init__)ÚincludeÚexcludeÚkwargsr   c                    sF   | j | jdœ}ˆr(‡fdd„| ¡ D ƒ}ˆ rB‡ fdd„| ¡ D ƒ}|S )N©z
text/plainz	text/htmlc                    s   i | ]\}}|ˆ v r||“qS r   r   ©Ú.0ÚkÚv©r   r   r   Ú
<dictcomp>   ó    z7JupyterRenderable._repr_mimebundle_.<locals>.<dictcomp>c                    s   i | ]\}}|ˆ vr||“qS r   r   r   ©r   r   r   r       r   )r   r   Úitems)r   r   r   r   Údatar   ©r   r   r   Ú_repr_mimebundle_   s    z#JupyterRenderable._repr_mimebundle_)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r$   r   r   r   r   r      s
   
þr   c                   @   s:   e Zd ZdZdZdee ee eeeef dœdd„Z	dS )ÚJupyterMixinz@Add to an Rich renderable to make it render in Jupyter notebook.r   r   )r   r   r   r   r   c           	         sl   t ƒ }t| | |j¡ƒ}t|ƒ}| |¡}||dœ}ˆrN‡fdd„| ¡ D ƒ}ˆ rh‡ fdd„| ¡ D ƒ}|S )Nr   c                    s   i | ]\}}|ˆ v r||“qS r   r   r   r   r   r   r   5   r   z2JupyterMixin._repr_mimebundle_.<locals>.<dictcomp>c                    s   i | ]\}}|ˆ vr||“qS r   r   r   r    r   r   r   7   r   )r
   ÚlistÚrenderÚoptionsÚ_render_segmentsÚ_render_bufferr!   )	r   r   r   r   ÚconsoleÚsegmentsr   r   r"   r   r#   r   r$   )   s    

zJupyterMixin._repr_mimebundle_N)
r%   r&   r'   r(   Ú	__slots__r   r)   r   r   r$   r   r   r   r   r*   $   s   
ûr*   )r1   r   c                 C   s¦   t t dœdd„}g }|j}t}t | ¡D ]b\}}}|r8q(||ƒ}|r‚| |¡}|rdd|› d|› d�n|}|jr‚d|j› d|› d	�}||ƒ q(d
 |¡}	tj	|	d�}
|
S )N)r   r   c                 S   s   |   dd¡  dd¡  dd¡S )zEscape html.ú&z&amp;ú<z&lt;ú>z&gt;)Úreplace)r   r   r   r   Úescape<   s    z _render_segments.<locals>.escapez<span style="z">z</span>z	<a href="z" target="_blank">z</a>Ú )Úcode)
r)   Úappendr   r   ÚsimplifyÚget_html_styleÚlinkÚjoinÚJUPYTER_HTML_FORMATÚformat)r1   r7   Ú	fragmentsÚappend_fragmentÚthemer   ÚstyleÚcontrolÚruler9   r   r   r   r   r.   ;   s"    


r.   N)r1   r   r   c                 C   sB   t | ƒ}t||ƒ}zddlm} ||ƒ W n ty<   Y n0 dS )zRender segments to Jupyter.r   )ÚdisplayN)r.   r   ÚIPython.displayrG   ÚModuleNotFoundError)r1   r   r   Újupyter_renderableÚipython_displayr   r   r   rG   T   s    
rG   )Úargsr   r   c                  O   s   t ƒ }|j| i |¤ŽS )zProxy for Console print.)r
   Úprint)rL   r   r0   r   r   r   rM   b   s    rM   )Útypingr   r   r   r   r   r   Úpip._vendor.rich.consoler   r8   r
   Úsegmentr   Úterminal_themer   r?   r   r*   r)   r.   rG   rM   r   r   r   r   Ú<module>   s    