
    daf*                     *   d Z ddlZddlZddlmZ ddlmZ ddlZddlZddl	Z	 ej                         d        Z G d dej                        Z G d d	ej                        Z G d
 de      Z G d de      Zd Zedk(  r ej&                          yy)z&Unit tests for socket timeout feature.    N)support)socket_helperc                     t        j                  |       5  t        j                  | |t        j                  t        j
                        d   d   cddd       S # 1 sw Y   yxY w)zResolve 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socketgetaddrinfoAF_INETSOCK_STREAM)hostports     ,/root/Python-3.12.4/Lib/test/test_timeout.pyresolve_addressr      sX     
	)	)$	/ <!!$fnn"("4"466799:<< < <s   :AA#c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)CreationTestCasez9Test case for socket.gettimeout() and socket.settimeout()c                 r    t        j                   t         j                  t         j                        | _        y N)r   r
   r   sockselfs    r   setUpzCreationTestCase.setUp   s    MM&..&2D2DE	    c                 8    | j                   j                          y r   r   closer   s    r   tearDownzCreationTestCase.tearDown       		r   c                 Z    | j                  | j                  j                         d d       y )Nztimeout not disabled by default)assertEqualr   
gettimeoutr   s    r   testObjectCreationz#CreationTestCase.testObjectCreation"   s$    --/:	<r   c                    | j                   j                  d       | j                  | j                   j                         d       | j                   j                  d       | j                  | j                   j                         d       | j                   j                  d        | j                  | j                   j                         d        y )NgzGa@   )r   
settimeoutr   r    r   s    r   testFloatReturnValuez%CreationTestCase.testFloatReturnValue'   s    		U#--/7		Q--/3		T"--/6r   c                 L   | j                   j                  d       | j                  t        | j                   j	                               t
               | j                   j                  d       | j                  t        | j                   j	                               t
               y )N   g333333@)r   r$   assertIstyper    floatr   s    r   testReturnTypezCreationTestCase.testReturnType2   sf    		Qd499//12E:		S!d499//12E:r   c                    | j                   j                  d       | j                   j                  d       | j                   j                  d       | j                   j                  d        | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  d       | j                  t        | j                   j                  g        | j                  t        | j                   j                  i        | j                  t        | j                   j                  d       y )Nr             y                )r   r$   assertRaises	TypeErrorr   s    r   testTypeCheckzCreationTestCase.testTypeCheck:   s    		Q		Q		S!		T")TYY%9%92>)TYY%9%92>)TYY%9%92>)TYY%9%92>)TYY%9%92>)TYY%9%92>r   c                    | j                  t        | j                  j                  d       | j                  t        | j                  j                  d       | j                  t        | j                  j                  d       y )Ng      )r0   
ValueErrorr   r$   r   s    r   testRangeCheckzCreationTestCase.testRangeCheckG   sV    *dii&:&:B?*dii&:&:B?*dii&:&:DAr   c                    | j                   j                  d       | j                   j                  d       | j                  | j                   j	                         d        | j                   j                  d       | j                  | j                   j	                         d       | j                   j                  d       | j                   j                  d       | j                  | j                   j	                         d       | j                   j                  d       | j                  | j                   j	                         d        y )N
   TFr-   )r   r$   setblockingr   r    r   s    r   testTimeoutThenBlockingz(CreationTestCase.testTimeoutThenBlockingM   s    		R 		d#--/6		e$--/5		R 		e$--/5		d#--/6r   c                    | j                   j                  d       | j                   j                  d       | j                  | j                   j	                         d       | j                   j                  d       | j                   j                  d       | j                  | j                   j	                         d       y )NFr'   T)r   r9   r$   r   r    r   s    r   testBlockingThenTimeoutz(CreationTestCase.testBlockingThenTimeout[   s    		e$		Q--/3		d#		Q--/3r   N)__name__
__module____qualname____doc__r   r   r!   r%   r+   r2   r6   r:   r<   r/   r   r   r   r      s4    CF<
	7;?B74r   r   c                   8    e Zd ZdZej
                  Zd ZeZd Z	y)TimeoutTestCaseg       @c                     t               r   )NotImplementedErrorr   s    r   r   zTimeoutTestCase.setUpq   s    !##r   c                    | j                   j                  |       t        | j                   |      }t        |      D ]  }t	        j
                         }	  ||   | j                  d       | j                  || j                  z          | j                  ||dz
         y# t        $ r"}t	        j
                         |z
  }Y d}~ [d}~ww xY w)z
        Test the specified socket method.

        The method is run at most `count` times and must raise a TimeoutError
        within `timeout` + self.fuzz seconds.
        NzTimeoutError was not raisedg      ?)r   r$   getattrrangetime	monotonicTimeoutErrorfail
assertLessfuzzassertGreater)	r   counttimeoutmethodargsit1edeltas	            r   _sock_operationzTimeoutTestCase._sock_operationv   s     			W%F+u 	5A!B	5 II34w235'C-0   (2-s   B""	C+CCN)
r=   r>   r?   rM   r   HOST	localhostr   r   rW   r/   r   r   rB   rB   f   s%     D""I$ H1r   rB   c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TCPTimeoutTestCasez3TCP test case for socket.socket() timeout functionsc                     t        j                   t         j                  t         j                        | _        t	        dd      | _        y )Nzwww.python.org.P   )r   r
   r   r   r   addr_remoter   s    r   r   zTCPTimeoutTestCase.setUp   s.    MM&..&2D2DE	*+<bAr   c                 8    | j                   j                          y r   r   r   s    r   r   zTCPTimeoutTestCase.tearDown   r   r   c           
         t        dd      }t        dd      }d}t        j                  t        j                  t        j                        }t        j
                  }|j                  |       	 |j                  |       |j                          ~|r0| j                  dj                  |d   |d   ||d   |d                || _        t!        j"                  | j                  d         5  | j%                  dd	d
| j                         d d d        y # t        $ r Y t        $ r)}|j                  t        j                  k(  rd}Y d }~d }~ww xY w# |j                          ~w xY w# 1 sw Y   y xY w)Nzpythontest.netiZ  i[  TFzWe 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).r   r'   gMbP?connect)r   r   r
   r   r   LOOPBACK_TIMEOUTr$   ra   rJ   OSErrorerrnoECONNREFUSEDr   skipTestformatr^   r   r   rW   )r   	blackhole	whiteholeskipr   rP   errs          r   testConnectTimeoutz%TCPTimeoutTestCase.testConnectTimeout   sV   
 $$4e<	 $$4e<	0 }}V^^V-?-?@** 		LL)% JJLMM8 V!!!!!!!! %--d.>.>q.AB 	H  E9d6F6FG	H 	H5  	 	yyE...	 JJL&	H 	HsB   /D ,E)	EE E'EE EE E&)E2c                     t        j                  | j                  d         5  | j                  j	                  | j                         | j                  dddd       d d d        y # 1 sw Y   y xY w)Nr   r'         ?recv   )r   r   r^   r   ra   rW   r   s    r   testRecvTimeoutz"TCPTimeoutTestCase.testRecvTimeout   s\    --d.>.>q.AB 	7IId../  C6	7 	7 	7s   :A&&A/c                     t        j                  | j                  | j                         | j                  j	                          | j                  ddd       y )Nr'   rn   accept)r   	bind_portr   rY   listenrW   r   s    r   testAcceptTimeoutz$TCPTimeoutTestCase.testAcceptTimeout   s<    		4>>:		QX.r   c                 r   t        j                   t         j                  t         j                        5 }t        j                  || j
                         |j                          | j                  j                  |j                                | j                  dddddz         d d d        y # 1 sw Y   y xY w)Nd   rn   send   X@ r   r
   r   r   rt   rY   ru   r   ra   getsocknamerW   r   servs     r   testSendzTCPTimeoutTestCase.testSend   s    ]]6>>6+=+=> 	B$##D$..9KKMIId..01  c64&=A	B 	B 	B   A1B--B6c           	         t        j                   t         j                  t         j                        5 }t        j                  || j
                         |j                          | j                  j                  |j                                | j                  dddddz  |j                                d d d        y # 1 sw Y   y xY w)Nrx   rn   sendtorz   r{   r|   r~   s     r   
testSendtozTCPTimeoutTestCase.testSendto   s    ]]6>>6+=+=> 	5$##D$..9KKMIId..01  c8TF]!%!1!1!35	5 	5 	5s   B B<<Cc                 r   t        j                   t         j                  t         j                        5 }t        j                  || j
                         |j                          | j                  j                  |j                                | j                  dddddz         d d d        y # 1 sw Y   y xY w)Nrx   rn   sendallrz   r{   r|   r~   s     r   testSendallzTCPTimeoutTestCase.testSendall  s    ]]6>>6+=+=> 	E$##D$..9KKMIId..01  c9dVmD	E 	E 	Er   N)r=   r>   r?   r@   r   r   rl   rq   rv   r   r   r   r/   r   r   r[   r[      s3    =BJHX7/B5Er   r[   c                   "    e Zd ZdZd Zd Zd Zy)UDPTimeoutTestCasez3UDP test case for socket.socket() timeout functionsc                 r    t        j                   t         j                  t         j                        | _        y r   )r   r
   
SOCK_DGRAMr   r   s    r   r   zUDPTimeoutTestCase.setUp  s    MM&..&2C2CD	r   c                 8    | j                   j                          y r   r   r   s    r   r   zUDPTimeoutTestCase.tearDown  r   r   c                     t        j                  | j                  | j                         | j	                  dddd       y )Nr'   rn   recvfromrp   )r   rt   r   rY   rW   r   s    r   testRecvfromTimeoutz&UDPTimeoutTestCase.testRecvfromTimeout  s0     			4>>:QZ6r   N)r=   r>   r?   r@   r   r   r   r/   r   r   r   r     s    =E7r   r   c                  Z    t        j                  d       t        j                  d       y )NnetworkT)module)r   requiresrequires_working_socketr/   r   r   setUpModuler     s    Y##40r   __main__)r@   	functoolsunittesttestr   test.supportr   rH   rd   r   	lru_cacher   TestCaser   rB   r[   r   r   r=   mainr/   r   r   <module>r      s    ,    &    < <J4x(( J4Z$1h'' $1N|E |E~7 7 1
 zHMMO r   