HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/test/__pycache__/test_readline.cpython-36.pyc
3


 \1�@s�dZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZmZddlmZe
d�Zejo�dejkZejeed	�d
�Gdd�dej��ZGd
d�dej�Zddd�Zedkr�ej�dS)z:
Very minimal unittests for parts of the readline module.
�)�	ExitStack)�EION)�
import_module�unlink�temp_dir�TESTFN)�assert_python_ok�readline�libedit�
clear_historyzXThe history update test cannot be run because the clear_history method is not available.c@s:eZdZdZdd�Zejeed�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�tj�tjd�tjd�|jtjd�d�|jtjd�d�|jtjd�d�tjdd�|jtjd�d�|jtjd�d�|jtjd�d�|jtj�d�tjd�|jtjd�d�|jtjd�d�|jtj�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)�self�r�%/usr/lib64/python3.6/test_readline.py�testHistoryUpdatess


z*TestHistoryManipulation.testHistoryUpdates�append_history_filezappend_history not availablec
Cs@tjdd�}|j�|j}|jt|�tj�tjd�tjd�tj	|�tj�|j
tj�d�tj|�|j
tj�d�|j
tj
d�d�|j
tj
d�d�tjd|�tj�tj|�|j
tj�d�|j
tj
d�d�|j
tj
d�d�|j
tj
d�d�tj|�|jt��tjd|�WdQRXtj	|�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_append6s2





z.TestHistoryManipulation.test_write_read_appendcCs�tj�ytjd�Wn4tk
rJ}z|jdt|��WYdd}~XnXtjd�tjdd�tjt�|j	t
jt�tj�tjt�t
r�tjd�|jtjd�d�|jtjd�d�dS)Nu	entrée 1z Locale cannot encode test data: u	entrée 2r
u
entrée 22Zdummyr)r	rr�UnicodeEncodeError�skipTest�formatrrrrr!�remover �is_editlinerr)r�errrrr�test_nonascii_history]s$



z-TestHistoryManipulation.test_nonascii_historyN)�__name__�
__module__�__qualname__�__doc__r�unittest�
skipUnless�hasattrr	r#r*rrrrrs
&rc@sneZdZejejdkoed�dd��ZdZ	dd�Z
dd	�Zd
d�Zejejdkd
�ejed�dd���Z
dS)�TestReadlineiz%not supported in this library versioncCs$tdddd�\}}}|j|d�dS)Nz-czimport readlinezxterm-256color)ZTERM�)rr)rZrc�stdout�stderrrrr�	test_initsszTestReadline.test_initzvimport readline
readline.set_auto_history({})
input()
print("History length:", readline.get_current_history_length())
cCs t|jjd��}|jd|�dS)NTsHistory length: 1
)�run_pty�auto_history_scriptr&�assertIn)r�outputrrr�test_auto_history_enabled�sz&TestReadline.test_auto_history_enabledcCs t|jjd��}|jd|�dS)NFsHistory length: 0
)r7r8r&r9)rr:rrr�test_auto_history_disabled�sz'TestReadline.test_auto_history_disabledcCs tjtjd�}|dkr&|jd|���ytjd�Wn4tk
rh}z|jdt|��WYdd}~XnXd}d}|dtd	�7}|d
7}|d7}|d7}t	||�}|j
d
|�|j
d|�|j
d|�tr�ttd�r�|j
d|�|j
d|�d}|j
d|d|�|j
d|d|�dS)N�C�POSIXzthe 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 )r=r>)
�locale�	setlocale�LC_CTYPEr%r	rr$r&�lenr7r9r(r1)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���}tjj|d�}t|d��}|jd|�WdQRXtjj|d�}t|d��,}djdd�t|d	�D��}|j|�WdQRXd
}ttj�}||d<||d<t	|d
|d�t|d��}|j
�}	WdQRX|jt|	�|�|j|	dj
�d�WdQRXdS)N�
�inputrc�wbsset history-size %d
�historyr3css|]}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
)rH�env�rbr
s
last input���)rr!�path�join�open�write�range�dict�environr7�	readlinesrrE�strip)
rZhistory_sizeZtest_dirrK�fZhistory_file�datarGrQ�linesrrr�test_history_size�s&


zTestReadline.test_history_sizeN)r+r,r-r/ZskipIfr	Z_READLINE_VERSIONr(r6r8r;r<rIr`rrrrr2qsVr2�dummy input
c'Cs�td�}t�}|j�\}}tjd|f}tj|||||d�}tj|�t	���N}	|	j
|�dd�}
|	j|
|�|	jtj|�|	j
tj
��}|j|tjtjB�tj|d�x�x�|j�D]�\}}
|
tj@�r"ytj|d�}Wn4tk
�r}z|jtkr��d}WYdd}~XnX|�s|S|j|�|
tj@r�y|tj||�d�}Wn6tk
�rz}z|jtk�rf�d}WYdd}~XnX|s�|j|tj�q�Wq�WWdQRXdS)	N�ptyz-c)�stdinr4r5rQcSs&y|j�Wntk
r YnXdS)N)�	terminate�ProcessLookupError)�procrrrrdszrun_pty.<locals>.terminateFir3)r�	bytearray�openpty�sys�
executable�
subprocess�Popenr!rr�
enter_context�callback�	selectorsZSelectSelector�registerZ
EVENT_READZEVENT_WRITE�set_blockingZselect�read�OSError�errnor�extendrWZmodify)rGrHrQrbr:ZmasterZslave�argsrfZcleanuprdZsel�_Zevents�chunkr)rrrr7
sF





r7�__main__)raN)r.�
contextlibrrtrrBr!rorkrirr/Ztest.supportrrrrZtest.support.script_helperrr	r(r0r1ZTestCaserr2r7r+�mainrrrr�<module>s*
Y
2