� ���g�?��\�dZddlZddlZddlmZddlmZddlmZiZGd�d��Z dS)zGprovides the Lexer class for parsing template strings into parse trees.�N)� exceptions)� parsetree)�adjust_whitespacec��eZdZ dd�Zed���Zdd�Zd�Zd�Zd�Z e j d��Z d �Z d �Zd �Zd �Zd �Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�LexerNc�&�||_||_tj|j��|_d|_d|_d|_d|_g|_ g|_ g|_ ||_ |� g|_ dSt|d��s |g|_ dS||_ dS)N�r�__iter__)�text�filenamer� TemplateNode�template�matched_lineno�matched_charpos�lineno�match_position�tag� control_line� ternary_stack�encoding� preprocessor�hasattr)�selfr r �input_encodingrs �Z/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/mako/lexer.py�__init__zLexer.__init__s����� � �� �!�.�t�}�=�=�� ���� ����� �������������&�� � � � "�D� � � ���z�2�2� -�!-��D� � � � ,�D� � � �c�8�|j|j|j|jd�S)N)�sourcer�posr )r rrr )rs r�exception_kwargszLexer.exception_kwargs*s)���i��)��'�� �  � � rc��� t||f}nG#t$r:|rtj||��ntj|��}|t||f<YnwxYw|�|��S)z>compile the given regexp, cache the reg, and call match_reg().)� _regexp_cache�KeyError�re�compile� match_reg)r�regexp�flags�regs r�matchz Lexer.match3s�� 1�����0�C�C��� 1� 1� 1�/4�L�"�*�V�U�+�+�+�"�*�V�:L�:L�C�-0�M�6�5�/� *� *� *� 1�����~�~�c�"�"�"s��AA�Ac��|j}|�|j|j��}|r�|���\}}||kr|dzn||_|j|_|dz }|dkr0||jkr%|jd|dz��d��}||z |_|xj|j||j�� d��z c_|S)z�match the given regular expression object to the current text position. if a match occurs, update the current text and line position. r rN� ) rr+r �spanrr� textlength�rfindr�count)rr*�mpr+�start�end�cps rr'zLexer.match_reg>s���� ��� � �$�)�T�%8�9�9�� � K� �:�:�<�<�L�U�C�-0�E�\�\�#��'�'�s�D� �"&�+�D� ��a��B��Q�w�w�2���/�/��Y�x��a��x�(�.�.�t�4�4��#%��7�D� � �K�K�4�9�R�$�*=�%=�>�D�D�T�J�J� J�K�K�� rc�d�|j}d�|��}d}d}d} |�d��}|r�|�dtj��}|r�<|�d|z��}|r`|r|dksX|dksR|dksL|j||jt |�d����z �|�d��fS|s#|�d|ztj��}|�r||�d���d ��z }||�d���d ��z}||�d���d ��z }||�d���d ��z}||�d���d ��z }||�d���d��z}���tj dd�|��zfi|j ���)N�|rTz#.*\nz+(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1z(%s)r z(.*?)(?=\"|\'|#|%s)�{�}�(�)�[�]z Expected: %s�,) r�joinr+r%�Sr �len�groupr1r�SyntaxExceptionr!) r� watch_nestingr �startpos�text_re� brace_level� paren_level� bracket_levelr+s r�parse_until_textzLexer.parse_until_textTs.���&���)�)�D�/�/��� �� �� � ��J�J�x�(�(�E�� ���J�J�>�����E�� ���J�J�w��0�1�1�E�� K�� K� �1�_�_� �a���=�1�;L�;L��I� �4�#6��U�[�[��^�^�9L�9L�#L�L���K�K��N�N� �� � K�� � �#9�G�#C�R�T�J�J��� ��u�{�{�1�~�~�3�3�C�8�8�8� ��u�{�{�1�~�~�3�3�C�8�8�8� ��u�{�{�1�~�~�3�3�C�8�8�8� ��u�{�{�1�~�~�3�3�C�8�8�8� �����Q���!5�!5�c�!:�!:�:� �����Q���!5�!5�c�!:�!:�:� ���,�����$���/���37�3H��� rc��|�d|j��|�d|j��|�d|j��|j|d<||i|��}t |j��r&|jdj�|��n|j j�|��|j r�|j d}|j�|��t|tj ��r|�|j��s?|jr8|jdr+|jddj�|��t|tj��rBt |j��r|jd|_|j�|��dSt|tj ���r%|jr4|j ���|j���dS|jr6|j �|��|j�g��dS|j rG|j d�|j��r"|jd�|��dS|j rZ|j d�|j��s7t-jd|j�d|j dj�d�fi|j���dSdSdS) Nrrr r ������ Keyword 'z#' not a legal ternary for keyword '�')� setdefaultr rrr rAr�nodes�appendrr� isinstancer� ControlLine� is_ternary�keywordr�Tag�parent�isend�pop� is_primaryrrCr!)r�nodecls�args�kwargs�node� control_frames r� append_nodezLexer.append_node|s"�����(�D�I�.�.�.����(�D�$7�8�8�8����%��!5�6�6�6�!�]��z���w��'��'�'�� �t�x�=�=� -� �H�R�L� � %� %�d� +� +� +� +� �M� � &� &�t� ,� ,� ,� � � >� �-�b�1�M� � � &� &�t� ,� ,� ,��t�Y�%:�;�;� >�&�0�0���>�>� >� �&�  >� �&�r�*�  >��"�2�&�r�*�0�7�7��=�=�=� �d�I�M� *� *� ��4�8�}�}� +�"�h�r�l�� � �H�O�O�D� !� !� !� !� !� ��i�3� 4� 4� ��z� ��!�%�%�'�'�'��"�&�&�(�(�(�(�(��� ��!�(�(��.�.�.��"�)�)�"�-�-�-�-�-��"� �t�'8��'<�'G�'G�� �(�(� ��"�2�&�-�-�d�3�3�3�3�3��"� �4�+<�R�+@�+K�+K�� �,�,� �!�0�0��|�|�|�T�%6�r�%:�%B�%B�%B�D����+���� � � � � � rz #.*coding[:=]\s*([-\w.]+).*\r?\nc��t|t��r9|j�|��}|r|�d��p|pd}||fS|�t j��r�|tt j��d�}d}|j�|� dd����}|�[|�d��dkrBtj d|�d��z|� dd��dd|���nI|j�|� dd����}|r|�d��n|pd}|rT |� |��}n=#t$r0tj d|z|� dd��dd|���wxYw||fS)z�given string/unicode or bytes/string, determine encoding from magic encoding comment, return body as unicode or raw if decode_raw=False r zutf-8N�ignorezHFound utf-8 BOM in file, with conflicting magic encoding comment of '%s'rz0Unicode decode operation of encoding '%s' failed) rR�str� _coding_rer+rB� startswith�codecs�BOM_UTF8rA�decoder�CompileException�UnicodeDecodeError)rr � decode_raw�known_encodingr �mr�parsed_encodings r�decode_raw_streamzLexer.decode_raw_stream�s��� �d�C� � � "���%�%�d�+�+�A��'�Q�W�W�Q�Z�Z�D�>�D�W�H��T�>� !� �?�?�6�?� +� +� M���F�O�,�,�.�.�/�D�%�O���%�%�d�k�k�'�8�&D�&D�E�E�A��}�������w�!6�!6� �1�5�78�w�w�q�z�z�B��K�K���2�2���� ������%�%�d�k�k�'�8�&D�&D�E�E�A�,-�L�a�g�g�a�j�j�j�>�3L�W�O� � � ��{�{�?�3�3����%� � � � �1�F�%�&��K�K���2�2���� ��� ������$�$s �)E?�?:F9c�R�|�|jd|j|j��\|_|_|jD]}||j��|_�|�|j��t|j��|_ |j |jkrn�|� ��rn�|� ��r�<|� ��r�Q|� ��r�f|���r�{|���r��|���r��|���r��|���r��|j |jkrnt'jd���t|j��r*t'jd|jdjzfi|j���t|j��rUt'jd|jdjz|j|jdj|jdj|j���|jS)NTzassertion failed�Unclosed tag: <%%%s>rLz"Unterminated control keyword: '%s')ror rr rr'rdrAr/r� match_end�match_expression�match_control_line� match_comment�match_tag_start� match_tag_end�match_python_block� match_percent� match_textr� MakoExceptionrrCrUr!rrr r)r�preprocs r�parsez Lexer.parse�s;��#'�#9�#9� �I�t�T�]�D�M�$ �$ � �� �t�y��(� +� +�G���� �*�*�D�I�I� ���t��'�'�'��d�i�.�.��� ?��"�T�_�4�4���~�~��� ���$�$�&�&� ���&�&�(�(� ���!�!�#�#� ���#�#�%�%� ���!�!�#�#� ���&�&�(�(� ���!�!�#�#� ����� � � ���"�T�_�4�4���*�+=�>�>� >� �t�x�=�=� ��,�&���"��)=�=����'��� � �t� � !� !� ��,�4��#�B�'�/�0�� ��!�"�%�,��!�"�%�)�� � �� ��}�rc���d}|�|tjtjztjz��}|sdS|���\}}}||_i}|r=tjd|��D]'}|\}} } | p| } | �dd��} | ||<�(|� tj ||��|r|j � ��n�|dkr�|�dtj��}|s*tjd|j d jzfi|j���|� tj|�d ����|���Sd S) Na� \<% # opening tag ([\w\.\:]+) # keyword ((?:\s+\w+|\s*=\s*|"[^"]*?"|'[^']*?'|\s*,\s*)*) # attrname, = \ # sign, string expression # comma is for backwards compat # identified in #366 \s* # more whitespace (/)?> # closing Fz)\s*(\w+)\s*=\s*(?:'([^']*)'|\"([^\"]*)\")� r-r z(.*?)(?=\</%text>)rqrLr T)r+r%�Ir@�X�groupsrU�findall�replacer`rrVrrYrrCr!�TextrBrw) rr*r+rU�attrrX� attributes�att�key�val1�val2r s rrvzLexer.match_tag_starts��� �� � � � � �D�2�4�K�"�$� � � �� � ��5�$�|�|�~�~����u��� �� � � '��z�<�d��� '� '��#&���T�4��|�t���|�|�F�D�1�1��"&� �3��� �������<�<�<� � (� �H�L�L�N�N�N�N� �� � ��J�J�4�b�d�;�;�E�� � �0�*�T�X�b�\�-A�A����+���� � � �Y�^�U�[�[��^�^� <� <� <��%�%�'�'� '��trc���|�d��}|r�t|j��s-tjd|�d��zfi|j���|jdj|�d��krAtjd|�d���d|jdj�d�fi|j���|j���dSd S) Nz\</%[\t ]*([^\t ]+?)[\t ]*>z(Closing tag without opening tag: </%%%s>r rLzClosing tag </%z> does not match tag: <%�>TF) r+rArrrCrBr!rUrY�rr+s rrwzLexer.match_tag_endFs���� � �9�:�:�� � ��t�x�=�=� � �0�>��k�k�!�n�n�%����+���� ��"��%����Q���7�7� �0�0��{�{�1�~�~�~�~�t�x��|�';�';�';�=����+���� �H�L�L�N�N�N��4��5rc�~�|�dtj��}|sdS|���}|r|SdS)Nz\ZFT)r+r%r@rB)rr+�strings rrrzLexer.match_endZsC��� � �5�"�$�'�'��� ��5������� � ��M��4rc���|�dtj��}|rN|�tj|�d��dz|�d��z��dSdS)Nz(?<=^)(\s*)%%(%*)r �%�TF)r+r%�Mr`rr�rBr�s rryzLexer.match_percentesi��� � �/���6�6�� � � � � ���� � �A���� 4�u�{�{�1�~�~� E� � � ��4��5rc���|�dtjtjz��}|r9|�d��}|r |�t j|��dSdS)Na� (.*?) # anything, followed by: ( (?<=\n)(?=[ \t]*(?=%|\#\#)) # an eval or line-based # comment, preceded by a # consumed newline and whitespace | (?=\${) # an expression | (?=</?%) # a substitution or block or call start or end # - don't consume | (\\\r?\n) # an escaped newline - throw away | \Z # end of string )r TF)r+r%r�r@rBr`rr�)rr+r s rrzzLexer.match_textosj��� � � � �D�2�4�K�# � ��( � ��;�;�q�>�>�D�� 7�� � ����6�6�6��4��5rc� �|�d��}|rv|j|j}}|�dd��\}}t |��dz}|�t j||�d��dk||���dSdS) Nz<%(!)?Fz%>r-r �!�rr T) r+rrrJrr`r�CoderB)rr+�liner r r4s rrxzLexer.match_python_block�s���� � �9�%�%�� � ��+�T�-A�#�D��-�-�e�U�;�;�I�D�#�%�T�*�*�T�1�D� � � ����� � �A���#�%��� � � � ��4��5rc�d�|�d��}|sdS|j|j}}|�ddd��\}}|dkr|�dd��\}}nd}|�dd ��}|�t j||���||� ��dS) Nz\${FTz\|r9r7�rr-r�) r+rrrJr�r`r� Expression�strip)rr+r�r r r4�escapess rrszLexer.match_expression�s���� � �6�"�"��� ��5��'��)=�c���)�)�$��t�<�<� ��c� �#�:�:��0�0��t�<�<�L�G�S�S��G��|�|�F�D�)�)�� ��� � � � �M�M�O�O��� � � � ��trc���|�dtj��}|sdS|�d��}|�d��}|dkr�tjd|��}|st jd|zfi|j���|�dd��\}}|du}|rvt|j��st jd|�d |�d �fi|j���|jd j |kr.t jd |�d |jd j �d �fi|j���|� tj |||��n |� tj |��dS)NzC(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\\r?\n)|[^\r\n])*)(?:\r?\n|\Z)Fr r�r�z(end)?(\w+)\s*(.*)zInvalid control line: '%s'zNo starting keyword 'z' for 'rNrLrMz' doesn't match keyword 'T)r+r%r�rBrrCr!rArrUr`rrS�Comment)rr+�operatorr �m2rXrUs rrtzLexer.match_control_line�s���� � � � �D� � �� � ��5��;�;�q�>�>���{�{�1�~�~�� �s�?�?���/��6�6�B�� � �0�0�4�7����+���� �X�X�a��^�^�N�E�7���%�E�� ��4�,�-�-� �$�4�4�?F�w�w����M����/�����&�r�*�2�g�=�=�$�4�4��4�4��!2�2�!6�!>�!>�!>�@����/���� � � �Y�2�G�U�D� I� I� I� I� � � �Y�.�� 5� 5� 5��trc��|�dtj��}|r5|�tj|�d����dSdS)z*matches the multiline version of a commentz<%doc>(.*?)</%doc>r TF)r+r%r@r`rr�rBr�s rruzLexer.match_comment�sM��� � �0�"�$�7�7�� � � � � �Y�.�� � �A��� ?� ?� ?��4��5r)NNN)N)�__name__� __module__� __qualname__r�propertyr!r+r'rJr`r%r&rdror}rvrwrrryrzrxrsrtru�rrrrsF������EI�-�-�-�-�,� � ��X� � #� #� #� #����,&�&�&�P0�0�0�d���?�@�@�J�(%�(%�(%�T8�8�8�t0�0�0�d���( � � �������:���&���*$�$�$�L����rr) �__doc__rfr%�makorr� mako.pygenrr#rr�rr�<module>r�s���N�M� � � � � � � � �������������(�(�(�(�(�(�� �N�N�N�N�N�N�N�N�N�Nr
Memory