HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_readline.cpython-310.pyc
o

�i�8�@sdZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZmZmZddlmZed	�Zeed
�rUdejvZnejo\dejvZd
d�Ze�eed�d�Gdd�dej��ZGdd�dej�Zddd�Ze dkr�e�!�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�libeditcCsbtr/ttd�rtdtjd���tdtjd���ttd�r&tdtj���tdt���dSdS)N�_READLINE_VERSIONzreadline version: z#xzreadline runtime version: rzreadline library version: zuse libedit emulation? )r�hasattrr
�printr
Z_READLINE_RUNTIME_VERSIONr�is_editline�rr�//usr/local/lib/python3.10/test/test_readline.py�setUpModules

�r�
clear_historyzXThe history update test cannot be run because the clear_history method is not available.c@s:eZdZdZdd�Ze�eed�d�dd��Z	dd	�Z
d
S)�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.
    cCs�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)r
r�add_history�assertEqual�get_history_item�replace_history_item�get_current_history_lengthZremove_history_item)�selfrrr�testHistoryUpdates1s


z*TestHistoryManipulation.testHistoryUpdates�append_history_filezappend_history not availablecCsLtjdd�}|��|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�t�|�zt�d|�Wn	ty�Ynwt�|�t�	|�dS)	NF)�deleterrrrr�)�tempfile�NamedTemporaryFile�close�name�
addCleanuprr
rr�write_history_filerr�read_history_filerr!�os�FileNotFoundError)rZhfileZ	hfilenamerrr�test_write_read_appendHs:





�
z.TestHistoryManipulation.test_write_read_appendc
Cs�t��zt�d�Wnty&}z|�dt|��WYd}~nd}~wwt�d�t�dd�t�t�|�	t
jt�t��t�t�t
rNt�d�|�t�d�d�|�t�d�d�dS)Nu	entrée 1� Locale cannot encode test data: u	entrée 2ru
entrée 22Zdummyr)r
rr�UnicodeEncodeError�skipTest�formatrr)rr(r+�remover*rrr)r�errrrr�test_nonascii_historyvs"��



z-TestHistoryManipulation.test_nonascii_historyN)�__name__�
__module__�__qualname__�__doc__r �unittest�
skipUnlessrr
r-r4rrrrr's�
,rc@sneZdZe�ejdko
ed�dd��ZdZ	dd�Z
dd	�Zd
d�Ze�ejdkd
�e�ed�dd���Z
dS)�TestReadlineiz%not supported in this library versioncCs$tdddd�\}}}|�|d�dS)N�-czimport readlinezxterm-256color)ZTERM�)r	r)r�rc�stdout�stderrrrr�	test_init�s�zTestReadline.test_initzvimport readline
readline.set_auto_history({})
input()
print("History length:", readline.get_current_history_length())
cC� t|j�d��}|�d|�dS)NTsHistory length: 1��run_pty�auto_history_scriptr1�assertIn�r�outputrrr�test_auto_history_enabled��z&TestReadline.test_auto_history_enabledcCrB)NFsHistory length: 0rCrGrrr�test_auto_history_disabled�rJz'TestReadline.test_auto_history_disabledc
Cs*t�tjd�}|dvr|�d|���zt�d�Wnty5}z|�dt|��WYd}~nd}~wwd}d}|dtd�7}|d	7}|d
7}|d7}t	||�}|�
d|�|�
d
|�tjdksft
sl|�
d|�t
sttd�r|�
d|�|�
d|�d}|�
d|d|�|�
d||�dS)N)�CZPOSIXzthe LC_CTYPE locale is uëïr.a*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
Zset_pre_input_hookssubstitution 't\xeb'
s matches ['t\xebnt', 't\xebxt']
s'[\xefnserted]|t\xebxt[after]'sresult s
shistory )�locale�	setlocale�LC_CTYPEr0r
rr/r1�lenrDrF�sys�platformrr)r�locr3�script�inputrHZexpectedrrr�
test_nonascii�s4��4

zTestReadline.test_nonasciiiz3this readline version does not support history-sizez-editline history size configuration is brokenc
	CsVd}t���}tj�|d�}t|d��}|�d|�Wd�n1s$wYtj�|d�}t|d��}d�dd�t|d	�D��}|�|�Wd�n1sSwYd
}ttj�}||d<||d<t	|d
|d�t|d��}|�
�}	Wd�n1s�wY|�t|	�|�|�|	d�
�d�Wd�dS1s�wYdS)N�
�inputrc�wbsset history-size %d
�historyr=css�|]}d|VqdS)sitem %d
Nr)�.0�irrr�	<genexpr>s��z1TestReadline.test_history_size.<locals>.<genexpr>rz�
import os
import readline

history_file = os.environ["HISTORY_FILE"]
readline.read_history_file(history_file)
input()
readline.write_history_file(history_file)
ZINPUTRCZHISTORY_FILEslast input
)rY�env�rb���s
last input)rr+�path�join�open�write�range�dict�environrD�	readlinesrrT�strip)
rZhistory_sizeZtest_dirr\�fZhistory_file�datarXrb�linesrrr�test_history_sizes0�

��


�"�zTestReadline.test_history_sizeN)r5r6r7r9ZskipIfr
r
rrArErIrKrZrqrrrrr;�s �
b��r;�dummy input
cCs�td�}t�}|��\}}tjd|f}tj|||||d�}t�|�t	���}	|	�
|�dd�}
|	�|
|�|	�tj|�|	�
t�
��}|�|tjtjB�t�|d�	|��D]s\}}
|
tj@r�zt�|d�}Wnty�}z|jtkrw�d	}WYd}~nd}~ww|s�|Wd�S|�|�|
tj@r�z|t�||�d�}Wnty�}z|jtkr��d	}WYd}~nd}~ww|s�|�|tj�qXqT1s�wYdS)
N�ptyr<)�stdinr?r@rbcSs$z|��WdStyYdSw)N)�	terminate�ProcessLookupError)�procrrrru<s
�zrun_pty.<locals>.terminateFTir=)r�	bytearray�openptyrU�
executable�
subprocess�Popenr+r&r�
enter_context�callback�	selectors�SelectSelector�register�
EVENT_READ�EVENT_WRITE�set_blocking�select�read�OSError�errnor�extendrh�modify)rXrYrbrsrHZmasterZslave�argsrw�cleanupruZsel�_�events�chunkr3rrrrD3sV



���


�����rD�__main__)rrN)"r8�
contextlibrr�rrQr+rr{rUr$r9Ztest.supportrZtest.support.import_helperrZtest.support.os_helperrrrZtest.support.script_helperr	r
rrrrr:ZTestCaserr;rDr5�mainrrrr�<module>s:
�`
*2�