� ]�g� � ��ddlZddlmZddlmZddlmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZdd lmZdd lmZmZejd ej��Zejd ��ZGd �de ��Ze eZeegefZeeegefZ ejd��j!fdede defd�Z"dedee e#e ee effd�Z$ d#dede eefde%de edef d�Z&e'dkrOgd�Z(ddl)m*Z*ddl+m,Z,e,dd d!�"��Z-e(D]!Z.e-�/ee.��e.���"e*e-��dSdS)$�N)� literal_eval)� attrgetter)�Callable�Iterable�List�Match� NamedTuple�Optional�Tuple�Union�)�_emoji_replace)� EmojiVariant)� MarkupError)�Style)�Span�Textz((\\*)\[([a-z#/@][^[]*?)])z^([\w.]*?)(\(.*?\))?$c�`�eZdZUdZeed< eeed< defd�Zedefd���Z dS)�TagzA tag in console markup.�name� parameters�returnc�@�|j�|jn|j�d|j��S)N� �rr��selfs �[/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/rich/markup.py�__str__z Tag.__str__s)����0�D�I�I���6V�6V�T�_�6V�6V� �c�L�|j� d|j�d�nd|j�d|j�d�S)z*Get the string representation of this tag.N�[�]�=rrs r�markupz Tag.markup!s@�� ��&� �� � � � � �3�T�Y�3�3���3�3�3� r N) �__name__� __module__� __qualname__�__doc__�str�__annotations__r r�propertyr%�r rrrs}�������"�"� �I�I�I�$��� ����3� �� � � � � � �� � � ��X� � � r rz(\\*)(\[[a-z#/@][^[]*?])r%�_escaperc��dttdtfd�}|||��}|�d��r|�d��s|dzS|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. �matchrc�B�|���\}}|�|�d|��S)z!Called by re.sub replace matches.�\)�groups)r0� backslashes�texts r�escape_backslashesz"escape.<locals>.escape_backslashes=s-��!�L�L�N�N�� �T��4�{�4�4�d�4�4�4r r2z\\)rr*�endswith)r%r.r6s r�escaper80sr��5�%��*�5��5�5�5�5� �W�'�� 0� 0�F� ���t����V�_�_�V�%<�%<����}�� �Mr c#�:K�d}t}t}t�|��D]�}|���\}}}|���\}} ||kr||||�dfV�|rQ|t |��d��\} } | r|d| zdfV�|| dzz }| r||t |��d�dfV�| }��|�d��\} } }|d|| | r|nd��fV�| }��|t |��kr|||d�dfV�dSdS)z�Parse markup in to an iterable of tuples of (position, text, tag). Args: markup (str): A string containing console markup rN�r2r$)�divmodr�RE_TAGS�finditerr3�span�len� partition)r%�position�_divmod�_Tagr0� full_text�escapes�tag_text�start�endr4�escapedr5�equalsrs r�_parserKIs������H��G� �D��!�!�&�)�)����',�|�|�~�~�$� �7�H��Z�Z�\�\� ��s� �8� � ������/��5� 5� 5� 5� � �#*�7�3�w�<�<��#;�#;� �K��� )��T�K�/��5�5�5�5���q��(��� ��Y�s�7�|�|�~�~�6��<�<�<�<����#+�#5�#5�c�#:�#:� ��f�j��T�4�4��F�&D�j�j��E�E�E�E�E�E�����#�f�+�+�����x�y�y�)�4�/�/�/�/�/�/��r �T�style�emoji� emoji_variantc ����t}d|vr t|r |||���n||���St|���}|j}tj}g��j�g}|j} t } t} dtdtttff��fd� } t|��D�]�\} }}|�/|� dd��}||r ||��n|���8|��g|j �d ���r |j d d����}|rE||��} | |��\}}n[#t $rt#d |j�d | �d ���d�wxYw ���\}}n"#t&$rt#d| �d���d�wxYw|j �d���r#|jr�d}|j���}t*�|��}|�|���\}}|�dn|} t1|��}n\#t2$r'}t#d|�d|j�d|j�����d}~wt6$r }t#d|j�d|����d�d}~wwxYw|r|t9|t:��r|n|ff}nd}| | |t=|��t|j |i���������-| | |t=|��t|��������_| ||j ��|j��}��t=|��|f�����t=|��}�r@����\}}t|��}|r| | |||������@t?|ddd�tAd�����|_!|S)a�Render 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)rM� style_namerc���tt���d��D]!\}\}}|j|kr�| ��cS�"t|���)z"Pop tag matching given style name.r )� enumerate�reversedr�KeyError)rR�index�_�tag�pop� style_stacks ��r� pop_stylezrender.<locals>.pop_style�sb���(��+�)>�)>��B�B� #� #�O�E�8�A�s��x�:�%�%��s�E�6�{�{�"�"�"�&��z�"�"�"r Nz\[�/r z closing tag 'z' at position z doesn't match any open tagzclosing tag '[/]' at position z has nothing to close�@rLz()zerror parsing z in z; r-)�meta�����rG)�key)"rr�appendr� normalizerZrrr*r �intrK�replacer� startswith�striprVrr%� IndexErrorr� RE_HANDLERr0r3r� SyntaxError�msg� Exception� isinstance�tupler?�sortedr�spans)r%rMrNrO� emoji_replacer5rbrcrp� append_span�_SpanrCr\rA� plain_textrYrRrG�open_tag� handler_namer� handler_match�match_parameters� meta_params�error�normalized_tag� text_lengthrZr[s @@r�renderr}js�����*#�M� �&����DI� U�M�M�&�-� @� @� @� @�v�� � � � � �e� � � �D� �[�F���I�)+�K� �/�C��E��,�K� �E� �D�#�c�#�e�C��H�o�#�#�#�#�#�#�#�&,�F�^�^�D@�D@�!��*�c� � !�#�+�+�E�3�7�7�J� �F��E�=�=��,�,�,�:� F� F� F� F� �_��x�"�"�3�'�'�> @� �X�a�b�b�\�/�/�1�1� ��$�!*��:�!6�!6�J�$�*3�)�J�*?�*?���x�x��#�$�$�$�)�k�C�J�k�k�h�k�k�k���#�$�$���� $�*-�#�%�%���x�x��%�$�$�$�)�\�X�\�\�\���#�$�$���� �=�+�+�C�0�0�'H��*�)�')� �%-�%8�%>�%>�%@�%@� �(2�(8�(8��(D�(D� �(�4�=J�=Q�=Q�=S�=S�:�L�*:�(8�(@���FV�'� (�*6�z�*B�*B�K�K��*����"-� g�� g� g�8�CV� g� g�\a�\e� g� g�#�#������ )�(�(�(�"-� Q��1D� Q� Q�%� Q� Q�#�#�#'�(�����(���� (�� ,�#-�k�5�#A�#A�!4� � �&1�^� +�K��')� ��K���!�3�t�9�9�e�(�-��9U�.V�.V�.V�������  �K���e�S��Y�Y��H� � � F� F�G�G�G�G�"&��i�i���&9�&9�3�>�!J�!J���"�"�C��I�I�~�#>�?�?�?���d�)�)�K� �:� �_�_�&�&� ��s��C���� � :� �K���e�[�%�8�8� 9� 9� 9� �:� ��d�d��d� ��G�)<�)<�=�=�=�D�J� �Ks<�,D;�;'E"�& E4�4F� H� I6�'"I � I6�I1�1I6�__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)�Table�Markup�Result)rr )�padding)rLTN)0�re�astr�operatorr�typingrrrrr r r r rrNr�errorsrrMrr5rr�compile�VERBOSEr<rirr*�_ReStringMatch�_ReSubCallable�_EscapeSubMethod�subr8rdrK�boolr}r&�MARKUP�richr� rich.tabler��gridr%�add_rowr-r r�<module>r�s��� � � � �������������V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�V�*�*�*�*�*�*��������������������������� �"�*�%��J� � �� �R�Z�0� 1� 1� � � � � � �*� � � �.�s����>�*�C�/�0���^�S�1�3�6�7�� !+�� �+F� G� G� K��� �� �� �����20�3�0�8�E�#�x��}�h�s�m�*K�$L�M�0�0�0�0�F "��,0� }�}� �}� ��e�� �}� �}��L�)� }�  � }�}�}�}�@ �z������F������� � � � � � � �5��8�V� 4� 4� 4�D��+�+�� � � �T�T�&�\�\�6�*�*�*�*� �E�$�K�K�K�K�K�#�r
Memory