ó
¬«Y]c           @   s™  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 y d  d l	 Z	 Wn e
 k
 r d Z	 n Xe j Z d Z e	 rá d e	 j f d „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z n  e j e	 d	 ƒ d
 e j f d „  ƒ  Yƒ Z d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d d „ Z e d k r•e d e ƒ n  d S(   iÿÿÿÿN(   t   test_supports   QUIT
t   echo_serverc           B   s    e  Z d  Z d „  Z d „  Z RS(   i   c         C   sV   t  j j |  ƒ | |  _ t j t j t j ƒ |  _ t j	 |  j ƒ |  _
 d  |  _ d  S(   N(   t	   threadingt   Threadt   __init__t   eventt   sockett   AF_INETt   SOCK_STREAMt   sockR    t	   bind_portt   portt   Nonet   start_resend_event(   t   selfR   (    (    s#   lib/python2.7/test/test_asynchat.pyR      s
    	c         C   s  |  j  j d ƒ |  j j ƒ  |  j  j ƒ  \ } } d |  _ x< t |  j k ry | j d ƒ } | sf Pn  |  j | |  _ q> W|  j j t d ƒ |  _ |  j	 r« |  j	 j
 ƒ  n  yJ xC |  j ró | j |  j |  j  ƒ } t j d ƒ |  j | |  _ q± WWn n X| j ƒ  |  j  j ƒ  d  S(   Ni   t    gü©ñÒMbP?(   R	   t   listenR   t   sett   acceptt   buffert   SERVER_QUITt   recvt   replaceR   t   waitt   sendt
   chunk_sizet   timet   sleept   close(   R   t   connt   clientt   datat   n(    (    s#   lib/python2.7/test/test_asynchat.pyt   run"   s*    		
(   t   __name__t
   __module__R   R   R!   (    (    (    s#   lib/python2.7/test/test_asynchat.pyR      s   		t   echo_clientc           B   sG   e  Z d  „  Z d „  Z e j d k r3 d „  Z n  d „  Z d „  Z RS(   c         C   s\   t  j j |  ƒ g  |  _ |  j t j t j ƒ |  j t	 | f ƒ |  j
 | ƒ d |  _ d  S(   NR   (   t   asynchatt
   async_chatR   t   contentst   create_socketR   R   R   t   connectt   HOSTt   set_terminatorR   (   R   t
   terminatort   server_port(    (    s#   lib/python2.7/test/test_asynchat.pyR   D   s    	c         C   s   d  S(   N(    (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   handle_connectL   s    t   darwinc         C   s   d  S(   N(    (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   handle_exptR   s    c         C   s   |  j  | 7_  d  S(   N(   R   (   R   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   collect_incoming_dataU   s    c         C   s    |  j  j |  j ƒ d |  _ d  S(   NR   (   R'   t   appendR   (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   found_terminatorX   s    (	   R"   R#   R   R.   t   syst   platformR0   R1   R3   (    (    (    s#   lib/python2.7/test/test_asynchat.pyR$   B   s   			c          C   sM   t  j ƒ  }  t |  ƒ } | j ƒ  |  j ƒ  |  j ƒ  t j d ƒ | |  f S(   Ng{®Gáz„?(   R   t   EventR   t   startR   t   clearR   R   (   R   t   s(    (    s#   lib/python2.7/test/test_asynchat.pyt   start_echo_server]   s    


s!   Threading required for this test.t   TestAsynchatc           B   sŒ   e  Z e Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   c         C   s   t  j ƒ  |  _ d  S(   N(   R    t   threading_setupt   _threads(   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   setUpk   s    c         C   s   t  j |  j Œ  d  S(   N(   R    t   threading_cleanupR=   (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   tearDownn   s    c         C   sà   t  j ƒ  } t | ƒ } | | _ | j ƒ  | j ƒ  | j ƒ  t j d ƒ t	 | | j
 ƒ } | j d ƒ | j d | ƒ | j d | ƒ | j t ƒ t j d |  j d d d d ƒ | j ƒ  |  j | j d	 d
 g ƒ d  S(   Ng{®Gáz„?s   hello s   world%ss   I'm not dead yet!%st   use_pollt   counti,  t   timeouts   hello worlds   I'm not dead yet!(   R   R6   R   R   R7   R   R8   R   R   R$   R   t   pushR   t   asyncoret   loopt   usepollt   joint   assertEqualR'   (   R   t   termt   server_chunkR   R9   t   c(    (    s#   lib/python2.7/test/test_asynchat.pyt   line_terminator_checkq   s    	



c         C   s%   x d D] } |  j  d | ƒ q Wd  S(   Ni   i   i   s   
(   i   i   i   (   RM   (   R   t   l(    (    s#   lib/python2.7/test/test_asynchat.pyt   test_line_terminator1‡   s    c         C   s%   x d D] } |  j  d | ƒ q Wd  S(   Ni   i   i   s   
(   i   i   i   (   RM   (   R   RN   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_line_terminator2Œ   s    c         C   s%   x d D] } |  j  d | ƒ q Wd  S(   Ni   i   i   t   qqq(   i   i   i   (   RM   (   R   RN   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_line_terminator3‘   s    c         C   sˆ   t  ƒ  \ } } t | | j ƒ } d } | j | ƒ | j t ƒ t j d |  j d d d d ƒ | j ƒ  |  j	 | j
 | |  g ƒ d  S(   Ns   hello world, I'm not dead yet!
RA   RB   i,  RC   g{®Gáz„?(   R:   R$   R   RD   R   RE   RF   RG   RH   RI   R'   (   R   t   termlenR9   R   RL   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   numeric_terminator_check–   s    
c         C   s   |  j  d ƒ |  j  d ƒ d  S(   Ni   l    (   RT   (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_numeric_terminator1¢   s    c         C   s   |  j  d ƒ d  S(   Nl    (   RT   (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_numeric_terminator2¨   s    c         C   s”   t  ƒ  \ } } t d  | j ƒ } d } | j | ƒ | j t ƒ t j d |  j d d d d ƒ | j	 ƒ  |  j
 | j g  ƒ |  j
 | j | ƒ d  S(   Ns   hello world, I'm not dead yet!
RA   RB   i,  RC   g{®Gáz„?(   R:   R$   R   R   RD   R   RE   RF   RG   RH   RI   R'   R   (   R   R9   R   RL   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_none_terminator«   s    
c         C   s“   t  ƒ  \ } } t d | j ƒ } d } t j | t d d ƒ} | j | ƒ t j d |  j	 d d d d	 ƒ | j
 ƒ  |  j | j d
 d g ƒ d  S(   Ns   
s   hello world
I'm not dead yet!
t   buffer_sizei   RA   RB   i,  RC   g{®Gáz„?s   hello worlds   I'm not dead yet!(   R:   R$   R   R%   t   simple_producerR   t   push_with_producerRE   RF   RG   RH   RI   R'   (   R   R9   R   RL   R   t   p(    (    s#   lib/python2.7/test/test_asynchat.pyt   test_simple_producer¸   s    
c         C   s~   t  ƒ  \ } } t d | j ƒ } d } | j | t ƒ t j d |  j d d d d ƒ | j ƒ  |  j	 | j
 d d	 g ƒ d  S(
   Ns   
s   hello world
I'm not dead yet!
RA   RB   i,  RC   g{®Gáz„?s   hello worlds   I'm not dead yet!(   R:   R$   R   RZ   R   RE   RF   RG   RH   RI   R'   (   R   R9   R   RL   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_string_producerÃ   s    
c         C   s„   t  ƒ  \ } } t d | j ƒ } | j d ƒ | j t ƒ t j d |  j d d d d ƒ | j ƒ  |  j	 | j
 d d	 d
 g ƒ d  S(   Ns   
s   hello world

I'm not dead yet!
RA   RB   i,  RC   g{®Gáz„?s   hello worldR   s   I'm not dead yet!(   R:   R$   R   RD   R   RE   RF   RG   RH   RI   R'   (   R   R9   R   RL   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_empty_lineÍ   s    
c         C   s½   t  ƒ  \ } } t j ƒ  | _ t d | j ƒ } | j d ƒ | j t ƒ | j ƒ  t	 j
 d |  j d d d d ƒ | j j ƒ  | j ƒ  |  j | j g  ƒ |  j t | j ƒ d k ƒ d  S(	   Ns   
s   hello world
I'm not dead yet!
RA   RB   i,  RC   g{®Gáz„?i    (   R:   R   R6   R   R$   R   RD   R   t   close_when_doneRE   RF   RG   R   RH   RI   R'   t
   assertTruet   lenR   (   R   R9   R   RL   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_close_when_doneØ   s    

(   R"   R#   t   FalseRG   R>   R@   RM   RO   RP   RR   RT   RU   RV   RW   R\   R]   R^   Rb   (    (    (    s#   lib/python2.7/test/test_asynchat.pyR;   g   s   												
	t   TestAsynchat_WithPollc           B   s   e  Z e Z RS(    (   R"   R#   t   TrueRG   (    (    (    s#   lib/python2.7/test/test_asynchat.pyRd   ï   s   t   TestAsynchatMockedc           B   s   e  Z d  „  Z RS(   c         C   si   d d d „  ƒ  Y} d t  j f d „  ƒ  Y} | ƒ  } | ƒ  } | j | ƒ |  j | j ƒ | j ƒ  d  S(   Nt   fake_socketc           B   s   e  Z d  „  Z d „  Z RS(   c         S   s   d S(   Ni    (    (   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   filenoø   s    c         S   s   t  j t j d ƒ ‚ d  S(   Nt   EAGAIN(   R   t   errort   errnoRi   (   R   t   size(    (    s#   lib/python2.7/test/test_asynchat.pyR   û   s    (   R"   R#   Rh   R   (    (    (    s#   lib/python2.7/test/test_asynchat.pyRg   ÷   s   	t   MyChatc           B   s   e  Z d  „  Z RS(   c         S   s   t  d ƒ ‚ d  S(   NRj   (   t	   Exception(   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   handle_errorÿ   s    (   R"   R#   Ro   (    (    (    s#   lib/python2.7/test/test_asynchat.pyRm   þ   s   (    (   R%   R&   t
   set_sockett
   addCleanupt   del_channelt   handle_read(   R   Rg   Rm   R	   t
   dispatcher(    (    s#   lib/python2.7/test/test_asynchat.pyt   test_blockingioerrorô   s    		(   R"   R#   Ru   (    (    (    s#   lib/python2.7/test/test_asynchat.pyRf   ó   s   t   TestHelperFunctionsc           B   s   e  Z d  „  Z RS(   c         C   s<   |  j  t j d d ƒ d ƒ |  j  t j d d ƒ d ƒ d  S(   Ns   qwertys   
i   t
   qwertydkjfi    (   RI   R%   t   find_prefix_at_end(   R   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_find_prefix_at_end  s    (   R"   R#   Ry   (    (    (    s#   lib/python2.7/test/test_asynchat.pyRv     s   t   TestFifoc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s  t  j ƒ  } | j d ƒ | j d ƒ |  j t | ƒ d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j t | ƒ d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  t ƒ |  j | j ƒ  d ƒ |  j t | ƒ d ƒ |  j | j ƒ  t	 ƒ |  j | j ƒ  d ƒ d  S(	   Ni   t   ai   i   i    (   i   i   (   i   R{   (   i    N(   R%   t   fifoRD   RI   Ra   t   firstt   popt   is_emptyRc   Re   R   (   R   t   f(    (    s#   lib/python2.7/test/test_asynchat.pyt
   test_basic  s    c         C   sŠ   t  j d d d g ƒ } |  j t | ƒ d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d ƒ |  j | j ƒ  d	 ƒ d  S(
   Nt   xi   i   i   i    (   i   R‚   (   i   i   (   i   i   (   i    N(   R%   R|   RI   Ra   R~   R   (   R   R€   (    (    s#   lib/python2.7/test/test_asynchat.pyt   test_given_list   s    (   R"   R#   R   Rƒ   (    (    (    s#   lib/python2.7/test/test_asynchat.pyRz     s   	c         C   s   t  j t t t t t ƒ d  S(   N(   R    t   run_unittestR;   Rd   Rf   Rv   Rz   (   t   verbose(    (    s#   lib/python2.7/test/test_asynchat.pyt	   test_main)  s    t   __main__R…   (   Rk   RE   R%   R   R   t   unittestR4   t   testR    R   t   ImportErrorR   R*   R   R   R   R&   R$   R:   t
   skipUnlesst   TestCaseR;   Rd   Rf   Rv   Rz   R†   R"   Re   (    (    (    s#   lib/python2.7/test/test_asynchat.pyt   <module>   s4   
	.
‡