o
    Ž¨Êh©  ã                   @   s‚   d dl mZ d dl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 edg d¢ƒZG d	d
„ d
eƒZG dd„ deƒZdS )é    )Úprint_function)Ú
namedtuple)ÚRequestsMock)Úioloop)ÚFuture)ÚHTTPRequestÚHTTPResponseÚ	HTTPErrorÚRequest)ÚurlÚmethodÚheadersÚbodyc                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚResponseGeneratorc                 C   s   | S ©N© )Úselfr   r   r   úD/var/www/html/env/lib/python3.10/site-packages/test/tornado/utils.pyÚget_adapter   s   zResponseGenerator.get_adapterc                 C   sˆ   t ||j|j|jd dd�}|j|_tƒ }d |_|jdk s!|jdkr7t|j|d�|_	t
 ¡  ¡  |j|j	¡ |S t
 ¡  ¡  |j|¡ |S )NÚ )r   Úeffective_urlÚerrorÚbufferéÈ   i,  )Úresponse)r   Ústatusr   r   ÚdataÚ_bodyr   Úcontentr	   r   r   ÚIOLoopÚcurrentÚadd_callbackÚset_exceptionÚ
set_result)r   Úrequestr   ÚrespÚfr   r   r   Úbuild_response   s   ÿÿz ResponseGenerator.build_responseN)Ú__name__Ú
__module__Ú__qualname__r   r(   r   r   r   r   r      s    r   c                   @   r   )ÚAsyncClientMockc                    s2   dd l }d‡ fdd„	}| d|¡ˆ _ˆ j ¡  d S )Nr   c                    s>   t |tƒst|| dd¡| dg ¡| dd¡ƒ}ˆ  tƒ |¡S )Nr   ÚGETr   r   r   )Ú
isinstancer   r
   ÚgetÚ_on_requestr   )Úclientr%   ÚcallbackÚkwargs©r   r   r   Úunbound_on_send"   s   



ýz.AsyncClientMock.start.<locals>.unbound_on_sendz(tornado.httpclient.AsyncHTTPClient.fetchr   )ÚmockÚpatchÚ_patcherÚstart)r   r6   r5   r   r4   r   r9      s   ÿzAsyncClientMock.startc                 C   s   | j  ¡  d S r   )r8   Ústopr4   r   r   r   r:   -   s   zAsyncClientMock.stopN)r)   r*   r+   r9   r:   r   r   r   r   r,      s    r,   N)Ú
__future__r   Úcollectionsr   Ú	responsesr   Útornador   Útornado.concurrentr   Útornado.httpclientr   r   r	   r
   Úobjectr   r,   r   r   r   r   Ú<module>   s    