� ���gMJ��<�dZddlZddlmZddlmZddlmZddlmZGd�d��ZGd �d e��ZGd �d e��Z Gd �de��Z Gd�de��Z Gd�de��Z Gd�de��Z Gd�de��ZGd�dee���ZGd�de��ZGd�de��ZGd�de��ZGd �d!e��ZGd"�d#e��ZGd$�d%e��ZGd&�d'e��ZGd(�d)e��ZGd*�d+e��ZdS),z5defines the parse tree components for Mako templates.�N)�ast)� exceptions)�filters)�utilc�:�eZdZdZd�Zed���Zd�Zd�ZdS)�Nodez(base class for a Node in the parse tree.c�>�||_||_||_||_dS�N��source�lineno�pos�filename)�selfr r rrs �^/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/mako/parsetree.py�__init__z Node.__init__s"���� ��� ���� �� � � �c�8�|j|j|j|jd�S)Nr r �rs r�exception_kwargszNode.exception_kwargss'���k��k��8�� �  � � rc��gSr �rs r� get_childrenzNode.get_children$���� rc�d���fd�}t�d|jjz|��}||��dS)Nc�`��|���D]}|�����dSr )r�accept_visitor)�node�n�visitors �r�traversez%Node.accept_visitor.<locals>.traverse(s?����&�&�(�(� *� *��� � ��)�)�)�)� *� *r�visit)�getattr� __class__�__name__)rr r!�methods ` rrzNode.accept_visitor'sJ��� *� *� *� *� *���'�D�N�,C�"C�X�N�N����t� � � � � rN) r%� __module__� __qualname__�__doc__r�propertyrrrrrrrrsb������2�2�!�!�!� � � ��X� ��������rrc�.��eZdZdZ�fd�Zd�Zd�Z�xZS)� TemplateNodez?a 'container' node that stores the overall collection of nodes.c�l��t���ddd|��g|_i|_dS)N�r)�superr�nodes�page_attributes)rrr$s �rrzTemplateNode.__init__4s6��� ������Q��8�,�,�,��� �!����rc��|jSr �r0rs rrzTemplateNode.get_children9� ���z�rc�L�dtj|j���d|j�d�S)Nz TemplateNode(�, �))r�sorted_dict_reprr1r0rs r�__repr__zTemplateNode.__repr__<s.��� � !�$�"6� 7� 7� 7� 7� �J�J�J� � r)r%r'r(r)rrr9� __classcell__�r$s@rr,r,0s\�������I�I�"�"�"�"�"� ��� � � � � � � rr,c�D��eZdZdZdZ�fd�Zd�Zd�Zd�Zd�Z d�Z �xZ S) � ControlLinez�defines a control line, a line-oriented python line or end tag. e.g.:: % if foo: (markup) % endif Fc ���t��jdi|��||_||_||_|dv|_g|_|jrg|_g|_dStj |fi|j ��}|j |_|j |_dS)N)�for�if�while�try�withr)r/r�text�keyword�isend� is_primaryr0�_declared_identifiers�_undeclared_identifiersr�PythonFragmentr�declared_identifiers�undeclared_identifiers)rrErFrD�kwargs�coder$s �rrzControlLine.__init__Qs���������"�"�6�"�"�"��� ��� ��� �!�%J�J����� � �:� G�)+�D� &�+-�D� (� (� (��%�d�D�D�d�.C�D�D�D�)-�)B�D� &�+/�+F�D� (� (� (rc��|jSr r3rs rrzControlLine.get_children`r4rc��|jSr )rHrs rrKz ControlLine.declared_identifierscs ���)�)rc��|jSr )rIrs rrLz"ControlLine.undeclared_identifiersfs ���+�+rc�j�ddhddhdhd�}||�|jt����vS)zRreturn true if the given keyword is a ternary keyword for this ControlLine�else�elif�except�finally)r@rBr?)�getrE�set)rrE�casess r� is_ternaryzControlLine.is_ternaryisF�� �6�"��i�(��8� � �� �%�)�)�D�L�#�%�%�8�8�8�8rc �V�d|j�d|j�d|j�d|j|jf�d� S)Nz ControlLine(r6r7)rErDrFr rrs rr9zControlLine.__repr__us;��� �L�L�L� �I�I�I� �J�J�J� �[�$�(� #� #� #�  � r) r%r'r(r)�has_loop_contextrrrKrLrZr9r:r;s@rr=r=Cs������������ G� G� G� G� G����*�*�*�,�,�,� 9� 9� 9� � � � � � � rr=c�(��eZdZdZ�fd�Zd�Z�xZS)�Textz#defines plain text in the template.c �H��t��jdi|��||_dS�Nr)r/r�content)rrarMr$s �rrz Text.__init__�s+��������"�"�6�"�"�"��� � � rc�6�d|j�d|j|jf�d�S)NzText(r6r7)rar rrs rr9z Text.__repr__�s$���!%����� �T�X�/F�/F�/F�G�Gr�r%r'r(r)rr9r:r;s@rr^r^~sT�������-�-������H�H�H�H�H�H�Hrr^c�4��eZdZdZ�fd�Zd�Zd�Zd�Z�xZS)�Codez�defines a Python code block, either inline or module level. e.g.:: inline: <% x = 12 %> module level: <%! import logger %> c ���t��jdi|��||_||_t j|fi|j��|_dSr`)r/rrD�ismoduler� PythonCoderrN)rrDrgrMr$s �rrz Code.__init__�sN��������"�"�6�"�"�"��� � �� ��N�4�A�A�4�+@�A�A�� � � rc��|jjSr )rNrKrs rrKzCode.declared_identifiers�s ���y�-�-rc��|jjSr )rNrLrs rrLzCode.undeclared_identifiers�s ���y�/�/rc�F�d|j�d|j�d|j|jf�d�S)NzCode(r6r7)rDrgr rrs rr9z Code.__repr__�s2��� �I�I�I� �M�M�M� �[�$�(� #� #� #� � r� r%r'r(r)rrKrLr9r:r;s@rrere�st��������� B�B�B�B�B� .�.�.�0�0�0� � � � � � � rrec�(��eZdZdZ�fd�Zd�Z�xZS)�Commentz6defines a comment line. # this is a comment c �H��t��jdi|��||_dSr`)r/rrD)rrDrMr$s �rrzComment.__init__�s+��������"�"�6�"�"�"��� � � rc�6�d|j�d|j|jf�d�S)NzComment(r6r7)rDr rrs rr9zComment.__repr__�s$���$(�I�I�I�� �T�X�/F�/F�/F�G�Grrcr;s@rrnrn�sX��������� �����H�H�H�H�H�H�Hrrnc�4��eZdZdZ�fd�Zd�Zd�Zd�Z�xZS)� Expressionz/defines an inline expression. ${x+y} c ����t��jdi|��||_||_t j|fi|j��|_t j|fi|j��|_ dSr`) r/rrD�escapesr� ArgumentListr� escapes_coderhrN)rrDrtrMr$s �rrzExpression.__init__�sl��������"�"�6�"�"�"��� ��� ��,�W�N�N��8M�N�N����N�4�A�A�4�+@�A�A�� � � rc��gSr rrs rrKzExpression.declared_identifiers�rrc���|jj�|jj�t j�����|jj��Sr )rNrL�unionrv� differencer�DEFAULT_ESCAPESrKrs rrLz!Expression.undeclared_identifiers�sR���y�/�5�5� � � 4� ?� ?��'� � � � � �*�T�Y�3� 4� 4�  5rc�P�d|j�d|jj�d|j|jf�d�S)Nz Expression(r6r7)rDrv�argsr rrs rr9zExpression.__repr__�s8��� �I�I�I� � � "� "� "� �[�$�(� #� #� #� � rrlr;s@rrrrr�st��������� B�B�B�B�B����5�5�5� � � � � � � rrrc�,��eZdZdZiZ�fd�Zd�Z�xZS)�_TagMetazImetaclass to allow Tag to produce a subclass according to its keywordc���t|dd���||j|j<t���|||��dS)N� __keyword__)r#� _classmapr�r/r)�cls�clsname�bases�dict_r$s �rrz_TagMeta.__init__�sE��� �3� �t� ,� ,� 8�-0�C�M�#�/� *� ������%��/�/�/�/�/rc �B�d|vr2|�d��\}}tjt|||fi|��S tj|}nB#t $r5tjd|z|d|d|d|d����wxYwtj|||fi|��S)N�:zNo such tag: '%s'r r rrr ) �split�type�__call__�CallNamespaceTagrr��KeyErrorr�CompileException)r�rE� attributesrM�ns�defnames rr�z_TagMeta.__call__�s��� �'�>�>�!�-�-��,�,�K�B���=� �"�g�z���=C��� � ��$�W�-�C�C��� � � ��-�#�g�-��h�'��h�'��5�M�� �+� ��� � �����}�S�'�:�@�@��@�@�@s �A � ?B )r%r'r(r)r�rr�r:r;s@rrr�s_����������I�0�0�0�0�0� A�A�A�A�A�A�Arrc�J��eZdZdZdZ�fd�Zd�Zd�Zd�Zd�Z d�Z d �Z �xZ S) �Tagz�abstract base class for tags. e.g.:: <%sometag/> <%someothertag> stuff </%someothertag> Nc �H���t��jdi|��|�_|�_��||���fd�|D��}t |��r7t jdd�d�|D����zfi�j ���d�_ g�_ dS)aVconstruct a new Tag instance. this constructor not called directly, and is only called by subclasses. :param keyword: the tag keyword :param attributes: raw dictionary of attribute key/value pairs :param expressions: a set of identifiers that are legal attributes, which can also contain embedded expressions :param nonexpressions: a set of identifiers that are legal attributes, which cannot contain embedded expressions :param \**kwargs: other arguments passed to the Node superclass (lineno, pos) c�&��g|] }|�jv� |��Sr)�parsed_attributes)�.0�rrs �r� <listcomp>z Tag.__init__.<locals>.<listcomp>,s&���J�J�J��!�4�3I�*I�*I�1�*I�*I�*IrzMissing attribute(s): %s�,c3�4K�|]}t|��V��dSr )�repr)r��ms r� <genexpr>zTag.__init__.<locals>.<genexpr>1s(����8�8�1�t�A�w�w�8�8�8�8�8�8rNr) r/rrEr��_parse_attributes�lenrr��joinr�parentr0) rrEr�� expressions�nonexpressions�requiredrM�missingr$s ` �rrz Tag.__init__ s�����8 �����"�"�6�"�"�"��� �$��� ���{�N�;�;�;�J�J�J�J�h�J�J�J�� �w�<�<� ��-�.��h�h�8�8��8�8�8�8�8�9��� �'� �� ��� ��� � � rc��|jduSr )r�rs r�is_rootz Tag.is_root9s���{�d�"�"rc��|jSr r3rs rrzTag.get_children<r4rc� �t��}i|_|jD�]�}||v�rJg}tjdtj���|j|��D]�}tjdtj���|��}|r�tj |� d��� ��fi|j ��}|� |j��}|�d|� d��z����|r"|�t!|������d�|��pt!d��|j|<��R||vrgtjd|j|��r#t'jd|�d |j�d �fi|j ���t!|j|��|j|<���t'jd |j�d |�d �fi|j ���||_dS)Nz(\${(?:[^$]*?{.+|.+?)})z ^\${(.+?)}$�z(%s)z + r.z\${.+?}z Attribute 'z ' in tag 'z%' does not allow embedded expressionszInvalid attribute for tag 'z': '�')rXr�r��re�compile�Sr��matchrrh�group�rstriprryrL�appendr�r��searchrr�rE�!expression_undeclared_identifiers) rr�r�rL�key�expr�xr�rNs rr�zTag._parse_attributes?s3��!$����!#����?�# �# �C��k�!�!�����$>���E�E�K�K��O�C�(���-�-�A�� �>�2�4�8�8�>�>�q�A�A�A�� -�"�~��G�G�A�J�J�-�-�/�/� � �37�3H� � ��2H�1M�1M� �7�2�2�.�� � �F�Q�W�W�Q�Z�Z�$7�8�8�8�8��-�� � �D��G�G�,�,�,��.3�j�j��.>�.>�.J�$�r�(�(��&�s�+�+���&�&��9�Z����)=�>�>��$�5�5�),���d�l�l�l�<����/���� /3�4�?�3�3G�.H�.H��&�s�+�+� �1�1��|�|�|�S�S�S�*����+���� 2H��.�.�.rc��gSr rrs rrKzTag.declared_identifiershrrc��|jSr )r�rs rrLzTag.undeclared_identifiersks ���5�5rc ��|jj�d|j�dtj|j���d|j|jf�d|j�d� S)N�(r6r7) r$r%rErr8r�r rr0rs rr9z Tag.__repr__nsT�� �N� #� #� #� �L�L�L� � !�$�/� 2� 2� 2� 2� �[�$�(� #� #� #� �J�J�J�  � r) r%r'r(r)r�rr�rr�rKrLr9r:r;s@rr�r��s�������� � ��K�+�+�+�+�+�Z#�#�#����'H�'H�'H�R���6�6�6� � � � � � � rr�)� metaclassc�2��eZdZdZ�fd�Zd�Z�fd�Z�xZS)� IncludeTag�includec ���t��j||dddfi|��tjd|�dd��zfi|j��|_dS)N)�file�importr}r�r�z __DUMMY(%s)r}r.)r/rrrhrWr� page_args�rrEr�rMr$s �rrzIncludeTag.__init__{s{�������� � � &� � �  � � �  � � ��� �J�N�N�6�2�6�6� 6� � �:>�:O� � ����rc��gSr rrs rrKzIncludeTag.declared_identifiers�rrc����|jj�dh���|jj��}|�t �������S)N�__DUMMY)r�rLrzrKryr/)r� identifiersr$s �rrLz!IncludeTag.undeclared_identifiers�s]����n�;�F�F� �K� � � �*�T�^�8� 9� 9� �� � ����!?�!?�!A�!A�B�B�Br�r%r'r(r�rrKrLr:r;s@rr�r�xsn��������K�  �  �  �  �  ����C�C�C�C�C�C�C�C�Crr�c�(��eZdZdZ�fd�Zd�Z�xZS)� NamespaceTag� namespacec �N��t��j||dddfi|��|�ddtt t |������z��|_d|vrd|vrtj d i|j ���d|vrd |vrtj d i|j ���dSdS) Nr�)�name� inheritabler��modulerr�z __anon_%sr��?'name' and/or 'import' attributes are required for <%namespace>r�r��4<%namespace> may only have one of 'file' or 'module')r�)r�) r/rrW�hex�abs�idr�rr�rr�s �rrzNamespaceTag.__init__�s��������� � � � 7� �  � � �  � � ��N�N�6�;��S��D���]�]�9K�9K�+K�L�L�� � �� #� #�� �(B�(B��-�#����'��� � �Z� � �H� �$:�$:��-�F����'��� � � �$:�$:rc��gSr rrs rrKz!NamespaceTag.declared_identifiers�rr�r%r'r(r�rrKr:r;s@rr�r��sL��������K������.������rr�c�(��eZdZdZ�fd�Zd�Z�xZS)�TextTagrDc ���t��j||dddfi|��tj|�dd��fi|j��|_dS)Nr�filterr.)r/rrrurWr� filter_argsr�s �rrzTextTag.__init__�sf���������*�b�8�b�K�K�F�K�K�K��+� �N�N�8�R� (� (� � �,0�,A� � ����rc��|jj�tj������|j��Sr �r�rLrzrr{�keysryr�rs rrLzTextTag.undeclared_identifiers�sB����6�A�A� � #� (� (� *� *� � � �%��6� 7� 7� 8r)r%r'r(r�rrLr:r;s@rr�r��sL��������K� � � � � � 8�8�8�8�8�8�8rr�c�R��eZdZdZ�fd�ZdZdZed���Zd�Z d�Z d�Z �xZ S)�DefTag�defc ����ddgd�|D��z}t��j|||ddfi|��|d}tjd|��rt j di|j���tjd |zd zfi|j��|_ |j j |_ |� d d ��|_ tj|� d d ��fi|j��|_dS)N�buffered�cachedc�<�g|]}|�d���|��S��cache_�� startswith�r��cs rr�z#DefTag.__init__.<locals>.<listcomp>�s9��0 �0 �0 ��Q�\�\�(�%;�%;�0 � �0 �0 �0 r�r�r�� decorator�r�r��^[\w_]+$�Missing parenthesis in %defzdef z:passr�r.r�)r�)r/rr�r�rr�rr� FunctionDecl� function_decl�funcnamer�rWr�rur��rrEr�rMr�r�r$s �rrzDefTag.__init__�sD���!�8�,�0 �0 �!�0 �0 �0 � � � ����� � � � +� �  � � �  � � ��&�!�� �8�K�� &� &� ��-�-���15�1F��� �!�-� �T�M�G� #� � �'+�'<� � ����&�/�� �#��� �R�8�8����+� �N�N�8�R� (� (� � �,0�,A� � ����rFc��|jjSr )r�r�rs rr�zDefTag.funcname�s���!�*�*rc �&�|jjdi|��Sr`)r��get_argument_expressions�r�kws rr�zDefTag.get_argument_expressions�s��:�t�!�:�@�@�R�@�@�@rc��|jjSr )r�� allargnamesrs rrKzDefTag.declared_identifiers�s���!�-�-rc ��g}|jjD].}|ttj|fi|j��j��z }�/t|���|j j� tj � �������|j��� |jj��Sr )r��defaults�listrrhrrLrXryr�rzrr{r�r�r�)r�resr�s rrLzDefTag.undeclared_identifiers�s������#�,� � �A� �4�������.���(��� �C�C� ��H�H� �U�� �7�B�B��+�0�0�2�2����� �U�4�9� :� :� �Z��*�6� 7� 7� r) r%r'r(r�r� is_anonymous�is_blockr*r�r�rKrLr:r;s@rr�r��s���������K� � � � � �6�L��H� �+�+��X�+�A�A�A�.�.�.� � � � � � � rr�c�d��eZdZdZ�fd�ZdZed���Zed���Zd�Z d�Z d�Z �xZ S) �BlockTag�blockc �N��gd�d�|D��z}t��j|||ddfi|��|�d��}|r,tjd|��st j d i|j���|s-|�dd��rt j di|j���tj |�dd ��fi|j��|_ ||_ |�d d ��|_ tj |�d d ��fi|j��|_dS)N)r�r�r}c�<�g|]}|�d���|��Sr�r�r�s rr�z%BlockTag.__init__.<locals>.<listcomp>s9��8 �8 �8 ��Q�\�\�(�%;�%;�8 � �8 �8 �8 rr�rr�r��,%block may not specify an argument signaturer}�#Only named %blocks may specify argsr.r�r�)r )r )r/rrWr�r�rr�rr� FunctionArgs� body_declr�r�rur�r�s �rrzBlockTag.__init__s����4�4�4�8 �8 �!�8 �8 �8 � � � ����� � � � +� �  � � �  � � ��~�~�f�%�%�� � ����d�3�3� ��-�>����'��� �� � ���v�t�4�4� ��-�5���9=�9N��� ��)� �N�N�6�2� &� &� � �*.�*?� � ����� �#��� �R�8�8����+� �N�N�8�R� (� (� � �,0�,A� � ����rTc��|jduSr r�rs rrzBlockTag.is_anonymous$s���y�D� � rc�&�|jp d|jfzS)Nz __M_anon_%d)r�r rs rr�zBlockTag.funcname(s���y�:�M�T�[�N�:�:rc �&�|jjdi|��Sr`)r r�r�s rr�z!BlockTag.get_argument_expressions,s��6�t�~�6�<�<��<�<�<rc��|jjSr �r r�rs rrKzBlockTag.declared_identifiers/� ���~�)�)rc��|jj�tj������|j��Sr r�rs rrLzBlockTag.undeclared_identifiers2sD�� � � 3� >� >��'�,�,�.�.� � � �%��6� 7� 7�  8r) r%r'r(r�rrr*rr�r�rKrLr:r;s@rrr�s���������K� � � � � �B�H� �!�!��X�!��;�;��X�;�=�=�=�*�*�*�8�8�8�8�8�8�8rrc�.��eZdZdZ�fd�Zd�Zd�Z�xZS)�CallTag�callc ���t��j||dddfi|��|d|_tj|jfi|j��|_tj|�dd��fi|j��|_ dS)Nr})r�r�r.) r/r� expressionrrhrrNr rWr r�s �rrzCallTag.__init__=s��������� �Z�&�9�i� � �CI� � � �%�V�,����N�4�?�L�L�d�6K�L�L�� ��)� �N�N�6�2� &� &� � �*.�*?� � ����rc�T�|jj�|jj��Sr �rNrKryr r�rs rrKzCallTag.declared_identifiersG� ���y�-�3�3�D�N�4N�O�O�Orc�T�|jj�|jj��Sr �rNrLrzrKrs rrLzCallTag.undeclared_identifiersJ�'���y�/�:�:� �I� *� � � rr�r;s@rrr:s^��������K� � � � � �P�P�P� � � � � � � rrc�*��eZdZ�fd�Zd�Zd�Z�xZS)r�c ���t��j|dz|z|t|�����dzddfi|��|�d|�dd�d�|j���D�����d�|_tj |jfi|j ��|_ tj |� d d ��fi|j ��|_dS) Nr�)r}r�.r�r�c3�6K�|]\}}|dk� |�d|��V��dS)r}�=Nr)r��k�vs rr�z,CallNamespaceTag.__init__.<locals>.<genexpr>^sC�������A�q���;�;��1�1�a�a� ��;�;�;��rr7r}r.)r/r�tupler�r�r��itemsrrrhrrNr rWr )rr�r�r�rMr$s �rrzCallNamespaceTag.__init__Qs�������� ��O�g� %� � �*�/�/�#�#� $� $�y� 0� � �  � � �  � � � �I�I� �G�G� �H�H��� �2�8�8�:�:���� � � � � ����N�4�?�L�L�d�6K�L�L�� ��)� �N�N�6�2� &� &� � �*.�*?� � ����rc�T�|jj�|jj��Sr rrs rrKz%CallNamespaceTag.declared_identifiersjrrc�T�|jj�|jj��Sr rrs rrLz'CallNamespaceTag.undeclared_identifiersmrr)r%r'r(rrKrLr:r;s@rr�r�PsY������� � � � � �2P�P�P� � � � � � � rr�c�"��eZdZdZ�fd�Z�xZS)� InheritTag�inheritc �D��t��j||dddfi|��dS)Nr�r)r/rr�s �rrzInheritTag.__init__vs@�������� �Z��B� � � �=C� � � � � r)r%r'r(r�rr:r;s@rr,r,ss=��������K� � � � � � � � � rr,c�(��eZdZdZ�fd�Zd�Z�xZS)�PageTag�pagec �&��gd�d�|D��z}t��j|||ddfi|��tj|�dd��fi|j��|_tj|�dd��fi|j��|_dS)N)r�r}�expression_filter� enable_loopc�<�g|]}|�d���|��Sr�r�r�s rr�z$PageTag.__init__.<locals>.<listcomp>�s)�� =� =� =�1�a�l�l�8�&<�&<� =�Q� =� =� =rrr}r.r3) r/rrr rWrr rur�)rrEr�rMr�r$s �rrzPageTag.__init__s���� � � � >� =� � =� =� =� >� � ������*�k�2�r�L�L�V�L�L�L��)� �N�N�6�2� &� &� � �*.�*?� � ����+� �N�N�.�� 3� 3� � �7;�7L� � ����rc��|jjSr rrs rrKzPageTag.declared_identifiers�rrr�r;s@rr0r0|sL��������K� � � � � � *�*�*�*�*�*�*rr0)r)r��makorrrrrr,r=r^rernrrr�rr�r�r�r�r�rrr�r,r0rrr�<module>r8s���<�;� � � � ���������������������������������> � � � � �4� � � �&8 �8 �8 �8 �8 �$�8 �8 �8 �vH�H�H�H�H�4�H�H�H�" �" �" �" �" �4�" �" �" �J H� H� H� H� H�d� H� H� H� � � � � �� � � �BA�A�A�A�A�t�A�A�A�>x �x �x �x �x �$�(�x �x �x �x �vC�C�C�C�C��C�C�C�4�����3����< 8� 8� 8� 8� 8�c� 8� 8� 8�< �< �< �< �< �S�< �< �< �~98�98�98�98�98�s�98�98�98�x � � � � �c� � � �,  �  �  �  �  �s�  �  �  �F � � � � �� � � �*�*�*�*�*�c�*�*�*�*�*r
Memory