Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_telnetlib.cpython-39.pyc

a

��g�2�@s8ddlZddlZddlZddlZddlZddlmZddlmZddl	Z	ej
Z
dd�ZGdd�de	j�Z
Gdd	�d	e�ZGd
d�dej�ZGdd
�d
ej�Zejdd��Zdefdd�ZGdd�de	j�ZGdd�de�ZGdd�de�ZeZGdd�de	j�ZGdd�de	j�ZGdd�de�Zedk�r4e	��dS) �N)�support)�
socket_helpercCsZ|��|��z:z|��\}}|��Wntjy>Yn0W|��n
|��0dS�N)�listen�set�accept�close�socket�timeout)�evtZserv�conn�addr�r�//usr/local/lib/python3.9/test/test_telnetlib.py�server
src@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�GeneralTestscCsrt��|_t�tjtj�|_|j�d�t�	|j�|_
tjt|j|jfd�|_
|j
�d�|j
��|j��dS)N�<)�target�argsT)�	threading�Eventrr	�AF_INET�SOCK_STREAM�sock�
settimeoutrZ	bind_port�port�Threadr�thread�	setDaemon�start�wait��selfrrr�setUps

zGeneralTests.setUpcCs|j��|`dSr)r�joinr!rrr�tearDown$s
zGeneralTests.tearDowncCst�t|j�}|j��dSr)�	telnetlib�Telnet�HOSTrrr�r"�telnetrrr�	testBasic(szGeneralTests.testBasiccCsNt�t|j��}|�|���Wd�n1s20Y|�|���dSr)r&r'r(rZassertIsNotNone�
get_socketZassertIsNone)r"�tnrrr�testContextManager-s,zGeneralTests.testContextManagerc	Csf|�t��du�t�d�zt�t|j�}Wt�d�nt�d�0|�|j	�
�d�|j	��dS)N�)�
assertTruer	�getdefaulttimeout�setdefaulttimeoutr&r'r(r�assertEqualr�
gettimeoutrr)rrr�testTimeoutDefault2s
zGeneralTests.testTimeoutDefaultc	Csl|�t��du�t�d�z tjt|jdd�}Wt�d�nt�d�0|�|j�	�du�|j�
�dS�Nr/)r
)r0r	r1r2r&r'r(rrr4rr)rrr�testTimeoutNone<s
zGeneralTests.testTimeoutNonecCs2tjt|jdd�}|�|j��d�|j��dSr6)r&r'r(rr3rr4rr)rrr�testTimeoutValueGszGeneralTests.testTimeoutValuecCs:t��}|jt|jdd�|�|j��d�|j��dSr6)	r&r'�openr(rr3rr4rr)rrr�testTimeoutOpenLszGeneralTests.testTimeoutOpencCsJtjt|jdd�}|j}|�|��|�|�|��|���|j��dSr6)	r&r'r(rrr3r,�filenor)r"r*Zt_sockrrr�testGettersRs
zGeneralTests.testGettersN)�__name__�
__module__�__qualname__r#r%r+r.r5r7r8r:r<rrrrrs

rc@s*eZdZdZd
dd�Zdd�Zdd�Zd	S)�
SocketStubz* a socket proxy that re-defines sendall() rcCst|�|_g|_d|_dS)NF)�list�reads�writes�block)r"rBrrr�__init__\s
zSocketStub.__init__cCs|j�|�dSr)rC�append)r"�datarrr�sendall`szSocketStub.sendallcCsZd}|jr(t|�|kr(||j�d�7}qt|�|krV|j�d||d��|d|�}|S)N�r)rB�len�pop�insert)r"�size�outrrr�recvbszSocketStub.recvN)r)r=r>r?�__doc__rErHrOrrrrr@Zs
r@c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TelnetAlikecCs
t��dSr)�NotImplementedErrorr!rrrr;lszTelnetAlike.filenocCsdSrrr!rrrrnrIzTelnetAlike.closecCs
|jjSr)rrDr!rrr�
sock_availoszTelnetAlike.sock_availcGsTt���&}tjj||g|�R�Wd�n1s40Y|j|��7_dSr)rZcaptured_stdoutr&r'�msg�	_messages�getvalue)r"rTrrNrrrrTqs
4zTelnetAlike.msgN)r=r>r?r;rrSrTrrrrrQksrQc@sDeZdZdd�Zedd��Zddd�Zdd	�Zdd
d�Zdd
�Z	dS)�MockSelectorcCs
i|_dSr��keysr!rrrrEyszMockSelector.__init__cCsdS)Ng����MbP?rr!rrr�
resolution|szMockSelector.resolutionNcCst�|d||�}||j|<|S)Nr)�	selectors�SelectorKeyrY)r"�fileobj�eventsrG�keyrrr�register�s
zMockSelector.registercCs|j�|�Sr)rYrK)r"r]rrr�
unregister�szMockSelector.unregistercCsFd}|jD]}t|t�r
|jj}q&q
|r.gSdd�|j��D�SdS)NFcSsg|]}||jf�qSr)r^)�.0r_rrr�
<listcomp>�rIz'MockSelector.select.<locals>.<listcomp>)rY�
isinstancerQrrD�values)r"r
rDr]rrr�select�s

zMockSelector.selectcCs|jSrrXr!rrr�get_map�szMockSelector.get_map)N)N)
r=r>r?rE�propertyrZr`rarfrgrrrrrWws


rWc#s6�fdd�}ztj}|t_dVW|t_n|t_0dS)Ncst��Sr)r@)Zignored�rBrr�new_conn�sztest_socket.<locals>.new_conn)r	�create_connection)rBrjZold_connrrir�test_socket�srlrcCsZ|D]}t|�tusJ|��qt|�� |dd�}d|_Wd�n1sL0Y|S)za return a telnetlib.Telnet object that uses a SocketStub with
        reads queued up to be read �dummyr�N)�type�bytesrlrU)rB�cls�xr*rrr�test_telnet�s

$rsc@seZdZdd�Zdd�ZdS)�ExpectAndReadTestCasecCstj|_tt_dSr)r&�_TelnetSelector�old_selectorrWr!rrrr#�szExpectAndReadTestCase.setUpcCs|jt_dSr)rvr&rur!rrrr%�szExpectAndReadTestCase.tearDownN)r=r>r?r#r%rrrrrt�srtc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�	ReadTestscCsrdg}t|�}|�d�}|j|d|j|j|jjfd�gd�}d�|dd��}t|�}|�d�}|�||�dS)	zc
        read_until(expected, timeout=None)
        test the blocking version of read_util
        sxxxmatchyyy�matchsxxxmatch)rT)s2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrxs2yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrIN���)rsZ
read_untilr3ZcookedqZrawqrrBr$)r"�wantr*rGrB�expectrrr�test_read_until�s

zReadTests.test_read_untilcCs2gd�}d�|�}t|�}|��}|�||�dS)zJ
        read_all()
          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zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzrIN)r$rs�read_allr3)r"rBr{r*rGrrr�
test_read_all�s
zReadTests.test_read_allcCsBtdg�}|��}|�t|�dk�t�}|��}|�d|�dS)zQ
        read_some()
          Read at least one byte or EOF; may block.
        r}�rIN)rsZ	read_somer0rJr3)r"r*rGrrr�test_read_some�s
zReadTests.test_read_somecCsrd}t|g�}t||�}d|j_|�d|��d|j_d}z||�7}Wq:ty^YqbYq:0q:|�||�dS)z
        read_*_eager()
          Read all data available already queued or on the socket,
          without blocking.
        �dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxTrIFN)rs�getattrrrDr3�EOFError)r"�	func_namerzr*�funcrGrrr�_read_eager�s

zReadTests._read_eagercCs|�d�|�d�dS)NZ
read_eagerZread_very_eager)r�r!rrr�test_read_eager�s
zReadTests.test_read_eagercCsVd}t|g�}|�d|���|jjr0|��q|��}|�||�|�t|j�dS�Nr�rI)rsr3�read_very_lazyrrB�	fill_rawqZassertRaisesr�)r"rzr*rGrrrr��s

zReadTests.read_very_lazycCs|d}t|g�}|�d|���d}z |��}||7}|s@|��WntyXYqlYn0|�|�|��q"|�||�dSr�)rsr3Z	read_lazyr�r�r0�
startswith)r"rzr*rGZ	read_datarrr�test_read_lazys

zReadTests.test_read_lazyN)
r=r>r?r|rr�r�r�r�r�rrrrrw�s
rwc@seZdZddd�Zdd�ZdS)�nego_collectorNcCsd|_||_d|_dS)NrI)�seen�	sb_getter�sb_seen)r"r�rrrrEsznego_collector.__init__cCs<|j||7_|tjkr8|jr8|��}|j|7_dSr)r��tl�SEr�r�)r"r�cmd�optZsb_datarrr�do_negosznego_collector.do_nego)N)r=r>r?rEr�rrrrr�s
r�c@seZdZdZdd�ZdS)�
WriteTestszKThe only thing that write does is replace each tl.IAC for
    tl.IAC+tl.IACcCszddtjddtjtjdtjtjdg}|D]@}t�}|�|�d�|jj�}|�|�tjtjtj�|�q4dS)Nsdata sample without IACsdata sample withs one IACsa fews iacsrI)	r��IACrs�writer$rrCr3�replace)r"Zdata_samplerGr*Zwrittenrrr�
test_write(s�
zWriteTests.test_writeN)r=r>r?rPr�rrrrr�$sr�c@s`eZdZejejejejejej	ej
ejgZdd�Z
dd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�OptionTestscCs�t|�}td�|��}t�}|�|j�|��}|j}|�t|�dk�|�	|dd�|j
�|�|dd�tj
�|�|t||��d|_dS)z helper for testing IAC + cmd rIrNr��)rsrJr$r��set_option_negotiation_callbackr�r~r�r0�assertIn�cmdsr3r�ZNOOPTr�)r"rGr*Zdata_len�nego�txtr�rrr�
_test_command8szOptionTests._test_commandcCs^|jD]<}|�tj|g�|�dtj|dg�|�dtj|dg�q|�dd�|jD��dS)Nr�sdyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy�
xxxxxxxxxx�
yyyyyyyyyycSsg|]}tj|�qSr)r�r�)rbr�rrrrcLrIz1OptionTests.test_IAC_commands.<locals>.<listcomp>)r�r�r�r�)r"r�rrr�test_IAC_commandsFs

zOptionTests.test_IAC_commandscCs0tjtjtjtjtjtjtjtjtjtjtjtjtjtjdtjtjtjtjdtjtjtjtjtjtjdtjtjdtjtjg}t|�}t|j�}|�|j�|�	�}|�
|d�tjtjdtjdtjd}|�
|j|�|�
d|���d|_dS)NsaasbbsccsddrIsaabb)
r�r�ZSBr�rsr�Zread_sb_datar�r�r~r3r�r�)r"�sendr*r�r�Zwant_sb_datarrr�test_SB_commandsNs"&&*�
$zOptionTests.test_SB_commandscCs�dtjtdg�dftjtjtdg�dftjtjtdg�dftjtjtdg�dftjtjtdg�dfg}|D]2\}}t|g�}|�d�|�	�}|�
||j�q|dS)	N)�az: recv b''
�Xz: IAC 88 not recognized
r�z: IAC DO 1
z
: IAC DONT 1
z
: IAC WILL 1
z
: IAC WONT 1
)r�r�rpZDOZDONTZWILLZWONTrs�set_debuglevelr~r�rU)r"Zgiven_a_expect_b�a�br*r�rrr�test_debuglevel_reads`s�


z!OptionTests.test_debuglevel_readscCs0t�}|�d�|�d�d}|�||j�dS)Nr�sxxxzsend b'xxx'
)rsr�r�r�rU)r"r*Zexpectedrrr�test_debuglevel_writess


z!OptionTests.test_debuglevel_writecCs^tg�� tdd�}d|_Wd�n1s.0Y|�d�|�d�|�|jd�dS)Nrm�0rnr��testz0.*test)rlrQrUr�rTZassertRegexr)rrr�test_debug_accepts_str_portzs

$

z'OptionTests.test_debug_accepts_str_portN)r=r>r?r�ZAOZAYTZBRKZECZELZGAZIPZNOPr�r�r�r�r�r�r�rrrrr�4s$r�c@seZdZdd�ZdS)�ExpectTestscCs@gd�}t|�}|�dg�\}}}|�|d�|dd���dS)z�
        expect(expected, [timeout])
          Read until the expected string has been seen, or a timeout is
          hit (default is no timeout); may block.
        )r�rxr�rxrINry)rsr{r3r$)r"rzr*�_rGrrr�test_expect�szExpectTests.test_expectN)r=r>r?r�rrrrr��sr��__main__) r	r[r&r�
contextlibr�rZtest.supportrZunittestr(rZTestCaser�objectr@r'rQ�BaseSelectorrW�contextmanagerrlrsrtrwr�r�r�r�r�r=�mainrrrr�<module>s2B 

bP


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists