a
    hbòfz  ã                   @   sž  d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ e dej¡Ze d¡ZG dd„ de
ƒZe	e Zeegef Zeeegef Z e d¡j!fee edœdd„Z"eeee#ee ee f  dœdd„Z$d#eeeef e%ee edœdd„Z&e'dk�ršg d¢Z(d dl)m*Z* d dl+m,Z, e*dd d!d"�Z-e(D ]Z.e- /ee.ƒe.¡ �qze,e-ƒ dS )$é    )Úliteral_eval)Ú
attrgetterN)ÚCallableÚIterableÚListÚMatchÚ
NamedTupleÚOptionalÚTupleÚUnioné   )ÚMarkupError)ÚStyle)ÚSpanÚText)ÚEmojiVariant)Ú_emoji_replacez((\\*)\[([a-z#\/@].*?)\])z^([\w\.]*?)(\(.*?\))?$c                   @   sF   e Zd ZU dZeed< ee ed< edœdd„Zeedœdd„ƒZ	d	S )
ÚTagzA tag in console markup.ÚnameÚ
parameters)Úreturnc                 C   s"   | j d u r| jS | j› d| j › �S )Nú ©r   r   ©Úself© r   úT/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/rich/markup.pyÚ__str__   s     ÿzTag.__str__c                 C   s.   | j du rd| j› d�S d| j› d| j › d�S )z*Get the string representation of this tag.Nú[ú]ú=r   r   r   r   r   Úmarkup"   s    ÿýz
Tag.markupN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__r	   r   Úpropertyr!   r   r   r   r   r      s   
r   z(\\*)(\[[a-z#\/@].*?\]))r!   Ú_escaper   c                 C   s"   t t tdœdd„}||| ƒ} | S )zÂEscapes text so that it won't be interpreted as markup.

    Args:
        markup (str): Content to be inserted in to markup.

    Returns:
        str: Markup with square brackets escaped.
    )Úmatchr   c                 S   s   |   ¡ \}}|› |› d|› �S )z!Called by re.sub replace matches.ú\)Úgroups)r*   ÚbackslashesÚtextr   r   r   Úescape_backslashes=   s    z"escape.<locals>.escape_backslashes)r   r&   )r!   r)   r/   r   r   r   Úescape1   s    
r0   )r!   r   c                 c   sü   d}t }t}t | ¡D ]À}| ¡ \}}}| ¡ \}}	||krP|| ||… dfV  |r¨|t|ƒdƒ\}
}|
r†|d|
 dfV  ||
d 7 }|r¨||t|ƒd… dfV  |	}q| d¡\}}}|d|||rÈ|ndƒfV  |	}q|t| ƒk rø|| |d… dfV  dS )zŒParse markup in to an iterable of tuples of (position, text, tag).

    Args:
        markup (str): A string containing console markup

    r   Né   r+   r    )Údivmodr   ÚRE_TAGSÚfinditerr,   ÚspanÚlenÚ	partition)r!   ÚpositionÚ_divmodÚ_Tagr*   Ú	full_textÚescapesÚtag_textÚstartÚendr-   Úescapedr.   Úequalsr   r   r   r   Ú_parseF   s,    rB   Ú T)r!   ÚstyleÚemojiÚemoji_variantr   c                    s   t }d| vr(t|r|| |d�n| |d�S t|d�}|j}tj}g ‰ˆj‰ g }|j}	t}
t}tt	t
tf dœ‡ ‡fdd„}t| ƒD �]@\}}}|durª||r¢||ƒn|ƒ q€|dur€|j d¡�rž|jd	d…  ¡ }|�r"||ƒ}z||ƒ\}}W n. t�y   td
|j› d|› d�ƒd‚Y n0 n6zˆ ƒ \}}W n& t�yV   td|› d�ƒd‚Y n0 |j d¡�r„|j�r^d}|j ¡ }t |¡}|du�r®| ¡ \}}|du �rªdn|}zt|ƒ}W n€ t�yþ } z*td|›d|j›d|j› �ƒ‚W Y d}~nFd}~0  t�y: } z$td|j›d|› �ƒd‚W Y d}~n
d}~0 0 |�rb|t|tƒ�rT|n|ff}nd}|	|
|t|ƒt|j|id�ƒƒ n|	|
|t|ƒt|ƒƒƒ q€|||jƒ|jƒ}ˆ t|ƒ|f¡ q€t|ƒ}ˆ�r ˆ ¡ \}}t|ƒ}|�rÌ|	|
|||ƒƒ �qÌt|ddd… tdƒd�|_ |S )a9  Render console markup in to a Text instance.

    Args:
        markup (str): A string containing console markup.
        emoji (bool, optional): Also render emoji code. Defaults to True.

    Raises:
        MarkupError: If there is a syntax error in the markup.

    Returns:
        Text: A test instance.
    r   )Údefault_variant)rD   )Ú
style_namer   c                    s@   t tˆƒdƒD ]$\}\}}|j| krˆ | ƒ  S qt| ƒ‚dS )z"Pop tag matching given style name.r   N)Ú	enumerateÚreversedr   ÚKeyError)rH   ÚindexÚ_Útag©ÚpopÚstyle_stackr   r   Ú	pop_styleŒ   s    
zrender.<locals>.pop_styleNú/r   zclosing tag 'z' at position z doesn't match any open tagzclosing tag '[/]' at position z has nothing to closeú@rC   z()zerror parsing z in z; r   )Úmetaéÿÿÿÿr>   )Úkey)!r   r   Úappendr   Ú	normalizerP   r   r   r&   r
   ÚintrB   r   Ú
startswithÚstriprK   r   r!   Ú
IndexErrorr   Ú
RE_HANDLERr*   r,   r   ÚSyntaxErrorÚmsgÚ	ExceptionÚ
isinstanceÚtupler6   Úsortedr   Úspans)r!   rD   rE   rF   Úemoji_replacer.   rX   rY   re   Úappend_spanÚ_Spanr:   rR   r8   Ú
plain_textrN   rH   r>   Úopen_tagÚhandler_namer   Úhandler_matchÚmatch_parametersÚmeta_paramsÚerrorÚnormalized_tagÚtext_lengthr   rO   r   Úrenderg   s¨    þ
ÿþ

ÿþ


ÿÿÿþÿüÿÿrr   Ú__main__)z[red]Hello World[/red]z[magenta]Hello [b]World[/b]z9[bold]Bold[italic] bold and italic [/bold]italic[/italic]zDClick [link=https://www.willmcgugan.com]here[/link] to visit my Blogz+:warning-emoji: [bold red blink] DANGER![/])ÚTable)ÚprintZMarkupÚResult)r   r   )Úpadding)rC   TN)0Úastr   Úoperatorr   ÚreÚtypingr   r   r   r   r   r	   r
   r   Úerrorsr   rD   r   r.   r   r   rE   r   r   ÚcompileÚVERBOSEr3   r^   r   r&   Ú_ReStringMatchÚ_ReSubCallableÚ_EscapeSubMethodÚsubr0   rZ   rB   Úboolrr   r"   ZMARKUPÚpip._vendor.rich.tablert   Úpip._vendor.richru   Úgridr!   Úadd_rowr   r   r   r   Ú<module>   sR   (þ

ÿþ&#   ü
û{
