o
    8Diu                     @   s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ zd dlZW n ey5   dZY nw edur@d dlmZ eedu dG d	d
 d
ejZG dd deZG dd deZG dd deZeedu dG dd deZdS )    )md5N)utf8)AsyncHTTPTestCase)httpclient_test)ApplicationRequestHandler)CurlAsyncHTTPClientzpycurl module not presentc                   @      e Zd Zdd ZdS )CurlHTTPClientCommonTestCasec                 C   s$   t tddd}| t|t  |S )NF
allow_ipv6)defaults)r   dict
assertTrue
isinstance)selfclient r   Z/var/www/Datamplify/venv/lib/python3.10/site-packages/tornado/test/curl_httpclient_test.pyget_http_client   s   z,CurlHTTPClientCommonTestCase.get_http_clientN)__name__
__module____qualname__r   r   r   r   r   r
      s    r
   c                   @   s   e Zd Zdd Zdd ZdS )DigestAuthHandlerc                 C   s   || _ || _d S Nusernamepassword)r   r   r   r   r   r   
initialize   s   
zDigestAuthHandler.initializec              
   C   s  d}d}d}| j jdd }|d ur|dd\}}|dks J i }|dD ]"}| d	d\}	}
|
d
 dkrE|
d dkrE|
dd }
|
||	< q'|d |ksRJ |d |ksZJ |d |ksbJ |d | jkskJ |d | j jksuJ tt| j d| d| j	 
 }tt| j j d| j j 
 }tt| d| d| 
 }||d kr| d d S | d d S | d | dd| d| d| d d S )Ntestasdf1234Authorization    Digest,=r   "realmopaquenoncer   uri:responseokfaili  zWWW-AuthenticatezDigest realm="z
", nonce="z", opaque=")requestheadersgetsplitstripr   pathr   r   r   	hexdigestmethodwrite
set_status
set_header)r   r*   r+   r,   auth_header	auth_modeparams
param_dictpairkvh1h2digestr   r   r   r4   !   s:   
$" 
zDigestAuthHandler.getN)r   r   r   r   r4   r   r   r   r   r      s    r   c                   @   r	   )CustomReasonHandlerc                 C      |  dd d S )N   Custom reasonr;   r   r   r   r   r4   F      zCustomReasonHandler.getNr   r   r   r4   r   r   r   r   rG   E       rG   c                   @   r	   )CustomFailReasonHandlerc                 C   rH   )Ni  rJ   rK   rL   r   r   r   r4   K   rM   zCustomFailReasonHandler.getNrN   r   r   r   r   rP   J   rO   rP   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )CurlHTTPClientTestCasec                    s   t    |  | _d S r   )supersetUpcreate_clienthttp_clientrL   	__class__r   r   rS   Q   s   
zCurlHTTPClientTestCase.setUpc                 C   s0   t dtdddfdtdddfdtfdtfgS )	N/digestfoobarr   /digest_non_ascii   barユ£/custom_reason/custom_fail_reason)r   r   rG   rP   rL   r   r   r   get_appU   s   zCurlHTTPClientTestCase.get_appc                 K   s   t ddtddd|S )NTFr   )force_instancer   r   )r   r   )r   kwargsr   r   r   rT   c   s
   
z$CurlHTTPClientTestCase.create_clientc                 C   $   | j ddddd}| |jd d S )NrX   rF   rY   rZ   r>   auth_usernameauth_password   okfetchassertEqualbodyr   r/   r   r   r   test_digest_authh   s   z'CurlHTTPClientTestCase.test_digest_authc                 C   s   |  d}| |jd d S )Nr]   rJ   )rh   ri   reasonrk   r   r   r   test_custom_reasonn   s   
z)CurlHTTPClientTestCase.test_custom_reasonc                 C   s    |  d}| t|jd d S )Nr^   zHTTP 400: Custom reason)rh   ri   strerrorrk   r   r   r   test_fail_custom_reasonr   s   
z.CurlHTTPClientTestCase.test_fail_custom_reasonc                 C   rb   )Nr[   rF   rY   r\   rc   rf   rg   rk   r   r   r   test_digest_auth_non_asciiv   s   z1CurlHTTPClientTestCase.test_digest_auth_non_ascii)r   r   r   rS   r_   rT   rl   rn   rq   rr   __classcell__r   r   rV   r   rQ   O   s    rQ   )hashlibr   unittesttornado.escaper   tornado.testingr   tornado.testr   tornado.webr   r   pycurlImportErrortornado.curl_httpclientr   skipIfHTTPClientCommonTestCaser
   r   rG   rP   rQ   r   r   r   r   <module>   s(    )