o
    Ëý°jz  ã                   @   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dede defdd„Z"dedeee#ee ee f  fdd„Z$			d&dedeeef de%dee def
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.¡ qÆe,e-ƒ dS 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                   @   sJ   e Zd ZU dZeed< 	 ee ed< 	 defdd„Zedef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   úŠ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/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$   dt t dtf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   c                 c   s  � d}t }t}t | ¡D ]`}| ¡ \}}}| ¡ \}}	||kr)|| ||… dfV  |rU|t|ƒdƒ\}
}|
rD|d|
 dfV  ||
d 7 }|rU||t|ƒd… dfV  |	}q| d¡\}}}|d|||re|ndƒfV  |	}q|t| ƒk r|| |d… dfV  dS 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   s0   €ÿrB   Ú TÚstyleÚemojiÚemoji_variantc                    sþ  t }d| vrt|r|| |d�|d�S | |d�S t|d�}|j}tj}g ‰ˆj‰ g }|j}	t}
t}dtdt	t
tf f‡ ‡fdd„}t| ƒD �]
\}}}|durY||rU||ƒn|ƒ qD|du�rO|j d	¡�r=|jd
d…  ¡ }|r‘||ƒ}z||ƒ\}}W n, ty�   td|j› d|› d�ƒd‚w zˆ ƒ \}}W n ty¨   td|› d�ƒd‚w |j d¡�r0|j�rd}|j ¡ }t |¡}|durÒ| ¡ \}}|du rÐdn|}zt|ƒ}W n3 tyó } ztd|›d|j›d|j› �ƒ‚d}~w t�y } ztd|j›d|› �ƒd‚d}~ww |�r|t|tƒ�r|n|ff}nd}|	|
|t|ƒt|j|id�ƒƒ qD|	|
|t|ƒt|ƒƒƒ qD|||jƒ|jƒ}ˆ t|ƒ|f¡ qDt|ƒ}ˆ�roˆ ¡ \}}t|ƒ}|�rl|	|
|||ƒƒ ˆ�sWt|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| ƒ‚)z"Pop tag matching given style name.r   )Ú	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)ÚprintÚ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"   ÚMARKUPÚpip._vendor.rich.tablert   Úpip._vendor.richru   Úgridr!   Úadd_rowr   r   r   r   Ú<module>   sd    (þ

ÿÿÿ
þ(#üÿ
þýü
û{î