
    g{"                        d dl mZmZmZmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZmZmZ d dlmZ d dlZ G d de	      Z G d	 d
e      Zi Z G d de      Z G d de      Z G d de	      Z G d de      Zd Z ed      Z ed      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d de      Z#y)     )HTTPHeadersHTTPMessageDelegateHTTPServerConnectionDelegateResponseStartLine)HostMatchesPathMatchesReversibleRouterRouterRule
RuleRouter)AsyncHTTPTestCase)Application	HTTPErrorRequestHandler)WSGIContainerNc                       e Zd Zd Zy)BasicRouterc                 D     G d dt               } ||j                        S )Nc                       e Zd Zd Zd Zy)1BasicRouter.find_handler.<locals>.MessageDelegatec                     || _         y N
connectionselfr   s     N/var/www/openai/venv/lib/python3.12/site-packages/tornado/test/routing_test.py__init__z:BasicRouter.find_handler.<locals>.MessageDelegate.__init__%   	    ",    c                     | j                   j                  t        ddd      t        ddi      d       | j                   j	                          y NHTTP/1.1   OKContent-Length2   OK)r   write_headersr   r   finishr   s    r   r*   z8BasicRouter.find_handler.<locals>.MessageDelegate.finish(   sC    --%j#t<!13 78
 &&(r    N__name__
__module____qualname__r   r*    r    r   MessageDelegater   $   s    -)r    r1   )r   r   )r   requestkwargsr1   s       r   find_handlerzBasicRouter.find_handler#   s"    
	)1 
	) w1122r    N)r-   r.   r/   r4   r0   r    r   r   r   "   s    3r    r   c                       e Zd Zd Zd Zy)BasicRouterTestCasec                     t               S r   )r   r+   s    r   get_appzBasicRouterTestCase.get_app4   s
    }r    c                 ^    | j                  d      }| j                  |j                  d       y )Nz/any_requestr(   fetchassertEqualbodyr   responses     r   test_basic_routerz%BasicRouterTestCase.test_basic_router7   s$    ::n-.r    N)r-   r.   r/   r8   r@   r0   r    r   r6   r6   3   s    /r    r6   c                       e Zd Zd Zy)GetResourcec                 Z    |t         vrt        d      | j                  t         |          y )N  )	resourcesr   r*   r   paths     r   getzGetResource.get@   s$    y C. IdO$r    Nr-   r.   r/   rH   r0   r    r   rB   rB   ?   s    %r    rB   c                       e Zd Zd Zy)PostResourcec                 >    | j                   j                  t        |<   y r   )r2   r=   rE   rF   s     r   postzPostResource.postH   s    ,,++	$r    N)r-   r.   r/   rM   r0   r    r   rK   rK   G   s    ,r    rK   c                       e Zd Zd Zd Zy)HTTPMethodRouterc                     || _         y r   )app)r   rQ   s     r   r   zHTTPMethodRouter.__init__M   s	    r    c                     |j                   dk(  rt        nt        }| j                  j	                  |||j
                  g      S )NGET)	path_args)methodrB   rK   rQ   get_handler_delegaterG   )r   r2   r3   handlers       r   r4   zHTTPMethodRouter.find_handlerP   s6    !(5!8+lxx,,Wg',,,XXr    N)r-   r.   r/   r   r4   r0   r    r   rO   rO   L   s    Yr    rO   c                       e Zd Zd Zd Zy)HTTPMethodRouterTestCasec                 (    t        t                     S r   )rO   r   r+   s    r   r8   z HTTPMethodRouterTestCase.get_appV   s    ..r    c                 P   | j                  ddd      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  |j                  d       y )	Nz/post_resourcePOSTdata)rU   r=   r$   z/get_resourcerD   s   data)r;   r<   coder=   r>   s     r   test_http_method_routerz0HTTPMethodRouterTestCase.test_http_method_routerY   s    ::.vF:K,::o.,::./,0r    N)r-   r.   r/   r8   r_   r0   r    r   rY   rY   U   s    /	1r    rY   c                 *      G  fddt               }|S )Nc                       e Zd Z fdZy)#_get_named_handler.<locals>.Handlerc                     | j                   j                  j                  d      +| j                  | j                   j                  d   dz          | j	                  dz   | j                        z          y )Napp_namez: )applicationsettingsrH   writer*   reverse_url)r   argsr3   handler_names      r   rH   z'_get_named_handler.<locals>.Handler.getg   sc    ((,,Z8D

4++44Z@4GHKKt+d.>.>|.LLMr    NrI   )rj   s   r   Handlerrb   f   s	    	Nr    rk   )r   )rj   rk   s   ` r   _get_named_handlerrl   e   s    N. N Nr    first_handlersecond_handlerc                   0     e Zd Z fdZd Zd Zd Z xZS )CustomRouterc                 0    t         |           i | _        y r   )superr   routes)r   	__class__s    r   r   zCustomRouter.__init__u   s    r    c                 :    | j                   j                  |       y r   )rs   update)r   rs   s     r   
add_routeszCustomRouter.add_routesy   s    6"r    c                     |j                   | j                  v r.| j                  |j                      \  }}|j                  ||      S y r   )rG   rs   rV   )r   r2   r3   rQ   rW   s        r   r4   zCustomRouter.find_handler|   s@    <<4;;&;;w||4LC++GW== 'r    c                 0    d|z   }|| j                   v r|S d S )N/)rs   )r   nameri   handler_paths       r   rh   zCustomRouter.reverse_url   s!    Tz+t{{:|DDr    )r-   r.   r/   r   rw   r4   rh   __classcell__)rt   s   @r   rp   rp   t   s    #>
Er    rp   c                       e Zd Zd Zd Zy)CustomRouterTestCasec                     t                G fddt              } |d      } |d      }j                  |t        f|t        f|t        fd       S )Nc                       e Zd Z fdZy)7CustomRouterTestCase.get_app.<locals>.CustomApplicationc                 *     j                   |g| S r   )rh   )r   r{   ri   routers      r   rh   zCCustomRouterTestCase.get_app.<locals>.CustomApplication.reverse_url   s    )v))$666r    N)r-   r.   r/   rh   )r   s   r   CustomApplicationr      s    7r    r   app1)rd   app2)/first_handler/second_handler/first_handler_second_app)rp   r   rw   FirstHandlerSecondHandler)r   r   r   r   r   s       @r   r8   zCustomRouterTestCase.get_app   s^    	7 	7 !&1 &1#'"6$(-#8.2L-A	
 r    c                    | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       y )Nr   s#   app1: first_handler: /first_handlerr   s%   app2: second_handler: /second_handlerr   s#   app2: first_handler: /first_handlerr:   r>   s     r   test_custom_routerz'CustomRouterTestCase.test_custom_router   sn    ::./(NO::/0(PQ::9:(NOr    N)r-   r.   r/   r8   r   r0   r    r   r   r      s    (Pr    r   c                       e Zd Zd Zy)ConnectionDelegatec                 0     G d dt               } ||      S )Nc                       e Zd Zd Zd Zy)9ConnectionDelegate.start_request.<locals>.MessageDelegatec                     || _         y r   r   r   s     r   r   zBConnectionDelegate.start_request.<locals>.MessageDelegate.__init__   r   r    c                     d}| j                   j                  t        ddd      t        dt	        t        |            i             | j                   j                  |       | j                   j                          y )Nr(   r#   r$   r%   r&   )r   r)   r   r   strlenrg   r*   )r   response_bodys     r   r*   z@ConnectionDelegate.start_request.<locals>.MessageDelegate.finish   sa     %--%j#t<!13s=7I3J KL %%m4&&(r    Nr,   r0   r    r   r1   r      s    -)r    r1   )r   )r   server_connrequest_connr1   s       r   start_requestz ConnectionDelegate.start_request   s    	)1 	) |,,r    N)r-   r.   r/   r   r0   r    r   r   r      s    -r    r   c                       e Zd Zd Zd Zy)RuleRouterTestc                 b   t               }d }t               }|j                  d|t        d      fi       |j	                  dt        d      t        d      di dfgft        t        d	      |      t        t        d      t        d
      t        t        d      |      dt               fg       |S )Nc                     | j                   j                  t        ddd      t        ddi             | j                   j	                  d       | j                   j                          y r"   )r   r)   r   r   rg   r*   )r2   s    r   request_callablez0RuleRouterTest.get_app.<locals>.request_callable   sX    ,,!*c48-s34 $$U+%%'r    /nested_handlernested_handlerz.*www.example.comr   z'tornado.test.routing_test.SecondHandlerrn   z
/.*handlerrm   )r{   /request_callable/connection_delegate)
r   rp   rw   rl   add_handlersr   r   r   r   r   )r   rQ   r   r   s       r   r8   zRuleRouterTest.get_app   s    m	( &89I&J KL	
 	   12 ((89E,	
 [.7[!12LW[!457GH');)=>	
* 
r    c                    | j                  d      }| j                  |j                  d       | j                  dddi      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  d	      }| j                  |j                  d
       | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d
       y )Nr   s   first_handler: /first_handlerHostr   )headerss   second_handler: /first_handlerr   s   nested_handler: /nested_handlerz/nested_not_found_handlerrD   r   r(   r   /404)r;   r<   r=   r^   r>   s     r   test_rule_based_routerz%RuleRouterTest.test_rule_based_router   s   ::./(HI::.AR8S:T(IJ::/0(JK::9:,::45.::12.::f%,r    N)r-   r.   r/   r8   r   r0   r    r   r   r      s    %N-r    r   c                   $    e Zd Zd Zd Zd Zd Zy)WSGIContainerTestCasec           	          t        | j                        } G d dt              }t        t	        d      t        d|i dfg      ft	        d      |fg      S )Nc                       e Zd Zd Zy).WSGIContainerTestCase.get_app.<locals>.Handlerc                 D    | j                  | j                  d             y )Ntornado)r*   rh   )r   ri   r3   s      r   rH   z2WSGIContainerTestCase.get_app.<locals>.Handler.get   s    D,,Y78r    NrI   r0   r    r   rk   r      s    9r    rk   z
/tornado.*/tornado/testr   /wsgi)r   wsgi_appr   r   r   r   )r   r   rk   s      r   r8   zWSGIContainerTestCase.get_app   sc     /	9n 	9   -"2GR!K LM W%x0
 	
r    c                      |dg        dgS )Nz200 OK   WSGIr0   )r   environstart_responses      r   r   zWSGIContainerTestCase.wsgi_app  s    x$yr    c                     | j                  d      }| j                  |j                  d       | j                  d      }| j                  |j                  d       y )Nr   s   /tornado/testr   r   r:   r>   s     r   test_wsgi_containerz)WSGIContainerTestCase.test_wsgi_container  sG    ::o.(89::g&0r    c                 ^    | j                  d      }| j                  |j                  d       y )Nr   rD   )r;   r<   r^   r>   s     r   test_delegate_not_foundz-WSGIContainerTestCase.test_delegate_not_found  s$    ::f%,r    N)r-   r.   r/   r8   r   r   r   r0   r    r   r   r      s    
"1-r    r   )$tornado.httputilr   r   r   r   tornado.routingr   r   r	   r
   r   r   tornado.testingr   tornado.webr   r   r   tornado.wsgir   typingr   r6   rE   rB   rK   rO   rY   rl   r   r   rp   r   r   r   r   r0   r    r   <module>r      s      . > > & 3& 3"/+ / 	%. %,> ,
Yv Y10 1  "/2"#34E# E$P, P<-5 -$<-& <-~-- -r    