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_timeout.cpython-37.pyc
B

��g�,�@s�dZddlZddlZddlmZe�d�ZddlZddlZddl	Z	e�
�dd��ZGdd�dej�Z
Gd	d
�d
ej�ZGdd�de�ZGd
d�de�Zdd�Zedkr�e�dS)z&Unit tests for socket timeout feature.�N)�support�networkc	Cs2t�|��t�||tjtj�ddSQRXdS)z�Resolve an (host, port) to an address.

    We must perform name resolution before timeout tests, otherwise it will be
    performed by connect().
    r�N)r�transient_internet�socketZgetaddrinfo�AF_INET�SOCK_STREAM)ZhostZport�r	�-/usr/local/lib/python3.7/test/test_timeout.py�resolve_addresssrc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�CreationTestCasez9Test case for socket.gettimeout() and socket.settimeout()cCst�tjtj�|_dS)N)rrr�sock)�selfr	r	r
�setUpszCreationTestCase.setUpcCs|j��dS)N)r
�close)rr	r	r
�tearDown!szCreationTestCase.tearDowncCs|�|j��dd�dS)Nztimeout not disabled by default)�assertEqualr
�
gettimeout)rr	r	r
�testObjectCreation$sz#CreationTestCase.testObjectCreationcCs^|j�d�|�|j��d�|j�d�|�|j��d�|j�d�|�|j��d�dS)Ng�z�Ga@�)r
�
settimeoutrr)rr	r	r
�testFloatReturnValue)sz%CreationTestCase.testFloatReturnValuecCsP|j�d�|�t|j���td��|j�d�|�t|j���td��dS)N�g�?g333333@)r
rr�typer)rr	r	r
�testReturnType4szCreationTestCase.testReturnTypecCs�|j�d�|j�d�|j�d�|j�d�|�t|jjd�|�t|jjd�|�t|jjd�|�t|jjg�|�t|jji�|�t|jjd�dS)Nrg�r	y)r
r�assertRaises�	TypeError)rr	r	r
�
testTypeCheck<szCreationTestCase.testTypeCheckcCs:|�t|jjd�|�t|jjd�|�t|jjd�dS)N���g�)r�
ValueErrorr
r)rr	r	r
�testRangeCheckIszCreationTestCase.testRangeCheckcCs�|j�d�|j�d�|�|j��d�|j�d�|�|j��d�|j�d�|j�d�|�|j��d�|j�d�|�|j��d�dS)N�
rrg)r
r�setblockingrr)rr	r	r
�testTimeoutThenBlockingOsz(CreationTestCase.testTimeoutThenBlockingcCsX|j�d�|j�d�|�|j��d�|j�d�|j�d�|�|j��d�dS)Nrr)r
r#rrr)rr	r	r
�testBlockingThenTimeout]sz(CreationTestCase.testBlockingThenTimeoutN)
�__name__�
__module__�__qualname__�__doc__rrrrrrr!r$r%r	r	r	r
rs
rc@s*eZdZdZejZdd�ZeZdd�Z	dS)�TimeoutTestCaseg@cCs
t��dS)N)�NotImplementedError)rr	r	r
rsszTimeoutTestCase.setUpc	Gs�|j�|�t|j|�}xbt|�D]L}t��}y||�Wq"tjk
rl}zt��|}PWdd}~XYq"Xq"W|�d�|�	|||j
�|�||d�dS)z�
        Test the specified socket method.

        The method is run at most `count` times and must raise a socket.timeout
        within `timeout` + self.fuzz seconds.
        Nzsocket.timeout was not raisedg�?)r
r�getattr�range�timeZ	monotonicr�timeoutZfailZ
assertLess�fuzzZ
assertGreater)	r�countr/�method�args�iZt1�eZdeltar	r	r
�_sock_operationxs
zTimeoutTestCase._sock_operationN)
r&r'r(r0rZHOST�	localhostrrr6r	r	r	r
r*hs
r*c@s\eZdZdZdd�Zdd�Ze�dd�dd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dS)�TCPTimeoutTestCasez3TCP test case for socket.socket() timeout functionscCs"t�tjtj�|_tdd�|_dS)Nzwww.python.org.�P)rrrr
r�addr_remote)rr	r	r
r�szTCPTimeoutTestCase.setUpcCs|j��dS)N)r
r)rr	r	r
r�szTCPTimeoutTestCase.tearDownTz*need to replace these hosts; see bpo-35518c
Cstdd�}tdd�}d}t�tjtj�}d}|�|�zZy|�|�WnFtjk
r\Yn2tk
r�}z|jtj	kr|d}Wdd}~XYnXWd|�
�~X|r�|�d�|d	|d
||d	|d
��||_
t�|j
d	��|�d
dd|j
�WdQRXdS)
Nzblackhole.snakebite.netiZ�zwhitehole.snakebite.neti[�TrFz�We didn't receive a connection reset (RST) packet from {}:{} within {} seconds, so we're unable to test connect timeout against the corresponding {}:{} (which is configured to silently drop packets).rrg����MbP?�connect)rrrrrr;r/�OSError�errnoZECONNREFUSEDrZskipTest�formatr:rrr6)rZ	blackholeZ	whitehole�skipr
r/�errr	r	r
�testConnectTimeout�s4


z%TCPTimeoutTestCase.testConnectTimeoutc	Cs>t�|jd��$|j�|j�|�dddd�WdQRXdS)Nrrg�?Zrecvi)rrr:r
r;r6)rr	r	r
�testRecvTimeout�sz"TCPTimeoutTestCase.testRecvTimeoutcCs,t�|j|j�|j��|�ddd�dS)Nrg�?Zaccept)r�	bind_portr
r7�listenr6)rr	r	r
�testAcceptTimeout�s
z$TCPTimeoutTestCase.testAcceptTimeoutc	CsZt�tjtj��@}t�||j�|��|j�|�	��|�
ddddd�WdQRXdS)N�dg�?�send�Xi@
)rrrrrCr7rDr
r;�getsocknamer6)r�servr	r	r
�testSend�s
zTCPTimeoutTestCase.testSendc	Cs`t�tjtj��F}t�||j�|��|j�|�	��|�
ddddd|�	��WdQRXdS)NrFg�?ZsendtorHi@
)rrrrrCr7rDr
r;rIr6)rrJr	r	r
�
testSendtoszTCPTimeoutTestCase.testSendtoc	CsZt�tjtj��@}t�||j�|��|j�|�	��|�
ddddd�WdQRXdS)NrFg�?ZsendallrHi@
)rrrrrCr7rDr
r;rIr6)rrJr	r	r
�testSendall
s
zTCPTimeoutTestCase.testSendallN)r&r'r(r)rr�unittestZskipIfrArBrErKrLrMr	r	r	r
r8�sU	
r8c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�UDPTimeoutTestCasez3UDP test case for socket.socket() timeout functionscCst�tjtj�|_dS)N)rrZ
SOCK_DGRAMr
)rr	r	r
rszUDPTimeoutTestCase.setUpcCs|j��dS)N)r
r)rr	r	r
rszUDPTimeoutTestCase.tearDowncCs$t�|j|j�|�dddd�dS)Nrg�?Zrecvfromi)rrCr
r7r6)rr	r	r
�testRecvfromTimeout sz&UDPTimeoutTestCase.testRecvfromTimeoutN)r&r'r(r)rrrPr	r	r	r
rOsrOcCst�d�t�ttt�dS)Nr)rZrequiresZrun_unittestrr8rOr	r	r	r
�	test_main's

rQ�__main__)r)�	functoolsrNZtestrZis_resource_enabledZ
skip_expectedr.r=r�	lru_cacherZTestCaserr*r8rOrQr&r	r	r	r
�<module>s M'