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

4+4Z@4GHHHKKt+d.>.>|.L.LLMMMMMr    NrI   )rj   s   r   Handlerrb   f   s5        	N 	N 	N 	N 	N 	N 	Nr    rk   )r   )rj   rk   s   ` r   _get_named_handlerrl   e   sH    N N N N N N N. N 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                 V    t                                                       i | _        d S r   )superr   routes)r   	__class__s    r   r   zCustomRouter.__init__u   s$    r    c                 :    | j                             |           d S r   )rs   update)r   rs   s     r   
add_routeszCustomRouter.add_routesy   s    6"""""r    c                 x    |j         | j        v r+| j        |j                  \  }}|                    ||          S d S r   )rG   rs   rV   )r   r2   r3   rQ   rW   s        r   r4   zCustomRouter.find_handler|   sA    <4;&&;w|4LC++GW=== '&r    c                 &    d|z   }|| j         v r|nd S )N/)rs   )r   nameri   handler_paths       r   rh   zCustomRouter.reverse_url   s!    Tz+t{::||Dr    )r-   r.   r/   r   rw   r4   rh   __classcell__)rt   s   @r   rp   rp   t   sl            # # #> > >
E E E E E E Er    rp   c                       e Zd Zd Zd ZdS )CustomRouterTestCasec                     t                       G fddt                    } |d          } |d          }                    |t          f|t          f|t          fd           S )Nc                       e Zd Z fdZdS )7CustomRouterTestCase.get_app.<locals>.CustomApplicationc                       j         |g|R  S r   )rh   )r   r{   ri   routers      r   rh   zCCustomRouterTestCase.get_app.<locals>.CustomApplication.reverse_url   s    )v)$66666r    N)r-   r.   r/   rh   )r   s   r   CustomApplicationr      s.        7 7 7 7 7 7 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 	7 	7 	7 	7 	7 	7 	7 	7 ! &111  &111#'"6$(-#8.2L-A 	
 	
 	
 r    c                 &   |                      d          }|                     |j        d           |                      d          }|                     |j        d           |                      d          }|                     |j        d           d S )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   s    ::.//(NOOO::/00(PQQQ::9::(NOOOOOr    N)r-   r.   r/   r8   r   r0   r    r   r   r      s7          (P P P P Pr    r   c                       e Zd Zd ZdS )ConnectionDelegatec                 >     G d dt                     } ||          S )Nc                       e Zd Zd Zd ZdS )9ConnectionDelegate.start_request.<locals>.MessageDelegatec                     || _         d S r   r   r   s     r   r   zBConnectionDelegate.start_request.<locals>.MessageDelegate.__init__   r   r    c                    d}| j                             t          ddd          t          dt	          t          |                    i                     | j                             |           | j                                          d S )Nr(   r#   r$   r%   r&   )r   r)   r   r   strlenrg   r*   )r   response_bodys     r   r*   z@ConnectionDelegate.start_request.<locals>.MessageDelegate.finish   s     %--%j#t<<!13s=7I7I3J3J KLL   %%m444&&(((((r    Nr,   r0   r    r   r1   r      s2        - - -) ) ) ) )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dS )RuleRouterTestc                    t                      }d }t                      }|                    d|t          d          fi           |                    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                             t          ddd          t          ddi                     | j                             d           | j                                          d S r"   )r   r)   r   r   rg   r*   )r2   s    r   request_callablez0RuleRouterTest.get_app.<locals>.request_callable   sq    ,,!*c488-s34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	   mm	( 	( 	( &89I&J&J KL	
 	
 	
 	   122 ((899E,	
 [..77[!122LWWW[!4557GHH');)=)=>	
 	
 	
* 
r    c                    |                      d          }|                     |j        d           |                      dddi          }|                     |j        d           |                      d          }|                     |j        d           |                      d	          }|                     |j        d
           |                      d          }|                     |j        d           |                      d          }|                     |j        d           |                      d          }|                     |j        d
           d S )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II::.AR8S:TT(IJJJ::/00(JKKK::9::,,,::455...::122...::f%%,,,,,r    N)r-   r.   r/   r8   r   r0   r    r   r   r      s3        % % %N- - - - -r    r   c                   &    e Zd Zd Zd Zd Zd ZdS )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dS ).WSGIContainerTestCase.get_app.<locals>.Handlerc                 V    |                      |                     d                     d S )Ntornado)r*   rh   )r   ri   r3   s      r   rH   z2WSGIContainerTestCase.get_app.<locals>.Handler.get   s(    D,,Y7788888r    NrI   r0   r    r   rk   r      s#        9 9 9 9 9r    rk   z
/tornado.*/tornado/testr   /wsgi)r   wsgi_appr   r   r   r   )r   r   rk   s      r   r8   zWSGIContainerTestCase.get_app   s     //	9 	9 	9 	9 	9n 	9 	9 	9   --"2GR!K LM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                     |                      d          }|                     |j        d           |                      d          }|                     |j        d           d S )Nr   s   /tornado/testr   r   r:   r>   s     r   test_wsgi_containerz)WSGIContainerTestCase.test_wsgi_container  s[    ::o..(8999::g&&00000r    c                 f    |                      d          }|                     |j        d           d S )Nr   rD   )r;   r<   r^   r>   s     r   test_delegate_not_foundz-WSGIContainerTestCase.test_delegate_not_found  s1    ::f%%,,,,,r    N)r-   r.   r/   r8   r   r   r   r0   r    r   r   r      sP        
 
 
"  1 1 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 3 3 3& 3 3 3"/ / / / /+ / / / 	% % % % %. % % %, , , , ,> , , ,
Y Y Y Y Yv Y Y Y1 1 1 1 10 1 1 1    "!/22""#344E E E E E# E E E$P P P P P, P P P<- - - - -5 - - -$<- <- <- <- <-& <- <- <-~- - - - -- - - - - -r    