U cf!@sddlZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZdd lmZdd lmZmZed ejZed ZGd dde Ze eZeegefZeeegefZ edj!fee edddZ"eee e#e ee efdddZ$d'ee eefe%e eedddZ&e'dkrddddd gZ(dd!l)m*Z*dd"l+m,Z,e,d#d$d%d&Z-e(D]Z.e-/ee.e.qe*e-dS)(N) literal_eval) attrgetter)CallableIterableListMatch NamedTupleOptionalTupleUnion)_emoji_replace) EmojiVariant) MarkupError)Style)SpanTextz((\\*)\[([a-z#/@][^[]*?)])z^([\w.]*?)(\(.*?\))?$c@sFeZdZUdZeed<eeed<edddZeedddZ d S) TagzA tag in console markup.name parameters)returncCs"|jdkr|jS|jd|jS)N rrselfrE/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/markup.py__str__s z Tag.__str__cCs.|jdkrd|jdSd|jd|jdS)z*Get the string representation of this tag.N[]=rrrrrmarkup!sz Tag.markupN) __name__ __module__ __qualname____doc__str__annotations__r rpropertyr!rrrrrs  rz(\\*)(\[[a-z#/@][^[]*?]))r!_escapercCs>tttddd}|||}|dr:|ds:|dS|S)zEscapes 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. )matchrcSs|\}}||d|S)z!Called by re.sub replace matches.\)groups)r* backslashestextrrrescape_backslashes=s z"escape..escape_backslashesr+z\\)rr&endswith)r!r)r/rrrescape0s  r1)r!rccsd}t}t}t|D]}|\}}}|\}} ||krP||||dfV|r|t|d\} } | r|d| dfV|| d7}| r||t|ddfV| }q|d\} } }|d|| | r|ndfV| }q|t|kr|||ddfVdS)zParse markup in to an iterable of tuples of (position, text, tag). Args: markup (str): A string containing console markup rNr+r )divmodrRE_TAGSfinditerr,spanlen partition)r!position_divmod_Tagr* full_textescapestag_textstartendr-escapedr.equalsrrrr_parseIs,   rCT)r!styleemoji emoji_variantrc s,t}d|kr(t|r|||dn||dSt|d}|j}tj}gjg}|j} t} t} tt t tfdfdd } t |D]L\} }}|dk r| dd}||r||n|q|dk r|j d r|j d d}|r0||}z| |\}}Wn0tk r,td |jd | d dYnXn8z\}}Wn(tk rftd| ddYnX|j dr|jrjd}|j}t|}|dk r|\}}|dkrdn|}z t|}Wn|tk r }z"td|d|jd|jW5d}~XYn<tk rF}ztd|jd|dW5d}~XYnX|rn|t|tr`|n|ff}nd}| | |t|t|j |idn| | |t|t|q| ||j |j}t||fqt|}r \}}t|}|r| | |||qt|dddt dd|_!|S)aRender console markup in to a Text instance. Args: markup (str): A string containing console markup. style: (Union[str, Style]): The style to use. emoji (bool, optional): Also render emoji code. Defaults to True. emoji_variant (str, optional): Optional emoji variant, either "text" or "emoji". Defaults to None. Raises: MarkupError: If there is a syntax error in the markup. Returns: Text: A test instance. r)default_variant)rE) style_namercs@ttdD]$\}\}}|j|kr| Sqt|dS)z"Pop tag matching given style name.r N) enumeratereversedrKeyError)rIindex_tagpop style_stackrr pop_styles zrender..pop_styleNz\[/r z closing tag 'z' at position z doesn't match any open tagzclosing tag '[/]' at position z has nothing to close@rDz()zerror parsing z in z; r)metar?)key)"r rappendr normalizerQrrr&r intrCreplacer startswithstriprLrr! IndexErrorr RE_HANDLERr*r,r SyntaxErrormsg Exception isinstancetupler7sortedrspans)r!rErFrG emoji_replacer.rYrZrg append_span_Spanr;rSr9 plain_textrOrIr?open_tag handler_namer handler_matchmatch_parameters meta_paramserrornormalized_tag text_lengthrrPrrenderjs          rt__main__z[red]Hello World[/red]zagenta]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![/])print)TableZMarkupResult)rr )padding)rDTN)0reastroperatorrtypingrrrrrr r r r rFrerrorsrrErr.rrcompileVERBOSEr4r`rr&_ReStringMatch_ReSubCallable_EscapeSubMethodsubr1r[rCboolrtr"ZMARKUPpip._vendor.richrvpip._vendor.rich.tablerwgridr!add_rowrrrrs`  (       &#