Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_readline.cpython-311.pyc
�

�Ke�8���dZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZmZddlmZed	��Zeed
��r
dejvZnejodejvZd
�Zejeed��d��Gd�dej����ZGd�dej��Zdd�Ze dkrej!��dSdS)z:
Very minimal unittests for parts of the readline module.
�)�	ExitStack)�EION)�verbose)�
import_module)�unlink�temp_dir�TESTFN)�assert_python_ok�readline�_READLINE_LIBRARY_VERSIONzEditLine wrapper�libeditc�F�tr�ttd��r:tdtjd����tdtjd����ttd��rtdtj����tdt����dSdS)N�_READLINE_VERSIONzreadline version: z#xzreadline runtime version: rzreadline library version: zuse libedit emulation? )r�hasattrr�printr�_READLINE_RUNTIME_VERSIONr�is_editline���</usr/local/apps/python3/lib/python3.11/test/test_readline.py�setUpModulers����7��8�0�1�1�	X��F�x�'A�F�F�F�G�G�G��V�x�/Q�V�V�V�W�W�W��8�8�9�9�	W��U�x�/Q�U�U�V�V�V�
�5��5�5�6�6�6�6�6�7�7r�
clear_historyzXThe history update test cannot be run because the clear_history method is not available.c�f�eZdZdZd�Zejeed��d��d���Z	d�Z
dS)�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��t���t�d��t�d��|�t�d��d��|�t�d��d��|�t�d��d��t�dd��|�t�d��d��|�t�d��d��|�t�d��d��|�t���d��t�d��|�t�d��d��|�t�d��d��|�t���d��dS)N�
first line�second liner��z
replaced line)rr�add_history�assertEqual�get_history_item�replace_history_item�get_current_history_length�remove_history_item)�selfs r�testHistoryUpdatesz*TestHistoryManipulation.testHistoryUpdates1s������ � � ����\�*�*�*����]�+�+�+�����2�2�1�5�5�t�<�<�<�����2�2�1�5�5�|�D�D�D�����2�2�1�5�5�}�E�E�E��%�%�a��9�9�9�����2�2�1�5�5�t�<�<�<�����2�2�1�5�5��G�G�G�����2�2�1�5�5�}�E�E�E�����<�<�>�>��B�B�B��$�$�Q�'�'�'�����2�2�1�5�5�t�<�<�<�����2�2�1�5�5�}�E�E�E�����<�<�>�>��B�B�B�B�Br�append_history_filezappend_history not availablec�$�tjd���}|���|j}|�t
|��t���t�d��t�d��t�	|��t���|�
t���d��t�|��|�
t���d��|�
t�
d��d��|�
t�
d��d��t�d|��t���t�|��|�
t���d��|�
t�
d��d��|�
t�
d��d��|�
t�
d��d��tj|��	t�d|��tj|��n#t $rYnwxYwt�	|��dS)	NF)�deleterrrrr�)�tempfile�NamedTemporaryFile�close�name�
addCleanuprrrr �write_history_filer!r$�read_history_filer"r(�os�FileNotFoundError)r&�hfile�	hfilenames   r�test_write_read_appendz.TestHistoryManipulation.test_write_read_appendHs����+�5�9�9�9��
���
�
�
��J�	�����	�*�*�*�	��� � � ����\�*�*�*����]�+�+�+��#�#�I�.�.�.���� � � �����<�<�>�>��B�B�B��"�"�9�-�-�-�����<�<�>�>��B�B�B�����2�2�1�5�5�|�D�D�D�����2�2�1�5�5�}�E�E�E�	�$�$�Q�	�2�2�2���� � � ��"�"�9�-�-�-�����<�<�>�>��B�B�B�����2�2�1�5�5�|�D�D�D�����2�2�1�5�5�}�E�E�E�����2�2�1�5�5�}�E�E�E�	�	�)����	!��(�(��I�6�6�6�
�I�i� � � � ��!�	�	�	��D�	����	�#�#�I�.�.�.�.�.s�6K&�&
K3�2K3c�D�t���	t�d��n<#t$r/}|�dt|��z��Yd}~nd}~wwxYwt�d��t�dd��t�t��|�	tjt��t���t�t��trt�d��|�t�d��d��|�t�d��d��dS)Nu	entrée 1� Locale cannot encode test data: u	entrée 2ru
entrée 22�dummyr)rrr �UnicodeEncodeError�skipTest�formatr#r1r	r0r3�remover2rr!r")r&�errs  r�test_nonascii_historyz-TestHistoryManipulation.test_nonascii_historyvsg����� � � �	L�� � ��-�-�-�-��!�	L�	L�	L��M�M�<�v�c�{�{�J�K�K�K�K�K�K�K�K�����	L�������[�)�)�)��%�%�a��6�6�6��#�#�F�+�+�+�����	�6�*�*�*���� � � ��"�"�6�*�*�*��	*�
� � ��)�)�)�����2�2�1�5�5�{�C�C�C�����2�2�1�5�5�|�D�D�D�D�Ds�6�
A/�%A*�*A/N)�__name__�
__module__�__qualname__�__doc__r'�unittest�
skipUnlessrrr7r@rrrrr's���������C�C�C�.�X�����+@�A�A�7�9�9�*/�*/�9�9�*/�XE�E�E�E�Errc���eZdZejejdkoed��d���ZdZ	d�Z
d�Zd�Zejejdkd	��ejed
��d�����Z
dS)
�TestReadlineiz%not supported in this library versionc�^�tddd���\}}}|�|d��dS)N�-czimport readlinezxterm-256color)�TERMr)r
r!)r&�rc�stdout�stderrs    r�	test_initzTestReadline.test_init�sF��.�d�4E�3C�E�E�E���F�F������%�%�%�%�%rzvimport readline
readline.set_auto_history({})
input()
print("History length:", readline.get_current_history_length())
c��t|j�d����}|�d|��dS)NTsHistory length: 1��run_pty�auto_history_scriptr=�assertIn�r&�outputs  r�test_auto_history_enabledz&TestReadline.test_auto_history_enabled�s=����1�8�8��>�>�?�?��	
�
�
�*�F�3�3�3�3�3rc��t|j�d����}|�d|��dS)NFsHistory length: 0rQrUs  r�test_auto_history_disabledz'TestReadline.test_auto_history_disabled�s=����1�8�8��?�?�@�@��	
�
�
�*�F�3�3�3�3�3rc�L�tjtjd��}|dvr|�d|����	t�d��n<#t$r/}|�dt|��z��Yd}~nd}~wwxYwd}d}|dtd��zz
}|d	z
}|d
z
}|dz
}t||��}|�
d|��|�
d
|��tjdksts|�
d|��tsAttd��r,|�
d|��|�
d|��d}|�
d|zdz|��|�
d|z|��dS)N)�C�POSIXzthe LC_CTYPE locale is uëïr9a*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<rr r;r=�lenrRrT�sys�platformrr)r&�locr?�script�inputrV�expecteds       r�
test_nonasciizTestReadline.test_nonascii�s�����v���5�5���.� � �
�M�M�;�C�;�;�<�<�<�	L�� � ��,�,�,�,��!�	L�	L�	L��M�M�<�v�c�{�{�J�K�K�K�K�K�K�K�K�����	L����2��h��
��3�y�>�>�)�)��
����
����
�������'�'���
�
�*�F�3�3�3��
�
�@�&�I�I�I��<�8�#�#�;�#��M�M�.��7�7�7��	K�w�x�1E�F�F�	K��M�M�6��?�?�?��M�M�A�6�J�J�J�5���
�
�j�8�+�g�5�v�>�>�>�	
�
�
�k�H�,�f�5�5�5�5�5s�A�
B�"%B�Biz3this readline version does not support history-sizez-editline history size configuration is brokenc	��d}t��5}tj�|d��}t	|d��5}|�d|z��ddd��n#1swxYwYtj�|d��}t	|d��5}d�d�t
|dz��D����}|�|��ddd��n#1swxYwYd	}ttj��}||d
<||d<t|d|�
��t	|d��5}|�
��}	ddd��n#1swxYwY|�t|	��|��|�|	d�
��d��ddd��dS#1swxYwYdS)N�
�inputrc�wbsset history-size %d
�historyrc3� K�|]	}d|zV��
dS)sitem %d
Nr)�.0�is  r�	<genexpr>z1TestReadline.test_history_size.<locals>.<genexpr>sC���� B� B�$%�!-�q� 0� B� B� B� B� B� Brrz�
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
)rj�env�rb���s
last input)rr3�path�join�open�write�range�dict�environrR�	readlinesr!re�strip)
r&�history_size�test_dirro�f�history_file�datarirx�liness
          r�test_history_sizezTestReadline.test_history_sizes���
��
�Z�Z�	?�8��g�l�l�8�Y�7�7�G��g�t�$�$�
A�����0�<�?�@�@�@�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A����
A�
A�
A�
A��7�<�<��)�<�<�L��l�D�)�)�
�Q��x�x� B� B�).�|�a�/?�)@�)@� B� B� B�B�B������
�
�
�	
�
�
�
�
�
�
�
�
�
�
����
�
�
�
��F��r�z�"�"�C�$�C�	�N�".�C����F�/�s�;�;�;�;��l�D�)�)�
&�Q����
�
��
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&����S��Z�Z��6�6�6����U�2�Y�_�_�.�.�
�>�>�>�?	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?�	?�	?s��1G�A'�G�'A+	�+G�.A+	�/3G�"AC3�'G�3C7	�7G�:C7	�;A
G�E&�G�&E*	�*G�-E*	�.AG�G�GN)rArBrCrE�skipIfrrrrOrSrWrYrlr�rrrrHrH�s��������X�_�X�/�&�8�L��_�<�>�>�&�&�>�>�&���4�4�4�4�4�4�[6�[6�[6�D�X�_�X�/�%�7�J�L�L��X�_�[�D�F�F�!?�!?�F�F�L�L�!?�!?�!?rrH�dummy input
c��td��}t��}|���\}}tjd|f}tj|||||���}tj|��t��5}	|	�
|��d�}
|	�|
|��|	�tj|��|	�
tj
����}|�|tjtjz��tj|d��	|���D]�\}}
|
tjzrh	tj|d��}n*#t($r}|jt,kr�d}Yd}~nd}~wwxYw|s|ccddd��S|�|��|
tjzrk	|tj||��d�}n*#t($r}|jt,kr�d}Yd}~nd}~wwxYw|s |�|tj������
#1swxYwYdS)	N�ptyrJ)�stdinrMrNrxc�R�	|���dS#t$rYdSwxYw)N)�	terminate�ProcessLookupError)�procs rr�zrun_pty.<locals>.terminate<s?��
���� � � � � ��%�
�
�
����
���s��
&�&FTir)r�	bytearray�openptyrf�
executable�
subprocess�Popenr3r.r�
enter_context�callback�	selectors�SelectSelector�register�
EVENT_READ�EVENT_WRITE�set_blocking�select�read�OSError�errnor�extendr~�modify)rirjrxr�rV�master�slave�argsr��cleanupr��sel�_�events�chunkr?s                rrRrR3s���
��
�
�C�
�[�[�F��k�k�m�m�O�V�U��N�D�&�)�D���D��e�E�s�S�S�S�D��H�U�O�O�O�	���(A�����d�#�#�#�	�	�	�	����D�)�)�)������6�*�*�*��#�#�I�$<�$>�$>�?�?�����V�Y�1�I�4I�I�J�J�J�
����&�&�&�	A�"�z�z�|�|�
A�
A���F��I�0�0�
)�$� "���� 8� 8����"�$�$�$��9��+�+�!� #�����������	$����
!�&�%�
�
�;(A�(A�(A�(A�(A�(A�(A�(A�<�M�M�%�(�(�(��I�1�1�	A�$� %�b�h�v�u�&=�&=�&>�&>� ?����"�$�$�$��9��+�+�!� #�����������	$����
!�A��
�
�6�9�+?�@�@�@��-	A�%(A�(A�(A�(A����(A�(A�(A�(A�(A�(Asm�?C I� E6�5I�6
F�F�I�F�I�2$I�G5�4I�5
H�?H�I�H�(I�I�I�__main__)r�N)"rD�
contextlibrr�rrbr3r�r�rfr,rE�test.supportr�test.support.import_helperr�test.support.os_helperrrr	�test.support.script_helperr
rrrrrrF�TestCaserrHrRrA�mainrrr�<module>r�s����!� � � � � �������
�
�
�
�	�	�	�	���������
�
�
�
��������� � � � � � �4�4�4�4�4�4�;�;�;�;�;�;�;�;�;�;�7�7�7�7�7�7��=��$�$��
�7�8�0�1�1�G�%��)K�K�K�K��#�E�	�X�5E�(E�K�	7�	7�	7����W�W�X��7�7�>�?�?�]E�]E�]E�]E�]E�x�0�]E�]E�?�?�]E�@f?�f?�f?�f?�f?�8�$�f?�f?�f?�R/A�/A�/A�/A�d�z����H�M�O�O�O�O�O��r