� ���g�(��>�dZddlZddlmZGd�d��Zd�ZdS)z<utilities for generating and formatting literal Python code.�N)� exceptionsc�`�eZdZd�Zd�Zd�Zd�Zdd�Zd�Zd�Z d �Z d �Z dd �Z d �Z d�Zd�ZdS)� PythonPrinterc���d|_g|_d|_||_d|_g|_d|_|���i|_tj d��|_ tj d��|_ tj d��|_ tj d��|_tj d ��|_tj d ��|_dS) Nrz �Fz^\s*#z^\s*$z:[ \t]*(?:#.*)?$z ^\s*(if|try|elif|while|for|with)z(^\s*(def|class|else|elif|except|finally)z"^\s*(else|elif|except|finally).*\:)�indent� indent_detail� indentstring�stream�lineno� line_buffer�in_indent_lines�_reset_multi_line_flags� source_map�re�compile�_re_space_comment� _re_space� _re_indent� _re_compound�_re_indent_keyword�_re_unindentor)�selfr s �Z/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/mako/pygen.py�__init__zPythonPrinter.__init__s����� �  ���#����� ��� ����$��� �$�$�&�&�&����!#��H�!5�!5�����H�-�-����*�%8�9�9����J�'J�K�K���"$�*� 7�# �# ���!�j�)N�O�O�����c�&�|xj|z c_dS�N)r �r�nums r�_update_linenozPythonPrinter._update_lineno7s�� � � �s�� � � � rc�D�|j|jvr||j|j<dSdSr)r r)rr s r� start_sourcezPythonPrinter.start_source:s-�� �;�d�o� -� -�+1�D�O�D�K� (� (� (� .� -rc�j�|j�d|z��|�|��dS)N� )r �writer!rs r� write_blankszPythonPrinter.write_blanks>s6�� � ���$��*�%�%�%� ���C� � � � � rNc���d|_ttjd|����D]N\}}|j�|��|�|�||z��|�d���OdS)z�print a line or lines of python which already contain indentation. The indentation of the total block of lines will be adjusted to that of the current indent level.F�\r?\nNr)r� enumerater�splitr �appendr#r!)r�block�starting_lineno�i�ls r�write_indented_blockz"PythonPrinter.write_indented_blockBs��� %����b�h�x��7�7�8�8� #� #�D�A�q� � � #� #�A� &� &� &��*��!�!�/�A�"5�6�6�6� � � �� "� "� "� "�  #� #rc�:�|D]}|�|���dS)z"print a series of lines of python.N)� writeline)r�lines�lines r� writelineszPythonPrinter.writelinesNs0��� !� !�D� �N�N�4� � � � � !� !rc�D�|js|���d|_|�4|j�|��s|j�|��rd}nd}|ot |��o |ddk}|sw|r|�|��r`|jdkrU|xjdzc_t |j��dkrtj d���|j� ��|�dS|j � |�|��dz��|�t |�d������|j�|��r�|j�|��}|rA|�d��}|xjdz c_|j�|��dSd}|j�|��}|r.|xjdz c_|j�|��dSdSdS) z�print a line of python, indenting it according to the current indent level. this also adjusts the indentation counter according to the content of the line. TNFr�#rzToo many whitespace closuresr%)r�_flush_adjusted_linesr�matchr�len�_is_unindentorrr r� MakoException�popr r&� _indent_liner!r+r�searchr�groupr,r)rr5�hastext� is_commentr:�indentor�m2s rr3zPythonPrinter.writelineSsI���#� (� � &� &� (� (� (�#'�D� � �L��%�+�+�D�1�1� ��~�#�#�D�)�)� ��G�G��G��:�c�$�i�i�:�D��G�s�N� �� %�� %� $� 3� 3�D� 9� 9� %�� �a��� �K�K�1� �K�K��4�%�&�&�!�+�+� �.�/M�N�N�N� � � "� "� $� $� $� �<� �F� � ���$�+�+�D�1�1�D�8�9�9�9� ���C�� � �4� 0� 0�1�1�2�2�2� �?� !� !�$� '� '� 8� �%�+�+�D�1�1�E�� 8� �;�;�q�>�>��� � �q� � � ��"�)�)�(�3�3�3�3�3����,�2�2�4�8�8���8��K�K�1�$�K�K��&�-�-�h�7�7�7�7�7�' 8� 8�"8�8rc�.�|���dS)z1close this printer, flushing any remaining lines.N)r9�rs r�closezPythonPrinter.close�s�� �"�"�$�$�$�$�$rc��t|j��dkrdS|jd}|�dS|j�|��}t |��S)zqreturn true if the given line is an 'unindentor', relative to the last 'indent' event received. rF�����)r;r rr:�bool)rr5rDr:s rr<zPythonPrinter._is_unindentor�s_�� �t�!� "� "�a� '� '��5��%�b�)�� � ��5��#�)�)�$�/�/���E�{�{�r�c�~�|dkr|j|jz|zStjd|z|j|jz|��S)z�indent the given line according to the current indent level. stripspace is a string of space that will be truncated from the start of the line before indenting.rL�^%s)r rr�sub)rr5� stripspaces rr?zPythonPrinter._indent_line�sN�� �� � ��$�t�{�2�T�9� 9��v� �Z� ��!2�T�[�!@�$� � � rc�$�d\|_|_dS)z^reset the flags which would indicate we are in a backslashed or triple-quoted section.)FFN)� backslashed� triplequotedrGs rrz%PythonPrinter._reset_multi_line_flags�s��/;�+���$�+�+�+rc���|jp|j}ttjd|����|_t tjd|����}|dks |dzdkr |j |_|S)zcreturn true if the given line is part of a multi-line block, via backslash or triple-quote.�\\$� \"\"\"|\'\'\'r�r)rRrSrKrr@r;�findall)rr5� current_state�tripless r�_in_multi_linezPythonPrinter._in_multi_line�su���(�=�D�,=� ��� �&�$� 7� 7�8�8����b�j�!1�4�8�8�9�9�� �a�<�<�7�Q�;�!�+�+�$(�$5� 5�D� ��rc���d}|���|jD]�}|�|��r|j�|dz���5|���}|�=t jd|��r(t jd|��� d��}|j�|� ||��dz����g|_|���dS)Nr%�^[ \t]*[^# \t]� ^([ \t]*)r) rr r[r r&� expandtabsrr@r:rAr?)rrP�entrys rr9z#PythonPrinter._flush_adjusted_lines�s���� � �$�$�&�&�&��%� O� O�E��"�"�5�)�)� O�� �!�!�%�$�,�/�/�/�/��(�(�*�*���%�"�)�4E�u�*M�*M�%�!#��,��!>�!>�!D�!D�Q�!G�!G�J�� �!�!�$�"3�"3�E�:�"F�"F��"M�N�N�N�N���� �$�$�&�&�&�&�&rr�rL)�__name__� __module__� __qualname__rr!r#r'r1r6r3rHr<r?rr[r9�rrrrs�������&P�&P�&P�P���2�2�2�!�!�!� #� #� #� #�!�!�!� E8�E8�E8�N%�%�%����P  �  �  �  �;�;�;� ���&'�'�'�'�'rrc�����ddg�d\�����fd�}d d�}g}d}tjd|��D]�}||��r|�|���#|���}|�=tjd|��r(tjd |���d ��}|�|||������d �|��S) z<remove the left-whitespace margin of a block of Python code.F)rrc�����p��}tjd|��rd��<nd��<d�}|r���r9|d��z|��\}}|rd��<ne|d��z|��\}}nL|d|��\}}|r|S|d|��\}}|r|�d ����<��|d |��\}}|��|S) NrUTFc��tj||��}|r,||t|�d����d�fSd|fS)Nr)rr:r;rA)�reg�t�ms rr:z7adjust_whitespace.<locals>.in_multi_line.<locals>.match sJ�����a� � �A�� ��!�C����� � �O�O�-�-�.�.�.��Q�w�rz%sz .*?(?=%s|$)r8rVrz.*?(?=\"\"\"|\'\'\'|#|$))rr@rA)r5� start_stater:rkrR�staterSs ���r� in_multi_linez(adjust_whitespace.<locals>.in_multi_linesA����K�(�?�E�,�,?� � �9�V�T� "� "� '�!%�E�+� � �!&�E�+� � � � �� C��\�"� C��%���l�(;� ;�T�B�B���4��P�*/�E�,�'�'�#�e�N�U�<�5H�$H�$�O�O�G�A�t�t��%��d�+�+���4��'�&�&��%� 0�$�7�7���4���*+�'�'�!�*�*�E�,�'���%� ;�T�B�B���4�#� C�&�rrLc�4�tjd|zd|��S)NrNrL)rrO)r5rPs rr?z'adjust_whitespace.<locals>._indent_line's���v�f�z�)�2�t�4�4�4rNr)r]r^rr%ra)rr+r,r_r@r:rA�join) �textrnr?r4rPr5rRrmrSs @@@r�adjust_whitespacerr�s������E�N�E�"(��[�,�"�"�"�"�"�"�"�H5�5�5�5� �E��J����4�(�(�9�9�� �=�� � � 9� �L�L�� � � � ��?�?�$�$�D��!�b�i�0A�4�&H�&H�!��X�l�D�9�9�?�?��B�B� � �L�L���d�J�7�7� 8� 8� 8� 8� �9�9�U� � �r)�__doc__r�makorrrrrerr�<module>russ��C�B� � � � �������l'�l'�l'�l'�l'�l'�l'�l'�^8�8�8�8�8r
Memory