a
    hbòfÑ  ã                   @   sœ   d dl mZmZmZmZ ddlmZ ddlmZ d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 )é    )ÚAnyÚDictÚIterableÚListé   )Ú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   úU/home/httpd/docs/test/DocsMgr/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                   @   s8   e Zd ZdZdZ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   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   ,   r   z2JupyterMixin._repr_mimebundle_.<locals>.<dictcomp>c                    s   i | ]\}}|ˆ vr||“qS r   r   r   r   r   r   r   .   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(   )r/   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   Úescape3   s    z _render_segments.<locals>.escapez<span style="z">z</span>z	<a href="z</a>Ú )Úcode)
r'   Úappendr	   r   ÚsimplifyÚget_html_styleÚlinkÚjoinÚJUPYTER_HTML_FORMATÚformat)r/   r5   Ú	fragmentsÚappend_fragmentÚthemer   ÚstyleÚcontrolÚruler7   r   r   r   r   r,   2   s"    


r,   N)r/   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.displayrE   ÚModuleNotFoundError)r/   r   r   Újupyter_renderableÚipython_displayr   r   r   rE   K   s    
rE   )Úargsr   r   c                  O   s   t ƒ }|j| i |¤ŽS )zProxy for Console print.)r   Úprint)rJ   r   r.   r   r   r   rK   Y   s    rK   )Útypingr   r   r   r   r6   r   Úsegmentr   Úterminal_themer	   r=   r
   r(   r'   r,   rE   rK   r   r   r   r   Ú<module>   s   