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.7/test/__pycache__/test_readline.cpython-37.pyc
B

��g�3�@sdZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZmZmZddlmZe
d�Zeed�r�d	ejkZnejo�d
ejkZdd�Ze�eed
�d�Gdd�dej��ZGdd�dej�Zddd�Zedk�re��dS)z:
Very minimal unittests for parts of the readline module.
�)�	ExitStack)�EION)�
import_module�unlink�temp_dir�TESTFN�verbose)�assert_python_ok�readline�_READLINE_LIBRARY_VERSIONzEditLine wrapper�libeditcCs^trZttd�r2tdtjd���tdtjd���ttd�rLtdtj���tdt���dS)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.7/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)Nz
first linezsecond liner��z
replaced line)r
r�add_history�assertEqual�get_history_item�replace_history_item�get_current_history_lengthZremove_history_item)�selfrrr�testHistoryUpdates/s


z*TestHistoryManipulation.testHistoryUpdates�append_history_filezappend_history not availablec	Cs@tjdd�}|��|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�|�|�t��t�d|�WdQRXt�	|�dS)	NF)�deletez
first linezsecond linerrr�)�tempfileZNamedTemporaryFile�close�name�
addCleanuprr
rr�write_history_filerr�read_history_filerr�osZassertRaises�FileNotFoundError)rZhfileZ	hfilenamerrr�test_write_read_appendFs2





z.TestHistoryManipulation.test_write_read_appendc
Cs�t��yt�d�Wn4tk
rJ}z|�dt|��Wdd}~XYnXt�d�t�dd�t�t�|�	t
jt�t��t�t�t
r�t�d�|�t�d�d�|�t�d�d�dS)Nu	entrée 1z 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_historyms$



z-TestHistoryManipulation.test_nonascii_historyN)�__name__�
__module__�__qualname__�__doc__r�unittest�
skipUnlessrr
r*r0rrrrr%s
&rc@sneZdZe�ejdkoe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)Nz-czimport readlinezxterm-256color)ZTERM�)r	r)rZrc�stdout�stderrrrr�	test_init�szTestReadline.test_initzvimport readline
readline.set_auto_history({})
input()
print("History length:", readline.get_current_history_length())
cCs t|j�d��}|�d|�dS)NTsHistory length: 1
)�run_pty�auto_history_scriptr-�assertIn)r�outputrrr�test_auto_history_enabled�sz&TestReadline.test_auto_history_enabledcCs t|j�d��}|�d|�dS)NFsHistory length: 0
)r<r=r-r>)rr?rrr�test_auto_history_disabled�sz'TestReadline.test_auto_history_disabledc
Cst�tjd�}|dkr&|�d|���yt�d�Wn4tk
rh}z|�dt|��Wdd}~XYnXd}d}|dtd�7}|d	7}|d
7}|d7}t	||�}|�
d|�|�
d
|�|�
d|�ts�ttd�r�|�
d|�|�
d|�d}|�
d|d|�|�
d|d|�dS)N)�CZPOSIXzthe LC_CTYPE locale is uëïz Locale cannot encode test data: 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]'
sindexes 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_CTYPEr,r
rr+r-�lenr<r>rr)r�locr/�script�inputr?Zexpectedrrr�
test_nonascii�s.$4
zTestReadline.test_nonasciiiz3this readline version does not support history-sizez-editline history size configuration is brokenc

Csd}t���}tj�|d�}t|d��}|�d|�WdQRXtj�|d�}t|d��,}d�dd�t|d	�D��}|�|�WdQRXd
}ttj�}||d<||d<t	|d
|d�t|d��}|�
�}	WdQRX|�t|	�|�|�|	d�
�d�WdQRXdS)N�
�inputrc�wbsset history-size %d
�historyr8css|]}d|VqdS)sitem %d
Nr)�.0�irrr�	<genexpr>sz1TestReadline.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
)rL�env�rb���s
last input)rr(�path�join�open�write�range�dict�environr<�	readlinesrrI�strip)
rZhistory_sizeZtest_dirrO�fZhistory_file�datarKrU�linesrrr�test_history_size�s&


zTestReadline.test_history_sizeN)r1r2r3r5ZskipIfr
r
rr;r=r@rArMrdrrrrr7�sVr7�dummy input
cCs�td�}t�}|��\}}tjd|f}tj|||||d�}t�|�t	���N}	|	�
|�dd�}
|	�|
|�|	�tj|�|	�
t�
��}|�|tjtjB�t�|d�x�x�|��D]�\}}
|
tj@�r"yt�|d�}Wn4tk
�r}z|jtkr��d}Wdd}~XYnX|�s|S|�|�|
tj@r�y|t�||�d�}Wn6tk
�rz}z|jtk�rf�d}Wdd}~XYnX|s�|�|tj�q�Wq�WWdQRXdS)	N�ptyz-c)�stdinr9r:rUcSs&y|��Wntk
r YnXdS)N)�	terminate�ProcessLookupError)�procrrrrh#szrun_pty.<locals>.terminateFir8)r�	bytearray�openpty�sys�
executable�
subprocess�Popenr(r#r�
enter_context�callback�	selectorsZSelectSelector�registerZ
EVENT_READZEVENT_WRITE�set_blockingZselect�read�OSError�errnor�extendr[Zmodify)rKrLrUrfr?ZmasterZslave�argsrjZcleanuprhZsel�_Zevents�chunkr/rrrr<sF





r<�__main__)reN) r4�
contextlibrrxrrFr(rsrormr"r5Ztest.supportrrrrrZtest.support.script_helperr	r
rrrrr6ZTestCaserr7r<r1�mainrrrr�<module>s0

Y
2