a
    Šxd¡  ã                   @   s(  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZm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G dd„ deƒZG dd„ deeƒZ G dd„ deƒZ!e"dkr$e #¡  dS )é    )ÚfuturesN)ÚFutureÚrun_on_executorÚ"future_set_result_unless_cancelled)Úutf8Ú
to_unicode)Úgen)ÚIOStream)Ú	TCPServer)ÚAsyncTestCaseÚbind_unused_portÚgen_testc                   @   s   e Zd Zdd„ ZdS )ÚMiscFutureTestc                 C   sv   t ƒ }t|dƒ |  | ¡ d¡ |  | ¡ ¡ t ƒ }| ¡  | ¡ }t|dƒ |  | ¡ |¡ |sr|  | ¡ d¡ d S ©Né*   )r   r   ÚassertEqualÚresultZassertFalseZ	cancelledÚcancel)ÚselfZfutZis_cancelled© r   úT/var/www/html/Ranjet/env/lib/python3.9/site-packages/tornado/test/concurrent_test.pyÚ'test_future_set_result_unless_cancelled#   s    

z6MiscFutureTest.test_future_set_result_unless_cancelledN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   "   s   r   c                   @   s   e Zd Zejdd„ ƒZdS )Ú	CapServerc                 c   sN   |  d¡V }t|ƒ}|| ¡ kr,| d¡ n| td| ¡  ƒ¡ | ¡  d S )Nó   
s   error	already capitalized
zok	%s)Ú
read_untilr   ÚupperÚwriter   Úclose)r   ÚstreamÚaddressÚdatar   r   r   Úhandle_stream7   s    zCapServer.handle_streamN)r   r   r   r   Ú	coroutiner$   r   r   r   r   r   6   s   r   c                   @   s   e Zd ZdS )ÚCapErrorN)r   r   r   r   r   r   r   r&   C   s   r&   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseCapClientc                 C   s
   || _ d S ©N©Úport)r   r*   r   r   r   Ú__init__H   s    zBaseCapClient.__init__c                 C   sD   t  dt|ƒ¡}|d u r tdƒ‚| ¡ \}}|dkr8|S t|ƒ‚d S )Nz
(.*)	(.*)
zdid not matchÚok)ÚreÚmatchr   Ú	ExceptionÚgroupsr&   )r   r#   ÚmÚstatusÚmessager   r   r   Úprocess_responseK   s    zBaseCapClient.process_responseN)r   r   r   r+   r4   r   r   r   r   r'   G   s   r'   c                   @   s   e Zd Zejdd„ ƒZdS )ÚGeneratorCapClientc                 c   s€   t  d¡ tt ¡ ƒ}t  d¡ | d| jf¡V  | t|d ƒ¡ t  d¡ | d¡V }t  d¡ | 	¡  t
 |  |¡¡‚d S )NÚ
capitalizeZ
connectingz	127.0.0.1Ú
Úreadingr   Z	returning)ÚloggingÚdebugr	   ÚsocketÚconnectr*   r   r   r   r    r   ÚReturnr4   )r   Zrequest_datar!   r#   r   r   r   r6   W   s    



zGeneratorCapClient.capitalizeN)r   r   r   r   r%   r6   r   r   r   r   r5   V   s   r5   c                       sl   e Zd ZdZ‡ fdd„Z‡ fdd„Zejdœdd„Zejdœd	d
„Z	ejdœdd„Z
ejdœdd„Z‡  ZS )ÚClientTestMixinNc                    s<   t ƒ  ¡  tƒ | _tƒ \}}| j |g¡ | j|d| _d S )Nr)   )ÚsuperÚsetUpr   Úserverr   Zadd_socketsÚclient_classÚclient)r   Úsockr*   ©Ú	__class__r   r   r@   h   s
    

zClientTestMixin.setUpc                    s   | j  ¡  tƒ  ¡  d S r(   )rA   Ústopr?   ÚtearDown©r   rE   r   r   rH   o   s    
zClientTestMixin.tearDownrI   c                 C   s8   | j  d¡}| j || j¡ |  ¡  |  | ¡ d¡ d S ©NZhelloÚHELLO)rC   r6   Úio_loopÚ
add_futurerG   Úwaitr   r   ©r   Úfuturer   r   r   Útest_futures   s    zClientTestMixin.test_futurec                 C   s8   | j  d¡}| j || j¡ |  ¡  |  td|j¡ d S )NrK   úalready capitalized)	rC   r6   rL   rM   rG   rN   ÚassertRaisesRegexr&   r   rO   r   r   r   Útest_future_errory   s    z!ClientTestMixin.test_future_errorc                    s"   t j‡ fdd„ƒ}ˆ j |¡ d S )Nc                  3   s   ˆ j  d¡V } ˆ  | d¡ d S rJ   )rC   r6   r   )r   rI   r   r   Úf€   s    z)ClientTestMixin.test_generator.<locals>.f©r   r%   rL   Zrun_sync©r   rU   r   rI   r   Útest_generator   s    zClientTestMixin.test_generatorc                    s"   t j‡ fdd„ƒ}ˆ j |¡ d S )Nc                   3   s>   ˆ   td¡ ˆ j d¡V  W d   ƒ n1 s00    Y  d S )NrR   rK   )rS   r&   rC   r6   r   rI   r   r   rU   ˆ   s    z/ClientTestMixin.test_generator_error.<locals>.frV   rW   r   rI   r   Útest_generator_error‡   s    z$ClientTestMixin.test_generator_error)r   r   r   rB   r@   rH   ÚtypingÚAnyrQ   rT   rX   rY   Ú__classcell__r   r   rE   r   r>   e   s   r>   c                   @   s   e Zd ZeZdS )ÚGeneratorClientTestN)r   r   r   r5   rB   r   r   r   r   r]      s   r]   c                   @   s<   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZd	S )
ÚRunOnExecutorTestc                 c   s0   G dd„ dt ƒ}|ƒ }| ¡ V }|  |d¡ d S )Nc                   @   s    e Zd Zdd„ Zedd„ ƒZdS )z1RunOnExecutorTest.test_no_calling.<locals>.Objectc                 S   s   t j d¡| _d S ©Né   ©r   ÚthreadÚThreadPoolExecutorÚexecutorrI   r   r   r   r+   ˜   s    z:RunOnExecutorTest.test_no_calling.<locals>.Object.__init__c                 S   s   dS r   r   rI   r   r   r   rU   ›   s    z3RunOnExecutorTest.test_no_calling.<locals>.Object.fN©r   r   r   r+   r   rU   r   r   r   r   ÚObject—   s   rf   r   ©ÚobjectrU   r   ©r   rf   ÚoÚanswerr   r   r   Útest_no_calling•   s    
z!RunOnExecutorTest.test_no_callingc                 c   s0   G dd„ dt ƒ}|ƒ }| ¡ V }|  |d¡ d S )Nc                   @   s"   e Zd Zdd„ Zeƒ dd„ ƒZdS )z8RunOnExecutorTest.test_call_with_no_args.<locals>.Objectc                 S   s   t j d¡| _d S r_   ra   rI   r   r   r   r+   ¦   s    zARunOnExecutorTest.test_call_with_no_args.<locals>.Object.__init__c                 S   s   dS r   r   rI   r   r   r   rU   ©   s    z:RunOnExecutorTest.test_call_with_no_args.<locals>.Object.fNre   r   r   r   r   rf   ¥   s   rf   r   rg   ri   r   r   r   Útest_call_with_no_args£   s    
z(RunOnExecutorTest.test_call_with_no_argsc                 c   s0   G dd„ dt ƒ}|ƒ }| ¡ V }|  |d¡ d S )Nc                   @   s&   e Zd Zdd„ Zedddd„ ƒZdS )z9RunOnExecutorTest.test_call_with_executor.<locals>.Objectc                 S   s   t j d¡| _d S r_   )r   rb   rc   Ú_Object__executorrI   r   r   r   r+   ´   s    zBRunOnExecutorTest.test_call_with_executor.<locals>.Object.__init__rn   )rd   c                 S   s   dS r   r   rI   r   r   r   rU   ·   s    z;RunOnExecutorTest.test_call_with_executor.<locals>.Object.fNre   r   r   r   r   rf   ³   s   rf   r   rg   ri   r   r   r   Útest_call_with_executor±   s    
z)RunOnExecutorTest.test_call_with_executorc                 #   s:   G dd„ dt ƒ}|ƒ ‰ ‡ fdd„}|ƒ V }|  |d¡ d S )Nc                   @   s"   e Zd Zdd„ Zeƒ dd„ ƒZdS )z2RunOnExecutorTest.test_async_await.<locals>.Objectc                 S   s   t j d¡| _d S r_   ra   rI   r   r   r   r+   Â   s    z;RunOnExecutorTest.test_async_await.<locals>.Object.__init__c                 S   s   dS r   r   rI   r   r   r   rU   Å   s    z4RunOnExecutorTest.test_async_await.<locals>.Object.fNre   r   r   r   r   rf   Á   s   rf   c                  “   s   ˆ   ¡ I d H } | S r(   )rU   )rk   ©rj   r   r   rU   Ë   s    z-RunOnExecutorTest.test_async_await.<locals>.fr   )rh   r   )r   rf   rU   r   r   rp   r   Útest_async_await¿   s
    z"RunOnExecutorTest.test_async_awaitN)r   r   r   r   rl   rm   ro   rq   r   r   r   r   r^   ”   s   


r^   Ú__main__)$Z
concurrentr   r9   r-   r;   rZ   ZunittestZtornado.concurrentr   r   r   Ztornado.escaper   r   Ztornador   Ztornado.iostreamr	   Ztornado.tcpserverr
   Ztornado.testingr   r   r   r   r   r/   r&   rh   r'   r5   r>   r]   r^   r   Úmainr   r   r   r   Ú<module>   s*   +?
