o
    )Zh{"                     @   s<  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 de	ZG d	d
 d
eZi ZG dd deZG dd deZG dd de	ZG dd deZdd ZedZedZG dd deZG dd deZ G dd deZ!G dd deZ"G d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d ZdS )BasicRouterc                 K   s   G dd dt }||jS )Nc                   @      e Zd Zdd Zdd ZdS )z1BasicRouter.find_handler.<locals>.MessageDelegatec                 S   
   || _ d S N
connectionselfr    r   P/var/www/html/lang_env/lib/python3.10/site-packages/tornado/test/routing_test.py__init__%      
z:BasicRouter.find_handler.<locals>.MessageDelegate.__init__c                 S   s.   | 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   r   r   r   r&   (   s   

z8BasicRouter.find_handler.<locals>.MessageDelegate.finishN__name__
__module____qualname__r   r&   r   r   r   r   MessageDelegate$       r,   )r   r   )r   requestkwargsr,   r   r   r   find_handler#   s   
zBasicRouter.find_handlerN)r)   r*   r+   r0   r   r   r   r   r   "       r   c                   @   r   )BasicRouterTestCasec                 C   s   t  S r   )r   r'   r   r   r   get_app4   s   zBasicRouterTestCase.get_appc                 C      |  d}| |jd d S )Nz/any_requestr$   fetchassertEqualbodyr   responser   r   r   test_basic_router7      
z%BasicRouterTestCase.test_basic_routerN)r)   r*   r+   r3   r;   r   r   r   r   r2   3   r-   r2   c                   @   r   )GetResourcec                 C   s"   |t vrtd| t |  d S )N  )	resourcesr   r&   r   pathr   r   r   get@   s   zGetResource.getNr)   r*   r+   rB   r   r   r   r   r=   ?   r1   r=   c                   @   r   )PostResourcec                 C   s   | j jt|< d S r   )r.   r8   r?   r@   r   r   r   postH      zPostResource.postN)r)   r*   r+   rE   r   r   r   r   rD   G   r1   rD   c                   @   r   )HTTPMethodRouterc                 C   r   r   )app)r   rH   r   r   r   r   M   r   zHTTPMethodRouter.__init__c                 K   s(   |j dkrtnt}| jj|||jgdS )NGET)Z	path_args)methodr=   rD   rH   get_handler_delegaterA   )r   r.   r/   handlerr   r   r   r0   P   s   zHTTPMethodRouter.find_handlerN)r)   r*   r+   r   r0   r   r   r   r   rG   L   r-   rG   c                   @   r   )HTTPMethodRouterTestCasec                 C   s
   t t S r   )rG   r   r'   r   r   r   r3   V   r   z HTTPMethodRouterTestCase.get_appc                 C   s`   | j dddd}| |jd |  d}| |jd |  d}| |jd | |jd d S )	Nz/post_resourcePOSTdata)rJ   r8   r    z/get_resourcer>   s   data)r6   r7   coder8   r9   r   r   r   test_http_method_routerY   s   

z0HTTPMethodRouterTestCase.test_http_method_routerN)r)   r*   r+   r3   rQ   r   r   r   r   rM   U   r-   rM   c                    s   G  fdddt }|S )Nc                          e Zd Z fddZdS )z#_get_named_handler.<locals>.Handlerc                    sD   | j jdd ur| | j jd d  |  d |    d S )Napp_namez: )ZapplicationsettingsrB   writer&   reverse_urlr   argsr/   handler_namer   r   rB   g   s   z'_get_named_handler.<locals>.Handler.getNrC   r   rY   r   r   Handlerf       r[   )r   )rZ   r[   r   rY   r   _get_named_handlere   s   r]   first_handlersecond_handlerc                       s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	CustomRouterc                    s   t    i | _d S r   )superr   routesr'   	__class__r   r   r   u   s   

zCustomRouter.__init__c                 C   s   | j | d S r   )rb   update)r   rb   r   r   r   
add_routesy   rF   zCustomRouter.add_routesc                 K   s,   |j | jv r| j|j  \}}|||S d S r   )rA   rb   rK   )r   r.   r/   rH   rL   r   r   r   r0   |   s   zCustomRouter.find_handlerc                 G   s   d| }|| j v r|S d S )N/)rb   )r   namerX   Zhandler_pathr   r   r   rV      s   zCustomRouter.reverse_url)r)   r*   r+   r   rf   r0   rV   __classcell__r   r   rc   r   r`   t   s
    r`   c                   @   r   )CustomRouterTestCasec                    sP   t   G  fdddt}|dd}|dd} |tf|tf|tfd  S )Nc                       rR   )z7CustomRouterTestCase.get_app.<locals>.CustomApplicationc                    s    j |g|R  S r   )rV   )r   rh   rX   routerr   r   rV      s   zCCustomRouterTestCase.get_app.<locals>.CustomApplication.reverse_urlN)r)   r*   r+   rV   r   rk   r   r   CustomApplication   r\   rm   app1)rS   app2)/first_handler/second_handler/first_handler_second_app)r`   r   rf   FirstHandlerSecondHandler)r   rm   rn   ro   r   rk   r   r3      s   

zCustomRouterTestCase.get_appc                 C   sL   |  d}| |jd |  d}| |jd |  d}| |jd d S )Nrp   s#   app1: first_handler: /first_handlerrq   s%   app2: second_handler: /second_handlerrr   s#   app2: first_handler: /first_handlerr5   r9   r   r   r   test_custom_router   s   


z'CustomRouterTestCase.test_custom_routerN)r)   r*   r+   r3   ru   r   r   r   r   rj      s    rj   c                   @   r   )ConnectionDelegatec                 C   s   G dd dt }||S )Nc                   @   r   )z9ConnectionDelegate.start_request.<locals>.MessageDelegatec                 S   r   r   r   r   r   r   r   r      r   zBConnectionDelegate.start_request.<locals>.MessageDelegate.__init__c                 S   sD   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lenrU   r&   )r   Zresponse_bodyr   r   r   r&      s   
z@ConnectionDelegate.start_request.<locals>.MessageDelegate.finishNr(   r   r   r   r   r,      r-   r,   )r   )r   Zserver_connZrequest_connr,   r   r   r   start_request   s   z ConnectionDelegate.start_requestN)r)   r*   r+   ry   r   r   r   r   rv      r1   rv   c                   @   r   )RuleRouterTestc              
   C   s   t  }d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dttd|dt	 fg |S )Nc                 S   s8   | j tdddtddi | j d | j   d S r   )r   r%   r   r   rU   r&   )r.   r   r   r   request_callable   s   

z0RuleRouterTest.get_app.<locals>.request_callable/nested_handlerZnested_handlerz.*www.example.comrp   z'tornado.test.routing_test.SecondHandlerr_   z
/.*handlerr^   )rh   /request_callable/connection_delegate)
r   r`   rf   r]   add_handlersr   r   r
   rs   rv   )r   rH   r{   rl   r   r   r   r3      s.   zRuleRouterTest.get_appc                 C   s   |  d}| |jd | j dddid}| |jd |  d}| |jd |  d	}| |jd
 |  d}| |jd |  d}| |jd |  d}| |jd
 d S )Nrp   s   first_handler: /first_handlerHostr}   )headerss   second_handler: /first_handlerr|   s   nested_handler: /nested_handlerz/nested_not_found_handlerr>   r   r$   r~   /404)r6   r7   r8   rP   r9   r   r   r   test_rule_based_router   s   





z%RuleRouterTest.test_rule_based_routerN)r)   r*   r+   r3   r   r   r   r   r   rz      s    'rz   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
WSGIContainerTestCasec                 C   sD   t | j}G dd dt}ttdtd|i dfgftd|fgS )Nc                   @   r   )z.WSGIContainerTestCase.get_app.<locals>.Handlerc                 _   s   |  | d d S )Ntornado)r&   rV   rW   r   r   r   rB      s   z2WSGIContainerTestCase.get_app.<locals>.Handler.getNrC   r   r   r   r   r[      r1   r[   z
/tornado.*/tornado/testr   /wsgi)r   wsgi_appr   r   r   r   )r   r   r[   r   r   r   r3      s   

zWSGIContainerTestCase.get_appc                 C   s   |dg  dgS )Nz200 OK   WSGIr   )r   environZstart_responser   r   r   r     s   
zWSGIContainerTestCase.wsgi_appc                 C   s4   |  d}| |jd |  d}| |jd d S )Nr   s   /tornado/testr   r   r5   r9   r   r   r   test_wsgi_container  s   

z)WSGIContainerTestCase.test_wsgi_containerc                 C   r4   )Nr   r>   )r6   r7   rP   r9   r   r   r   test_delegate_not_found  r<   z-WSGIContainerTestCase.test_delegate_not_foundN)r)   r*   r+   r3   r   r   r   r   r   r   r   r      s
    r   )$Ztornado.httputilr   r   r   r   Ztornado.routingr   r   r   r	   r
   r   Ztornado.testingr   Ztornado.webr   r   r   Ztornado.wsgir   typingr   r2   r?   r=   rD   rG   rM   r]   rs   rt   r`   rj   rv   rz   r   r   r   r   r   <module>   s*    		?