HEX
Server: Apache
System: Linux bd12.noc223.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: handcraf (1693)
PHP: 8.1.28
Disabled: NONE
Upload Files
File: //opt/alt/python312/lib64/python3.12/test/__pycache__/test_readline.cpython-312.opt-1.pyc
�

�h�e	3���dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZm
Z
mZddlmZddlmZe
d�Zeed	�rd
ej*vZnejxrdejvZd�Zej0eed
�d�Gd�dej2��ZGd�dej2�Zedk(rej:�yy)z:
Very minimal unittests for parts of the readline module.
�N)�verbose)�
import_module)�unlink�temp_dir�TESTFN)�run_pty)�assert_python_ok�readline�_READLINE_LIBRARY_VERSIONzEditLine wrapper�libeditc�"�tr�ttd�r:tdtjd���tdtj
d���ttd�rtdtj���tdt���yy)N�_READLINE_VERSIONzreadline version: z#xzreadline runtime version: rzreadline library version: zuse libedit emulation? )r�hasattrr
�printr�_READLINE_RUNTIME_VERSIONr�is_editline���9/opt/alt/python312/lib64/python3.12/test/test_readline.py�setUpModulers|����8�0�1��&�x�'A�'A�"�&E�F�G��.�x�/Q�/Q�RT�.U�V�W��8�8�9��.�x�/Q�/Q�.T�U�V�
�'��}�5�6�r�
clear_historyzXThe history update test cannot be run because the clear_history method is not available.c�\�eZdZdZd�Zejeed�d�d��Z	d�Z
y)�TestHistoryManipulationz�
    These tests were added to check that the libedit emulation on OSX and the
    "real" readline have the same interface for history manipulation. That's
    why the tests cover only a small subset of the interface.
    c��tj�tjd�tjd�|jtj	d�d�|jtj	d�d�|jtj	d�d�tjdd�|jtj	d�d�|jtj	d�d�|jtj	d�d�|jtj
�d�tjd�|jtj	d�d�|jtj	d�d�|jtj
�d�y)N�
first line�second liner��z
replaced line)r
r�add_history�assertEqual�get_history_item�replace_history_item�get_current_history_length�remove_history_item)�selfs r�testHistoryUpdatesz*TestHistoryManipulation.testHistoryUpdates/sR����� ����\�*����]�+�����2�2�1�5�t�<�����2�2�1�5�|�D�����2�2�1�5�}�E��%�%�a��9�����2�2�1�5�t�<�����2�2�1�5��G�����2�2�1�5�}�E�����<�<�>��B��$�$�Q�'�����2�2�1�5�t�<�����2�2�1�5�}�E�����<�<�>��Br�append_history_filezappend_history not availablec��tjd��}|j�|j}|j	t
|�tj�tjd�tjd�tj|�tj�|jtj�d�tj|�|jtj�d�|jtjd�d�|jtjd�d�tjd|�tj�tj|�|jtj�d�|jtjd�d�|jtjd�d�|jtjd�d�tj
|�	tjd|�tj
|�tj|�y#t $rY�!wxYw)	NF)�deleterrrrr�)�tempfile�NamedTemporaryFile�close�name�
addCleanuprr
rr�write_history_filer r#�read_history_filer!r'�os�FileNotFoundError)r%�hfile�	hfilenames   r�test_write_read_appendz.TestHistoryManipulation.test_write_read_appendFs����+�+�5�9��
���
��J�J�	�����	�*�	��� ����\�*����]�+��#�#�I�.���� �����<�<�>��B��"�"�9�-�����<�<�>��B�����2�2�1�5�|�D�����2�2�1�5�}�E�	�$�$�Q�	�2���� ��"�"�9�-�����<�<�>��B�����2�2�1�5�|�D�����2�2�1�5�}�E�����2�2�1�5�}�E�	�	�	�)��	!��(�(��I�6�
�I�I�i� �	�#�#�I�.��!�	��	�s�?J�	J�Jc��tj�	tjd�tjd�tj
dd�tjt�|jtjt�tj�tjt�trtjd�|jtjd�d�|jtjd�d�y#t$r(}|j	dt|�z�Yd}~��'d}~wwxYw)Nu	entrée 1� Locale cannot encode test data: u	entrée 2ru
entrée 22�dummyr)r
rr�UnicodeEncodeError�skipTest�formatr"r0rr/r2�remover1rr r!)r%�errs  r�test_nonascii_historyz-TestHistoryManipulation.test_nonascii_historyts������ �	L�� � ��-�	���[�)��%�%�a��6��#�#�F�+�����	�	�6�*���� ��"�"�6�*��
� � ��)�����2�2�1�5�{�C�����2�2�1�5�|�D��"�	L��M�M�<�v�c�{�J�K�K��	L�s�D&�&	E�/E�EN)�__name__�
__module__�__qualname__�__doc__r&�unittest�
skipUnlessrr
r6r?rrrrr%sB���C�.�X�����+@�A�7�9�*/�9�*/�XErrc��eZdZejejdkxred�d��ZdZ	d�Z
d�Zd�Zd�Z
ejejd	kd
�ejed�d���Zy
)�TestReadlineiz%not supported in this library versionc�L�tddd��\}}}|j|d�y)Nz-czimport readlinezxterm-256color)�TERMr)r	r )r%�rc�stdout�stderrs    r�	test_initzTestReadline.test_init�s.��.�d�4E�3C�E���F�F������%rzvimport readline
readline.set_auto_history({})
input()
print("History length:", readline.get_current_history_length())
c�p�t|jjd��}|jd|�y)NTsHistory length: 1�r�auto_history_scriptr<�assertIn�r%�outputs  r�test_auto_history_enabledz&TestReadline.test_auto_history_enabled�s.����1�1�8�8��>�?��	
�
�
�*�F�3rc�p�t|jjd��}|jd|�y)NFsHistory length: 0rOrRs  r�test_auto_history_disabledz'TestReadline.test_auto_history_disabled�s.����1�1�8�8��?�@��	
�
�
�*�F�3rc�l�tjd�}t|d��}|jd|�y)Na
            import readline
            def complete(text, state):
                if state == 0 and text == "$":
                    return "$complete"
                return None
            if "libedit" in getattr(readline, "__doc__", ""):
                readline.parse_and_bind(r'bind "\t" rl_complete')
            else:
                readline.parse_and_bind(r'"\t": complete')
            readline.set_completer_delims(" \t\n")
            readline.set_completer(complete)
            print(input())
        s$	
)�inputs	$complete)�textwrap�dedentrrQ)r%�scriptrSs   r�test_set_complete_delimsz%TestReadline.test_set_complete_delims�s1�����
"�

����x�0���
�
�l�F�+rc���tjtjd�}|dvr|jd|���	tjd�d}d}|dtd�zz
}|d	z
}|d
z
}|dz
}t||�}|jd|�|jd
|�tjdk(sts|jd|�ts4ttd�r$|jd|�|jd|�d}|jd|zdz|�|jd|z|�y#t$r(}|jdt|�z�Yd}~��d}~wwxYw)N)�C�POSIXzthe LC_CTYPE locale is uëïr8a*import readline

is_editline = readline.__doc__ and "libedit" in readline.__doc__
inserted = "[\xEFnserted]"
macro = "|t\xEB[after]"
set_pre_input_hook = getattr(readline, "set_pre_input_hook", None)
if is_editline or not set_pre_input_hook:
    # The insert_line() call via pre_input_hook() does nothing with Editline,
    # so include the extra text that would have been inserted here
    macro = inserted + macro

if is_editline:
    readline.parse_and_bind(r'bind ^B ed-prev-char')
    readline.parse_and_bind(r'bind "\t" rl_complete')
    readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro))
else:
    readline.parse_and_bind(r'Control-b: backward-char')
    readline.parse_and_bind(r'"\t": complete')
    readline.parse_and_bind(r'set disable-completion off')
    readline.parse_and_bind(r'set show-all-if-ambiguous off')
    readline.parse_and_bind(r'set show-all-if-unmodified off')
    readline.parse_and_bind(r'Control-a: "{}"'.format(macro))

def pre_input_hook():
    readline.insert_text(inserted)
    readline.redisplay()
if set_pre_input_hook:
    set_pre_input_hook(pre_input_hook)

def completer(text, state):
    if text == "t\xEB":
        if state == 0:
            print("text", ascii(text))
            print("line", ascii(readline.get_line_buffer()))
            print("indexes", readline.get_begidx(), readline.get_endidx())
            return "t\xEBnt"
        if state == 1:
            return "t\xEBxt"
    if text == "t\xEBx" and state == 0:
        return "t\xEBxt"
    return None
readline.set_completer(completer)

def display(substitution, matches, longest_match_length):
    print("substitution", ascii(substitution))
    print("matches", ascii(matches))
readline.set_completion_display_matches_hook(display)

print("result", ascii(input()))
print("history", ascii(readline.get_history_item(1)))
��z[after]s		sx	�
stext 't\xeb'
s#line '[\xefnserted]|t\xeb[after]'
�darwinsindexes 11 13
�set_pre_input_hookssubstitution 't\xeb'
s matches ['t\xebnt', 't\xebxt']
s'[\xefnserted]|t\xebxt[after]'sresult s
shistory )�locale�	setlocale�LC_CTYPEr;r
rr:r<�lenrrQ�sys�platformrr)r%�locr>r[rXrS�expecteds       r�
test_nonasciizTestReadline.test_nonascii�s\�����v����5���.� �
�M�M�3�C�7�;�<�	L�� � ��,�2��h��
��3�y�>�)�)��
����
����
�������'���
�
�*�F�3��
�
�@�&�I��<�<�8�#�;��M�M�.��7��w�x�1E�F��M�M�6��?��M�M�A�6�J�5���
�
�j�8�+�g�5�v�>�	
�
�
�k�H�,�f�5��c"�	L��M�M�<�v�c�{�J�K�K��	L�s�D<�<	E-�E(�(E-iz3this readline version does not support history-sizez-editline history size configuration is brokenc	�"�d}t�5}tjj|d�}t	|d�5}|jd|z�ddd�tjj|d�}t	|d�5}djd�t
|dz�D��}|j|�ddd�d	}ttj�}||d
<||d<t|d|�
�t	|d�5}|j�}	ddd�|jt	�|�|j|	dj�d�ddd�y#1swY��xYw#1swY��xYw#1swY�ixYw#1swYyxYw)N�
�inputrc�wbsset history-size %d
�historyrc3�&K�|]	}d|z���y�w)sitem %d
Nr)�.0�is  r�	<genexpr>z1TestReadline.test_history_size.<locals>.<genexpr>*s���� B�$%�!-�q� 0� B�s�rz�
import os
import readline

history_file = os.environ["HISTORY_FILE"]
readline.read_history_file(history_file)
input()
readline.write_history_file(history_file)
�INPUTRC�HISTORY_FILEslast input
)rX�env�rb���s
last input)rr2�path�join�open�write�range�dict�environr�	readlinesr rh�strip)
r%�history_size�test_dirrp�f�history_file�datar[ry�liness
          r�test_history_sizezTestReadline.test_history_sizesp��
��
�Z�	?�8��g�g�l�l�8�Y�7�G��g�t�$�
A�����0�<�?�@�
A��7�7�<�<��)�<�L��l�D�)�
�Q��x�x� B�).�|�a�/?�)@� B�B������
�	
��F��r�z�z�"�C�$�C�	�N�".�C����F�/�s�;��l�D�)�
&�Q����
��
&����S��Z��6����U�2�Y�_�_�.�
�>�?	?�	?�
A�
A��
�
��,
&�
&��9	?�	?�sT�-F�E �4F�6E-�9AF�E9�AF� E*	�%F�-E6	�2F�9F	�>F�FN)r@rArBrD�skipIfr
rrrMrPrTrVr\rmr�rrrrGrG�s����X�_�_�X�/�/�&�8�L��_�<�>�&�>�&���4�4�,�&[6�D�X�_�_�X�/�/�%�7�J�L��X�_�_�[�D�F�!?�F�L�!?rrG�__main__)rCrer2rir+rYrD�test.supportr�test.support.import_helperr�test.support.os_helperrrr�test.support.pty_helperr�test.support.script_helperr	r
rrrrrE�TestCaserrGr@�mainrrr�<module>r�s�����	�
���� �4�;�;�+�7���$��
�8�0�1�%��)K�)K�K�K��#�#�E�	�X�5E�5E�(E�K�	7�����W�X��7�>�?�]E�x�0�0�]E�?�]E�@y?�8�$�$�y?�x�z���H�M�M�O�r