Ñò
ÉbMQc           @   sŽ  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z d  d k l	 Z	 d  d k
 l Z d  d k
 l Z d  d k
 l Z d  d k
 l Z d  d k
 l Z d  d	 k l Z d  d
 k l Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z e i e ƒ Z d „  Z d „  Z h d „  d 6d „  d 6d „  d 6d „  d 6Z  d „  Z! e ƒ  Z" d „  Z# d „  Z$ d „  Z% h	 d „  d 6d „  d  6d! „  d" 6d# „  d 6d$ „  d% 6e% d& 6d' „  d( 6e$ d) 6d* „  d 6Z& d+ d, „ Z' d- Z( e( d. d/ d0 7Z( e d1 „  ƒ Z) d2 e f d3 „  ƒ  YZ* d4 „  e _+ d5 e f d6 „  ƒ  YZ, d7 „  Z- e d8 j o e! ƒ  n d S(9   iÿÿÿÿN(   t   Request(   t   Response(   t   url_open(   t   bytes_(   t   reraise(   t   Queue(   t   Empty(   t   contextmanager(   t   assert_raises(   t   eq_(   t   make_server(   t   WSGIRequestHandler(   t
   WSGIServer(   t   ServerHandlerc       	   C   sq   t  t ƒ i i ƒ  }  zQ |  ~  } xA t D]9 } t | i | d d ƒ} | i ƒ  d j p t ‚ q* WWd QXd S(   s‡   
        Test actual request/response cycle in the presence of Request.copy()
        and other methods that can potentially hang.
    t   timeouti   t   okN(	   t   servet   _test_app_req_readingt   __exit__t	   __enter__t   _test_ops_req_readR   t   urlt   readt   AssertionError(   t   _[1]t   servert   keyt   resp(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   test_request_reading   s
    # c         C   s\   t  |  ƒ } t i d | i ƒ t | i } | | ƒ t i d ƒ t d ƒ } | |  | ƒ S(   Ns   starting test operation: %st   doneR   (   R    t   logt   debugt	   path_infoR   R   (   t   envt   srt   reqt   test_opt   r(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR   "   s    
c         C   s
   |  i  ƒ  S(    (   t   copy(   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   <lambda>,   s    s   /copyc         C   s   |  i  i ƒ  S(    (   t	   body_fileR   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   -   s    s	   /read-allc         C   s   |  i  i d  ƒ S(   i    (   R(   R   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   .   s    s   /read-0c         C   s
   |  i  ƒ  S(    (   t   make_body_seekable(   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   /   s    s   /make-seekablec          C   s¬   t  t ƒ i i ƒ  }  zŒ |  ~  } x| t D]t } t | | ƒ y t i d d ƒ } Wn" t j
 o t	 d | ƒ ‚ n X| d  j	 o d | f GHt | ƒ q* q* WWd  QXd  S(   NR   i   s   Error during test %ss   Error during test:(   R   t   _test_app_req_interruptR   R   t   _test_ops_req_interruptt   _send_interrupted_reqt   _global_rest   getR   R   t   NoneR   (   R   R   t   patht   res(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   test_interrupted_request8   s    # c         C   sµ   d } yp t  |  ƒ } | i } | | j o t d | | f ƒ ‚ n t | i } t i d | i ƒ t t | | ƒ Wn t	 i
 t i ƒ  ƒ n Xt	 i
 d  ƒ | d g  ƒ g  Sd  S(   Ni † s*   request.content_length is %s instead of %ss   Running test: %ss   200 OK(   R    t   content_lengthR   R+   R    R   t   infoR   t   IOErrorR-   t   putt   syst   exc_infoR/   (   R!   R"   t	   target_clR#   t   clt   op(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR*   F   s    	c         C   sB   |  i  i d ƒ d j p t ‚ t i d |  i  d |  i ƒ } d  S(   Ni    t    t   fpt   environ(   R(   R   R   t   cgit   FieldStorageR>   (   R#   t   d(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   _req_int_cgiX   s     		c         C   sM   y t  |  i i ƒ  d ƒ Wn t j
 o t d ƒ ‚ n X|  i i ƒ  d  S(   Ns   a=b
s   False disconnect alert(   t   eqR(   t   readlineR5   R   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   _req_int_readline`   s
    c         C   s
   |  i  ƒ  S(    (   R&   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   j   s    c         C   s   |  i  S(    (   t   body(   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   k   s    s
   /read-bodyc         C   s   |  i  S(    (   t   POST(   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   l   s    s
   /read-postc         C   s   |  i  i ƒ  S(    (   R(   R   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   m   s    c         C   s   |  i  i d ƒ S(   i   i   i  @ (   R(   R   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   n   s    s   /read-too-muchs	   /readlinec         C   s   |  i  i ƒ  S(    (   R(   t	   readlines(   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   p   s    s
   /readliness	   /read-cgic         C   s
   |  i  ƒ  S(    (   R)   (   R#   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   r   s    t   /c         C   sj   t  i  ƒ  } | i d |  i f ƒ | i d ƒ } | i t t | ƒ ƒ | i ƒ  | i ƒ  | i ƒ  d  S(   Nt	   localhostt   wb(	   t   sockett   connectt   server_portt   makefilet   writeR   t   _interrupted_reqt   flusht   close(   R   R0   t   sockt   f(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR,   v   s    

s]   POST %s HTTP/1.0
content-type: application/x-www-form-urlencoded
content-length: 100000

s   a=b
z=t   xi'  c         c   s»   t  |  ƒ } zX t i d | i ƒ } | i t ƒ | i ƒ  d | i | _ t	 i
 d | i ƒ | VWd  t	 i
 d ƒ | i ƒ  | i d ƒ | i ƒ  o t	 i d ƒ n t	 i
 d ƒ Xd  S(   Nt   targets   http://localhost:%ds   server started on %ss   shutting server downi   s   worker is hangeds   server stopped(   t   _make_test_servert	   threadingt   Threadt   serve_forevert	   setDaemont   Truet   startRN   R   R   R   t   shutdownt   joint   isAlivet   warning(   t   appR   t   worker(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR   ˆ   s    
	
t   QuietHanlderc           B   s   e  Z d  „  Z RS(   c         G   s   d  S(   N(    (   t   selft   args(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   log_requestž   s    (   t   __name__t
   __module__Rh   (    (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyRe      s   c           C   s   d  S(   N(   R/   (    (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyR'   ¡   s    t   QuietServerc           B   s   e  Z d  „  Z RS(   c         C   s   d  S(   N(    (   Rf   R#   t   addr(    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   handle_error¤   s    (   Ri   Rj   Rm   (    (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyRk   £   s   c         C   sŠ   d } x} t  d d d ƒ D]i } yE t i | d | ƒ } t d | |  d t d	 t ƒ} d
 | _ | SWq | d j o ‚  q‚ q Xq Wd  S(   Ni   i   i   i    iÿÿÿÿi   RJ   t   server_classt   handler_classi   i   iÿÿ  (   t   ranget   randomt   randintR
   Rk   Re   R   (   Rc   t   maxportt   it   portR   (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyRX   §   s     		t   __main__(.   R7   t   loggingRY   Rq   RL   R?   t   webob.requestR    t   webob.responseR   t   webob.compatR   R   R   R   R   t
   contextlibR   t
   nose.toolsR   R	   RC   t   wsgiref.simple_serverR
   R   R   R   t	   getLoggerRi   R   R   R   R   R2   R-   R*   RB   RE   R+   R,   RQ   R   Re   Rm   Rk   RX   (    (    (    s4   /home/chrism/projects/webob/tests/test_in_wsgiref.pyt   <module>   sh   	
		


							






	