Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.15.214.120
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : format.cpython-311.pyc
�

Tf�=��H�dZddlZddlmZddlmZddlmZGd�d��Ze�	��d�Z
d	�Zd
�Zd�Z
d�Zd
�Zejd��Zd�ZGd�d��ZGd�d��ZGd�d��ZedkrddlmZeddd���dSdS)z�Format all or a selected region (line slice) of text.

Region formatting options: paragraph, comment block, indent, deindent,
comment, uncomment, tabify, and untabify.

File renamed from paragraph.py with functions added from editor.py.
�N)�askyesno)�
askinteger)�idleConfc�<�eZdZdZd�Zed���Zd�Zdd�ZdS)�FormatParagraphaFormat a paragraph, comment block, or selection to a max width.

    Does basic, standard text formatting, and also understands Python
    comment blocks. Thus, for editing Python source code, this
    extension is really only suitable for reformatting these comment
    blocks or triple-quoted strings.

    Known problems with comment reformatting:
    * If there is a selection marked, and the first line of the
      selection is not complete, the block will probably not be detected
      as comments, and will have the normal "text formatting" rules
      applied.
    * If a comment block has leading whitespace that mixes tabs and
      spaces, they will not be considered part of the same block.
    * Fancy comments, like this bulleted list, aren't handled :-)
    c��||_dS�N��editwin��selfrs  �7/usr/local/python-3.11/lib/python3.11/idlelib/format.py�__init__zFormatParagraph.__init__�
�������c�B�tjddddd���|_dS)N�
extensionsrz	max-width�int�H)�type�default)r�	GetOption�	max_width)�clss r�reloadzFormatParagraph.reload"s.�� �*�<�9J�+6�U�B�P�P�P��
�
�
rc��d|_dSr	r
�r
s r�closezFormatParagraph.close's
������rNc��|�|jn|}|jj}|j���\}}|r(|r&|�||��}t|��}n(t
||�d����\}}}}|rt|||��}nt||��}|�
ddd��||krk|�d|��|���|�
||��|�||��|���n|�d|��|�d��dS)a�Formats paragraph to a max width specified in idleConf.

        If text is selected, format_paragraph_event will start breaking lines
        at the max width, starting from the beginning selection.

        If no text is selected, format_paragraph_event uses the current
        cursor location to determine the paragraph (lines of text surrounded
        by blank lines) and formats it.

        The length limit parameter is for testing with a known value.
        N�insert�sel�1.0�end�break)rr�text�get_selection_indices�get�get_comment_header�find_paragraph�index�reformat_comment�reformat_paragraph�
tag_remove�mark_set�undo_block_start�deleter �undo_block_stop�see)	r
�event�limitr%�first�last�data�comment_header�newdatas	         r�format_paragraph_eventz&FormatParagraph.format_paragraph_event*sd��#(�-����U���|� ���l�8�8�:�:���t��	?�T�	?��8�8�E�4�(�(�D�/��5�5�N�N�#�4����H�)=�)=�>�>�
.�E�4����	6�&�t�U�N�C�C�G�G�(��u�5�5�G�����u�e�,�,�,��d�?�?��M�M�(�E�*�*�*��!�!�#�#�#��K�K��t�$�$�$��K�K��w�'�'�'�� � �"�"�"�"��M�M�(�D�)�)�)���������wrr	)	�__name__�
__module__�__qualname__�__doc__r�classmethodrrr:�rrrrsn�������� ����P�P��[�P����$�$�$�$�$�$rrc�2�tt|�d����\}}|�d|zd|z��}|�d|zdd��rYt|��rJ|dz}|�d|zd|z��}|�d|zdd��rt|���J|}t
|��}t|��}t
|��|krbt||d���sK|dz}|�d|zd|z��}t
|��|krt||d����Kd|z}|dz
}|�d|zd|z��}|dkr{t
|��|krht||d���sQ|dz
}|�d|zd|z��}|dkr*t
|��|krt||d����Qd|dzz}	|	|||�|	|��fS)	z�Returns the start/stop indices enclosing the paragraph that mark is in.

    Also returns the comment format string, if any, and paragraph of text
    between the start/stop indices.
    �.z%d.0z%d.end�<r#�Nr)�mapr�splitr'�compare�is_all_whiter(�len)
r%�mark�lineno�col�line�first_linenor8�comment_header_lenr6r5s
          rr)r)Ss\���c�4�:�:�c�?�?�+�+�K�F�C��8�8�F�V�O�X��%6�7�7�D��,�,�v����U�
3�
3�<��T�8J�8J�<��!����x�x�����F�):�;�;���,�,�v����U�
3�
3�<��T�8J�8J�<��L�'��-�-�N��^�,�,���T�
"�
"�N�
2�
2��t�$6�$7�$7�8�9�9�3��!����x�x�����F�):�;�;���T�
"�
"�N�
2�
2��t�$6�$7�$7�8�9�9�3��F�?�D��A�
�F��8�8�F�V�O�X��%6�7�7�D�
�1�*�*� ��&�&��6�6��t�$6�$7�$7�8�9�9�7��!����x�x�����F�):�;�;��	�1�*�*� ��&�&��6�6��t�$6�$7�$7�8�9�9�7�
�f�Q�h��E��$�������(=�(=�=�=rc�X�|�d��}d}t|��}||kr5t||��r |dz}||krt||��� ||kr|St||��}|dz|kr1t||dz��st||dz��}n|}|d|�}|}||k�rt||��s�t	jd||��}	tdt|	��d��D]�}
|	|
}|s�
t||z�����|kr/||kr)|�|�����|}||zdz}|
dzt|	��kr|	|
dzdkr|dz}��|dz}||krt||����|�|�����|�	||d���d�
|��S)z3Return data reformatted to specified width (limit).�
rrDNz(\s+)�� )rFrIrH�
get_indent�re�range�
expandtabs�append�rstrip�extend�join)r7r4�lines�i�n�indent1�indent2�new�partial�words�j�words            rr,r,xs+���J�J�t���E�	�A��E�
�
�A�
�a�%�%�L��q��*�*�%�
�a�C���a�%�%�L��q��*�*�%��A�v�v�����q��"�"�G���s�Q�w�w�|�E�!�A�#�J�/�/�w��U�1�Q�3�Z�(�(�����
����)�C��G�
�a�%�%��U�1�X�.�.�%����5��8�,�,���q�#�e�*�*�a�(�(�
	(�
	(�A���8�D��
���G�d�N�.�.�0�0�1�1�E�9�9��g�%�%��
�
�7�>�>�+�+�,�,�,�!����n�s�*�G���s�S��Z�Z���E�!�A�#�J�#�$5�$5�!�C�-���
�a�C���a�%�%��U�1�X�.�.�%��J�J�w�~�~��� � � ��J�J�u�Q�R�R�y�����9�9�S�>�>�rc����t����d��fd�|�d��D����}t|t���z
d��}t	||��}|�d��}d}|dsd}|dd�}d��fd�|D����|zS)z?Return data reformatted to specified width with comment header.rQc3�,�K�|]}|�d�V��dSr	r@)�.0rM�lcs  �r�	<genexpr>z#reformat_comment.<locals>.<genexpr>�s+�����<�<�4�T�"�#�#�Y�<�<�<�<�<�<r�����Nc3�"�K�|]	}�|zV��
dSr	r@)rhrMr8s  �rrjz#reformat_comment.<locals>.<genexpr>�s(�����=�=�T�^�D�(�=�=�=�=�=�=r)rIr[rF�maxr,)r7r4r8�format_widthr9�block_suffixris  `   @rr+r+�s�����

�^�	�	�B��9�9�<�<�<�<�4�:�:�d�+;�+;�<�<�<�<�<�D��u�s�>�2�2�2�B�7�7�L� ��|�4�4�G��m�m�D�!�!�G�
�L��2�;�����#�2�#�,���9�9�=�=�=�=�W�=�=�=�=�=��L�Lrc�0�tjd|��duS)z/Return True if line is empty or all whitespace.z^\s*$N)rU�match�rMs rrHrH�s���8�H�d�#�#�4�/�/rc�P�tjd|�����S)z/Return the initial space or tab indent of line.z	^([ \t]*)�rUrs�grouprts rrTrT�s ��
�8�L�$�'�'�-�-�/�/�/rc�^�tjd|��}|�dS|�d��S)aReturn string with leading whitespace and '#' from line or ''.

    A null return indicates that the line is not a comment line. A non-
    null return, such as '    #', will be used to find the other lines of
    a comment block with the same  indent.
    z^([ \t]*#*)NrlrDrv)rM�ms  rr(r(�s.��	����&�&�A��y����7�7�1�:�:�rz[ \t]*c���t�|��}|���t|����|����fS)z�Return a line's indentation as (# chars, effective # of spaces).

    The effective # of spaces is the length after properly "expanding"
    the tabs into spaces, as done by str.expandtabs(tabwidth).
    )�_line_indent_rersr#rIrwrW)rM�tabwidthrys   r�get_line_indentr}�sH��	���d�#�#�A��5�5�7�7�C����	�	�,�,�X�6�6�7�7�7�7rc�Z�eZdZdZd�Zd�Zd�Zd
d�Zd
d�Zd
d�Z	d
d	�Z
d
d
�Zd
d�Zd�Z
dS)�FormatRegionzFormat selected text (region).c��||_dSr	r
rs  rrzFormatRegion.__init__�rrc�r�|jj}|j���\}}|r3|r1|�|dz��}|�|dz��}n*|�d��}|�d��}|�||��}|�d��}||||fS)aqReturn line information about the selected text region.

        If text is selected, the first and last indices will be
        for the selection.  If there is no text selected, the
        indices will be the current cursor location.

        Return a tuple containing (first index, last index,
            string representation of text, list of text lines).
        z
 linestartz-1c lineend +1czinsert linestartzinsert lineend +1crQ)rr%r&r*r'rF)r
r%r5r6�head�tail�charsr\s        r�
get_regionzFormatRegion.get_region�s����|� ���l�8�8�:�:���t��	4�T�	4��:�:�e�l�2�3�3�D��:�:�d�%6�6�7�7�D�D��:�:�0�1�1�D��:�:�2�3�3�D�����t�$�$�����D�!�!���T�5�%�'�'rc��|jj}d�|��}||kr|���dS|�ddd��|�d|��|���|�||��|�||��|�	��|�
d|d��dS)aaReplace the text between the given indices.

        Args:
            head: Starting index of text to replace.
            tail: Ending index of text to replace.
            chars: Expected to be string of current text
                between head and tail.
            lines: List of new lines to insert between head
                and tail.
        rQNr!r"r#r )rr%r[�bellr-r.r/r0r r1�tag_add)r
r�r�r�r\r%�newcharss       r�
set_regionzFormatRegion.set_region�s����|� ���9�9�U�#�#���u����I�I�K�K�K��F�����u�e�,�,�,��
�
�h��%�%�%����������D�$�������D�(�#�#�#����������U�D�(�+�+�+�+�+rNc�b�|���\}}}}tt|����D]`}||}|rTt||jj��\}}	|	|jjz}	|j�|	��||d�z||<�a|�||||��dS)z$Indent region by indentwidth spaces.Nr$)	r�rVrIr}rr|�indentwidth�_make_blanksr��
r
r3r�r�r�r\�posrM�raw�	effectives
          r�indent_region_eventz FormatRegion.indent_region_events���#'�?�?�#4�#4� ��d�E�5���U���$�$�	O�	O�C���:�D��
O�!0��t�|�7L�!M�!M���Y�%���(@�@�	�!�\�6�6�y�A�A�D����J�N��c�
������d�E�5�1�1�1��wrc�~�|���\}}}}tt|����D]n}||}|rbt||jj��\}}	t
|	|jjz
d��}	|j�|	��||d�z||<�o|�	||||��dS)z$Dedent region by indentwidth spaces.rNr$)
r�rVrIr}rr|ror�r�r�r�s
          r�dedent_region_eventz FormatRegion.dedent_region_events���#'�?�?�#4�#4� ��d�E�5���U���$�$�	O�	O�C���:�D��
O�!0��t�|�7L�!M�!M���Y��	�D�L�,D� D�a�H�H�	�!�\�6�6�y�A�A�D����J�N��c�
������d�E�5�1�1�1��wrc���|���\}}}}tt|��dz
��D]}||}d|z||<�|�||||��dS)zrComment out each line in region.

        ## is appended to the beginning of each line to comment it out.
        rD�##r$�r�rVrIr��r
r3r�r�r�r\r�rMs        r�comment_region_eventz!FormatRegion.comment_region_event sr��
$(�?�?�#4�#4� ��d�E�5���U���a��(�(�	%�	%�C���:�D����E�#�J�J�����d�E�5�1�1�1��wrc�(�|���\}}}}tt|����D]C}||}|s�
|dd�dkr|dd�}n|dd�dkr
|dd�}|||<�D|�||||��dS)z�Uncomment each line in region.

        Remove ## or # in the first positions of a line.  If the comment
        is not in the beginning position, this command will have no effect.
        NrRr�rD�#r$r�r�s        r�uncomment_region_eventz#FormatRegion.uncomment_region_event,s���$(�?�?�#4�#4� ��d�E�5���U���$�$�	�	�C���:�D��
���B�Q�B�x�4����A�B�B�x����b�q�b��S����A�B�B�x���E�#�J�J�����d�E�5�1�1�1��wrc�h�|���\}}}}|���}|�dStt|����D]K}||}|r?t	||��\}	}
t|
|��\}}d|zd|zz||	d�z||<�L|�||||��dS)z@Convert leading spaces to tabs for each line in selected region.N�	rSr$)r��_asktabwidthrVrIr}�divmodr�)
r
r3r�r�r�r\r|r�rMr�r��ntabs�nspacess
             r�tabify_region_eventz FormatRegion.tabify_region_event?s���#'�?�?�#4�#4� ��d�E�5��$�$�&�&�����F���U���$�$�	G�	G�C���:�D��
G�!0��x�!@�!@���Y�!'�	�8�!<�!<���w�!�E�\�C�'�M�9�D����J�F��c�
������d�E�5�1�1�1��wrc��|���\}}}}|���}|�dStt|����D] }||�|��||<�!|�||||��dS)z.Expand tabs to spaces for each line in region.Nr$)r�r�rVrIrWr�)r
r3r�r�r�r\r|r�s        r�untabify_region_eventz"FormatRegion.untabify_region_eventNs���#'�?�?�#4�#4� ��d�E�5��$�$�&�&�����F���U���$�$�	9�	9�C��s��.�.�x�8�8�E�#�J�J�����d�E�5�1�1�1��wrc�T�tdd|jj|jjdd���S)zReturn value for tab width.z	Tab widthzColumns per tab? (2-16)rR���parent�initialvalue�minvalue�maxvalue)rrr%r�rs rr�zFormatRegion._asktabwidthYs5����%��<�$���1���
���	rr	)r;r<r=r>rr�r�r�r�r�r�r�r�r�r@rrrr�s�������$�$����(�(�(�,,�,�,�0
�
�
�
�
�
�
�
�
�
�
�
�����&
�
�
�
�	�	�	�	�����rrc�$�eZdZdZd�Zd�Zd�ZdS)�IndentszChange future indents.c��||_dSr	r
rs  rrzIndents.__init__grrc��|j}|j}tddd|zdzd|zdzdz|j���r||_d	|_d
S)NzToggle tabsz
Turn tabs )�on�offz?
Indent width )zwill bez
remains atz 8.z!
 Note: a tab is always 8 columns)r��r$)r�usetabsrr%r�)r
r3rr�s    r�toggle_tabs_eventzIndents.toggle_tabs_eventjs���,���/�����]�7�3�3� �!�'��0�1�38�9�3�3��\�
#�#�#�
	$�#*�k�G�O�#$�G���wrc��|j}tdd|j|jdd���}|r||jkr|js||_dS)NzIndent widthz6New indent width (2-16)
(Always use 8 when using tabs)rRr�r�r$)rrr%r�r�)r
r3rras    r�change_indentwidth_eventz Indents.change_indentwidth_eventzs_���,��� �K� ��&�2���
�����	&�3�'�-�-�-�g�o�-�"%�G���wrN)r;r<r=r>rr�r�r@rrr�r�dsG�������������� ����rr�c��eZdZd�Zdd�ZdS)�Rstripc��||_dSr	r
rs  rrzRstrip.__init__�rrNc�8�|jj}|jj}|���t	t|�d������}td|��D]r}|�d|zd|z��}t|��}t|�
����}||kr|�d||fzd|z���s|�d��dkr�t|jd��sy|�d	��d
kr`|�d��dkrG|�d��|�d	��d
kr|�d��dk�G|�
��dS)Nr#rDz%i.0z%i.endz%i.%izend-2crQ�interpzend-1cr"zend-3c)rr%�undor/r�floatr*rVr'rIrYr0�hasattrr1)	r
r3r%r��end_line�cur�txtr��cuts	         r�	do_rstripzRstrip.do_rstrip�s����|� ���|� ���������u�T�Z�Z��.�.�/�/�0�0����H�%�%�	B�	B�C��(�(�6�C�<��C��8�8�C��c�(�(�C��c�j�j�l�l�#�#�C��S�y�y����G�s�C�j�0�(�S�.�A�A�A���H�H�X���$�&�&��D�L�(�3�3�
'��:�:�h�'�'�%�/�/��x�x��)�)�T�1�1����H�%�%�%��:�:�h�'�'�%�/�/��x�x��)�)�T�1�1�	
�������rr	)r;r<r=rr�r@rrr�r��s7��������������rr��__main__)�mainzidlelib.idle_test.test_formatrRF)�	verbosity�exit)r>rU�tkinter.messageboxr�tkinter.simpledialogr�idlelib.configrrrr)r,r+rHrTr(�compiler{r}rr�r�r;�unittestr�r@rr�<module>r�s�����
�	�	�	�'�'�'�'�'�'�+�+�+�+�+�+�#�#�#�#�#�#�@�@�@�@�@�@�@�@�F������">�">�">�J"�"�"�HM�M�M�,0�0�0�
0�0�0�	�	�	��"�*�Y�'�'��8�8�8�M�M�M�M�M�M�M�M�`!�!�!�!�!�!�!�!�H��������@�z����������D�	(�A�E�B�B�B�B�B�B��r
© 2025 GrazzMean