ó
ŒwÛjc           @   s6  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l m Z m Z m Z y d d l Z Wn e k
 rÛ e Z n Xe j j d ƒ d Z e j j Z e e d ƒ Z e	 j e d ƒ Z e e d ƒ o:e j d	 k Z e	 j e d
 ƒ Z d „  Z e j Z d d „ Z  e r´d e
 j! e
 j" f d „  ƒ  YZ# d e
 j! e
 j$ f d „  ƒ  YZ% n  e j& d „  ƒ Z' d „  Z( e	 j e d ƒ d e	 j) f d „  ƒ  Yƒ Z* d e	 j) f d „  ƒ  YZ+ d „  Z, e- d k r2e, ƒ  n  d S(   s!   
Test suite for SocketServer.py.
iÿÿÿÿN(   t   reap_childrent   reap_threadst   verboset   networks   hello world
t   AF_UNIXs   requires Unix socketst   forkt   os2s   requires forkingc         C   s#   t  t d ƒ r t j |  ƒ n  d S(   s7   Call signal.alarm when it exists (i.e. not on Windows).t   alarmN(   t   hasattrt   signalR   (   t   n(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   signal_alarm#   s    i   c         C   sN   t  |  g g  g  | ƒ \ } } } |  | k r: |  j | ƒ St d |  f ‚ d  S(   Ns   timed out on %r(   t   _real_selectt   recvt   RuntimeError(   t   sockR
   t   timeoutt   rt   wt   x(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   receive+   s    !t   ForkingUnixStreamServerc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyR   3   s   t   ForkingUnixDatagramServerc           B   s   e  Z RS(    (   R   R   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyR   7   s   c         c   si   t  j ƒ  } | d k r( t  j d ƒ n  d  Vt  j | d ƒ \ } } |  j | | ƒ |  j d | ƒ d  S(   Ni    iH   i   i H  (   t   osR   t   _exitt   Nonet   waitpidt   assertEqual(   t   testcaset   pidt   pid2t   status(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   simple_subprocess<   s    c         C   so   |  j  ƒ  t |  d ƒ rk x? |  j j ƒ  D]. } y t j | d ƒ Wq) t k
 rV q) Xq) W|  j j ƒ  n  d  S(   Nt   active_childreni    (   t   server_closeR   R#   t   copyR   R   t   ChildProcessErrort   clear(   t   serverR   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   close_serverH   s    
s!   Threading required for this test.t   SocketServerTestc           B   s.  e  Z d  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d	 „  Z e d
 „  ƒ Z e d „  ƒ Z e d „  ƒ Z e e d „  ƒ ƒ Z d „  Z d „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z e d „  ƒ Z e d „  ƒ Z e e d „  ƒ ƒ Z e d „  ƒ Z d „  Z RS(   s   Test all socket servers.c         C   s0   |  j  t d ƒ t d ƒ d |  _ g  |  _ d  S(   Ni    i<   (   t
   addCleanupR   t	   port_seedt
   test_files(   t   self(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   setUpZ   s    
	c         C   s[   |  j  ƒ  t ƒ  x9 |  j D]. } y t j | ƒ Wq t j k
 rH q Xq Wg  |  j (d  S(   N(   t
   doCleanupsR    R-   R   t   removet   error(   R.   t   fn(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   tearDown`   s    
c         C   s  | t  j k r t d f Sd  } t j d k r7 d } n  t j d d d | ƒ } t j d k ré | d d k r{ | d	 } n  | d t j t j	 f k r¤ | d } n  t j d
 k rÎ | j
 t j t j	 ƒ } qé | j
 t j	 t j ƒ } n  |  j j | ƒ | Sd  S(   Ni    R   s   \sockett   prefixs   unix_socket.t   diri   t   :i   t   /(   t   sockett   AF_INETt   HOSTR   R   t   namet   tempfilet   mktempt   sept   altsept   replaceR-   t   append(   R.   t   protoR6   R3   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   pickaddrk   s     
	c         C   si   d | f d „  ƒ  Y} d | f d „  ƒ  Y} t  r: d GHn  | | | ƒ } |  j | j | j j ƒ  ƒ | S(   Nt   MyServerc           B   s   e  Z d  „  Z RS(   c         S   s   |  j  | ƒ t |  ƒ ‚  d  S(   N(   t   close_requestR)   (   R.   t   requestt   client_address(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   handle_error†   s    
(   R   R   RI   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyRE   …   s   t	   MyHandlerc           B   s   e  Z d  „  Z RS(   c         S   s#   |  j  j ƒ  } |  j j | ƒ d  S(   N(   t   rfilet   readlinet   wfilet   write(   R.   t   line(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   handleŒ   s    (   R   R   RP   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyRJ   ‹   s   s   creating server(   R   R   t   server_addressR9   t   getsockname(   R.   t   addrt   svrclst   hdlrbaseRE   RJ   R(   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   make_server„   s     c      	   C   s'  |  j  |  j | j ƒ | | ƒ } | j } t rJ d GHd G| GHd G| GHn  t j d d | d | j d i d d	 6ƒ } t | _	 | j
 ƒ  t r— d
 GHn  x6 t d ƒ D]( } t r¼ d G| GHn  | | j | ƒ q¤ Wt rÞ d GHn  | j ƒ  | j ƒ  t | ƒ |  j t j | j j ƒ t r#d GHn  d  S(   Ns   server createds   ADDR =s   CLASS =R<   s
   %s servingt   targett   kwargsg{®Gáz„?t   poll_intervals   server runningi   s   test clients   waiting for servert   done(   RV   RD   t   address_familyRQ   R   t	   threadingt   Threadt   serve_forevert   Truet   daemont   startt   ranget   shutdownt   joinR)   t   assertRaisesR9   R2   t   fileno(   R.   RT   RU   t   testfuncR(   RS   t   tt   i(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt
   run_server•   s6    			
		
   


 c         C   s’   t  j  | t  j ƒ } | j | ƒ | j t ƒ t | d ƒ } } x/ | rs d | k rs t | d ƒ } | | 7} qE W|  j | t ƒ | j ƒ  d  S(   Nid   s   
(   R9   t   SOCK_STREAMt   connectt   sendallt   TEST_STRR   R   t   close(   R.   RC   RS   t   st   buft   data(    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   stream_examine´   s    c         C   s¶   t  j  | t  j ƒ } t rC | t  j k rC | j |  j | ƒ ƒ n  | j t | ƒ t | d ƒ } } x/ | r— d | k r— t | d ƒ } | | 7} qi W|  j	 | t ƒ | j
 ƒ  d  S(   Nid   s   
(   R9   t
   SOCK_DGRAMt   HAVE_UNIX_SOCKETSR   t   bindRD   t   sendtoRn   R   R   Ro   (   R.   RC   RS   Rp   Rq   Rr   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   dgram_examine¿   s    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   t   SocketServert	   TCPServert   StreamRequestHandlerRs   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_TCPServerË   s    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t   ThreadingTCPServerR{   Rs   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ThreadingTCPServerÐ   s    c         C   s3   t  |  ƒ �! |  j t j t j |  j ƒ Wd  QXd  S(   N(   R"   Rj   Ry   t   ForkingTCPServerR{   Rs   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ForkingTCPServerÕ   s    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t   UnixStreamServerR{   Rs   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_UnixStreamServerÜ   s    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t   ThreadingUnixStreamServerR{   Rs   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ThreadingUnixStreamServerâ   s    c         C   s0   t  |  ƒ � |  j t t j |  j ƒ Wd  QXd  S(   N(   R"   Rj   R   Ry   R{   Rs   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ForkingUnixStreamServerè   s    	c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t	   UDPServert   DatagramRequestHandlerRx   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_UDPServerð   s    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t   ThreadingUDPServerR‡   Rx   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ThreadingUDPServerõ   s    c         C   s3   t  |  ƒ �! |  j t j t j |  j ƒ Wd  QXd  S(   N(   R"   Rj   Ry   t   ForkingUDPServerR‡   Rx   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ForkingUDPServerú   s    c         #   sK   t  j  ‰  d d ‡  f d †  ƒ  Y} | ƒ  t  _  z t  j  VWd ˆ  t  _  Xd S(   s<   Mocks the select.select() call to raise EINTR for first callt
   MockSelectc              s    e  Z d  „  Z ‡  f d †  Z RS(   c         S   s   d |  _  d  S(   Ni    (   t   called(   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   __init__  s    c            sP   |  j  d 7_  |  j  d k rB t j t j t j t j ƒ ƒ ‚ n
 ˆ  | Œ  Sd  S(   Ni   (   RŽ   t   selectR2   t   errnot   EINTRR   t   strerror(   R.   t   args(   t
   old_select(    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   __call__
  s    $(   R   R   R�   R–   (    (   R•   (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyR�     s   	N(    (   R�   (   R.   R�   (    (   R•   sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   mocked_select_module  s    	c         C   sJ   |  j  ƒ  �8 } |  j t j t j |  j ƒ } |  j | j d ƒ Wd  QXd  S(   Ni   (   R—   Rj   Ry   Rz   R{   Rs   t   assertGreaterRŽ   (   R.   t   mock_selectR   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_InterruptServerSelectCall  s
    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t   UnixDatagramServerR‡   Rx   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_UnixDatagramServer!  s    c         C   s    |  j  t j t j |  j ƒ d  S(   N(   Rj   Ry   t   ThreadingUnixDatagramServerR‡   Rx   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt    test_ThreadingUnixDatagramServer'  s    c         C   s   |  j  t t j |  j ƒ d  S(   N(   Rj   R   Ry   R‡   Rx   (   R.   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_ForkingUnixDatagramServer-  s    	c      
   C   s  d t  j f d „  ƒ  Y} d t  j f d „  ƒ  Y} g  } xm t d ƒ D]_ } | t d f | ƒ } t j d d d	 | j d
 i d d 6ƒ } t | _	 | j
 | | f ƒ qE Wx( | D]  \ } } | j ƒ  | j ƒ  q¯ Wx( | D]  \ } } | j ƒ  t | ƒ qÚ Wd  S(   NRE   c           B   s   e  Z RS(    (   R   R   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyRE   8  s   RJ   c           B   s   e  Z RS(    (   R   R   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyRJ   ;  s   i   i    R<   s   MyServer servingRW   RX   g{®Gáz„?RY   (   Ry   Rz   R{   Rb   R;   R\   R]   R^   R_   R`   RB   Ra   Rc   Rd   R)   (   R.   RE   RJ   t   threadsRi   Rp   Rh   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_shutdown4  s"    			

c         C   sJ   xC t  d ƒ D]5 } |  j t ƒ � t j t d f t j ƒ Wd  QXq Wd  S(   Ni   iÿÿÿÿ(   Rb   Re   t   OverflowErrorRy   Rz   R;   R{   (   R.   Ri   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   test_tcpserver_bind_leakN  s    (   R   R   t   __doc__R/   R4   RD   RV   R   Rj   Rs   Rx   R|   R~   t   requires_forkingR€   t   requires_unix_socketsR‚   R„   R…   Rˆ   RŠ   RŒ   t
   contextlibt   contextmanagerR—   Rš   Rœ   Rž   RŸ   R¡   R£   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyR*   V   s4   											t   MiscTestCasec           B   s   e  Z d  „  Z RS(   c         C   sŽ   d t  j f d „  ƒ  Y} | t d f t  j ƒ } t j | j t j ƒ } | j | j ƒ | j	 ƒ  | j
 ƒ  |  j | j d ƒ t | ƒ d  S(   NRE   c           B   s    e  Z d  „  Z d Z d „  Z RS(   c         S   s   t  S(   N(   t   False(   R.   RG   RH   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   verify_request`  s    i    c         S   s&   |  j  d 7_  t j j |  | ƒ d  S(   Ni   (   t   shutdown_calledRy   Rz   t   shutdown_request(   R.   RG   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyR­   d  s    (   R   R   R«   R¬   R­   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyRE   _  s   	i    i   (   Ry   Rz   R;   R{   R9   R[   Rk   Rl   RQ   Ro   t   handle_requestR   R¬   R)   (   R.   RE   R(   Rp   (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt4   test_shutdown_request_called_if_verify_request_false[  s    	

(   R   R   R¯   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyR©   Y  s   c           C   s2   t  j ƒ  r t j d ƒ ‚ n  t j j t ƒ d  S(   Ns"   can't run when import lock is held(   t   impt	   lock_heldt   unittestt   SkipTestt   testt   test_supportt   run_unittestR*   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt	   test_mainq  s    t   __main__(.   R¤   R§   R°   R   R�   R	   R9   R‘   R=   R²   Ry   t   test.test_supportR´   R    R   R   R\   t   ImportErrorR   Rµ   t   requiresRn   R;   R   Ru   t
   skipUnlessR¦   R<   t   HAVE_FORKINGR¥   R   R   R   t   ForkingMixInR�   R   R›   R   R¨   R"   R)   t   TestCaseR*   R©   R·   R   (    (    (    sŒ   /home/sim/yocto/scarthgap/build/tmp/work/x86_64-linux/python-native/2.7.18/recipe-sysroot-native/usr/lib/python2.7/test/test_socketserver.pyt   <module>   sT   
							ÿ 	