
    Df                         d Z ddlmZ ddlmZ ddlZddlZddlZddlm	Z
 ddlmZ ddlmZ ddlmZmZ epeZej        d	             Zej                            d
d          d             Zd Zd ZdS )z
Test wsgi.    )ThreadPoolExecutor)print_tbN)BaseUrlSession)ExceptionTrap)wsgi)IS_MACOS
IS_WINDOWSc               #   .  K   t          j                    } d }d}|| f}t          j        ||t          rdnd          } dj        di t                      }|                                5 }t                      V  ddd           dS # 1 swxY w Y   dS )	z)Fucking simple wsgi server fixture (duh).c                 *    d}dg} |||           dgS )Nz200 OK)zContent-typez
text/plains   Hello world! )_environstart_responsestatusresponse_headerss       E/var/www/media/lib/python3.11/site-packages/cheroot/test/test_wsgi.pyappzsimple_wsgi_server.<locals>.app   s,    :;v/000      z::iX     )timeoutzhttp://localhost:{port}/Nr   )portendfind_available_local_portr   ServerIS_SLOW_ENVformatlocals_run_in_thread)portr   hostaddrserverurlthreads          r   simple_wsgi_serverr#      s       ,..D! ! ! D:D[s;,FCCBGGGF
+
$
+
7
7fhh
7
7C				 	  Fhh                 s   ,B

BB      )rerunsreruns_delayc                    t          | d                   t          j                            dd          }                    d|           fdt          t          rdnd	
          5 fdt          t          rdnd          D             }t          d |D                       }ddd           n# 1 swxY w Y   	                                 |rJ dS )z*Test the connection keepalive works (duh).r!   )base_url   i  )pool_connectionspool_maxsizezhttp://c                     t          t          j        j                  5 }                     d          }|                                 d d d            n# 1 swxY w Y   t          | j                   t          |           S )Ninfo)	r   requests
exceptionsConnectionErrorgetraise_for_statusr   tbbool)traprespsessions     r   
do_requestz-test_connection_keepalive.<locals>.do_request1   s    8.>?? 	$4;;v&&D!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	Dzzs   *AAA
   2   )max_workersc                 :    g | ]}                               S r   )submit).0nr9   pools     r   
<listcomp>z-test_connection_keepalive.<locals>.<listcomp>9   s5     
 
 
 KK
##
 
 
r      c              3   >   K   | ]}|                                 V  d S N)result)r?   tasks     r   	<genexpr>z,test_connection_keepalive.<locals>.<genexpr>=   s*      77t{{}}777777r   N)
Sessionr/   adaptersHTTPAdaptermountr   r   rangesumclose)r#   pooledtasksfailuresr9   rA   r8   s       @@@r   test_connection_keepaliverS   (   sY    1%8999G** +  F MM)V$$$     
k(Ar	B	B	B 8d
 
 
 
 
+733488
 
 
 77777778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 MMOOOs   /?B::B>B>c                    |                      t          j        dd            t          j        d          }d|_        d}t	          j        t          |          5  |                    ddd           ddd           dS # 1 swxY w Y   dS )	z>Verify that repeat calls of ``Gateway.start_response()`` fail.get_environc                     i S rE   r   selfs    r   <lambda>z:test_gateway_start_response_called_twice.<locals>.<lambda>E       " r   NTz<^WSGI start_response called a second time with no exc_info.$match200r   )setattrr   Gatewaystarted_responsepytestraisesRuntimeErrorr   monkeypatchwsgi_gatewayerr_msgs      r   (test_gateway_start_response_called_twicerh   C   s    m__EEE<%%L$(L!LG	|7	3	3	3 5 5##E2t4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s   B  BBc                    |                      t          j        dd            t          j        d          }d}t          j        t
          |          5  |                    d           ddd           dS # 1 swxY w Y   dS )z>Check that calling ``Gateway.write()`` needs started response.rU   c                     i S rE   r   rW   s    r   rY   zGtest_gateway_write_needs_start_response_called_before.<locals>.<lambda>P   rZ   r   Nz*^WSGI write called before start_response.$r[   )r^   r   r_   ra   rb   rc   writerd   s      r   5test_gateway_write_needs_start_response_called_beforerl   N   s    m__EEE<%%L:G	|7	3	3	3 ! !4   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !s   A77A;>A;)__doc__concurrent.futures.threadr   	tracebackr   ra   r   r/   requests_toolbelt.sessionsr   rI   jaraco.contextr   cherootr   cheroot._compatr   r	   r   fixturer#   markflakyrS   rh   rl   r   r   r   <module>rw      s     8 8 8 8 8 8          @ @ @ @ @ @ ( ( ( ( ( (       0 0 0 0 0 0 0 0 $*   ( !!,,  -,45 5 5! ! ! ! !r   