o
    h                     @   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re#  dS 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   sz   t  }t|d | | d | |  t  }|  | }t|d | | | |s;| | d d S d S N*   )r   r   assertEqualresultassertFalse	cancelledcancel)selffutis_cancelled r   P/var/www/vscode/kcb/lib/python3.10/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                   @      e Zd Zejdd ZdS )	CapServerc                 c   sP    | 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       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   r0   r   r   r   __init__H   s   
zBaseCapClient.__init__c                 C   s@   t dt|}|d u rtd| \}}|dkr|S t|)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   r1   r:   r   r   r   r   r-   G   s    r-   c                   @   r   )GeneratorCapClientc                 c   s~    t d tt }t d |d| jfV  |t|d  t d |dV }t d |	  t
| |)N
capitalize
connectingz	127.0.0.1
readingr!   	returning)loggingdebugr	   socketconnectr0   r$   r   r"   r%   r   Returnr:   )r   request_datar&   r(   r   r   r   r<   W   s   



zGeneratorCapClient.capitalizeN)r   r   r   r   r*   r<   r   r   r   r   r;   V   r+   r;   c                       sl   e Zd ZdZ fddZ fddZdejfddZdejfd	d
Z	dejfddZ
dejfddZ  ZS )ClientTestMixinNc                    s<   t    t | _t \}}| j|g | j|d| _d S )Nr/   )supersetUpr    serverr   add_socketsclient_classclient)r   sockr0   	__class__r   r   rI   h   s
   

zClientTestMixin.setUpc                    s   | j   t   d S r.   )rJ   stoprH   tearDownr   rO   r   r   rR   o   s   
zClientTestMixin.tearDownr   c                 C   s8   | j d}| j|| j |   | | d d S NhelloHELLO)rM   r<   io_loop
add_futurerQ   waitr   r   r   futurer   r   r   test_futures      zClientTestMixin.test_futurec                 C   s8   | j d}| j|| j |   | td|j d S )NrV   already capitalized)	rM   r<   rW   rX   rQ   rY   assertRaisesRegexr,   r   rZ   r   r   r   test_future_errory   r]   z!ClientTestMixin.test_future_errorc                    "   t j fdd} j| d S )Nc                  3   s      j dV }  | d d S rT   )rM   r<   r   )r   rS   r   r   f   s   z)ClientTestMixin.test_generator.<locals>.fr   r*   rW   run_syncr   rb   r   rS   r   test_generator      zClientTestMixin.test_generatorc                    ra   )Nc                   3   sB      td  jdV  W d    d S 1 sw   Y  d S )Nr^   rV   )r_   r,   rM   r<   r   rS   r   r   rb      s   "z/ClientTestMixin.test_generator_error.<locals>.frc   re   r   rS   r   test_generator_error   rg   z$ClientTestMixin.test_generator_error)r   r   r   rL   rI   rR   typingAnyr\   r`   rf   rh   __classcell__r   r   rO   r   rG   e   s    rG   c                   @   s   e Zd ZeZdS )GeneratorClientTestN)r   r   r   r;   rL   r   r   r   r   rl      s    rl   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   2    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      t jd| _d S N   r   threadThreadPoolExecutorexecutorrS   r   r   r   r1         z:RunOnExecutorTest.test_no_calling.<locals>.Object.__init__c                 S      dS r   r   rS   r   r   r   rb         z3RunOnExecutorTest.test_no_calling.<locals>.Object.fNr   r   r   r1   r   rb   r   r   r   r   Object   s    rz   r   objectrb   r   r   rz   oanswerr   r   r   test_no_calling   
   
z!RunOnExecutorTest.test_no_callingc                 c   rn   )Nc                   @   "   e Zd Zdd Ze dd ZdS )z8RunOnExecutorTest.test_call_with_no_args.<locals>.Objectc                 S   ro   rp   rr   rS   r   r   r   r1      rv   zARunOnExecutorTest.test_call_with_no_args.<locals>.Object.__init__c                 S   rw   r   r   rS   r   r   r   rb      rx   z:RunOnExecutorTest.test_call_with_no_args.<locals>.Object.fNry   r   r   r   r   rz          rz   r   r{   r}   r   r   r   test_call_with_no_args   r   z(RunOnExecutorTest.test_call_with_no_argsc                 c   rn   )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   ro   rp   )r   rs   rt   _Object__executorrS   r   r   r   r1      rv   zBRunOnExecutorTest.test_call_with_executor.<locals>.Object.__init__r   )ru   c                 S   rw   r   r   rS   r   r   r   rb      rx   z;RunOnExecutorTest.test_call_with_executor.<locals>.Object.fNry   r   r   r   r   rz      s    rz   r   r{   r}   r   r   r   test_call_with_executor   r   z)RunOnExecutorTest.test_call_with_executorc                 #   s<    G dd dt }|   fdd}| V }| |d d S )Nc                   @   r   )z2RunOnExecutorTest.test_async_await.<locals>.Objectc                 S   ro   rp   rr   rS   r   r   r   r1      rv   z;RunOnExecutorTest.test_async_await.<locals>.Object.__init__c                 S   rw   r   r   rS   r   r   r   rb      rx   z4RunOnExecutorTest.test_async_await.<locals>.Object.fNry   r   r   r   r   rz      r   rz   c                     s      I d H } | S r.   )rb   )r   r~   r   r   rb      s   z-RunOnExecutorTest.test_async_await.<locals>.fr   )r|   r   )r   rz   rb   r   r   r   r   test_async_await   s   z"RunOnExecutorTest.test_async_awaitN)r   r   r   r   r   r   r   r   r   r   r   r   rm      s    


rm   __main__)$
concurrentr   rA   r3   rC   ri   unittesttornado.concurrentr   r   r   tornado.escaper   r   tornador   tornado.iostreamr	   tornado.tcpserverr
   tornado.testingr   r   r   r   r    r5   r,   r|   r-   r;   rG   rl   rm   r   mainr   r   r   r   <module>   s.   +?