o
    h                     @   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   U/var/www/vscode/kcb/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d| j|| j	f 
 }ttd| j j| j jf 
 }ttd|||f 
 }||d kr| d d S | d d S | d | dd|||f  d S )Ntestasdf1234Authorization    Digest,=r   "realmopaquenoncer   uriz%s:%s:%sz%s:%sresponseokfaili  zWWW-Authenticatez*Digest realm="%s", nonce="%s", opaque="%s")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   r3   !   sJ   

zDigestAuthHandler.getN)r   r   r   r   r3   r   r   r   r   r      s    r   c                   @   r	   )CustomReasonHandlerc                 C      |  dd d S )N   Custom reasonr:   r   r   r   r   r3   J      zCustomReasonHandler.getNr   r   r   r3   r   r   r   r   rF   I       rF   c                   @   r	   )CustomFailReasonHandlerc                 C   rG   )Ni  rI   rJ   rK   r   r   r   r3   O   rL   zCustomFailReasonHandler.getNrM   r   r   r   r   rO   N   rN   rO   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_clientrK   	__class__r   r   rR   U   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   rF   rO   rK   r   r   r   get_appY   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   rS   g   s
   
z$CurlHTTPClientTestCase.create_clientc                 C   $   | j ddddd}| |jd d S )NrW   rE   rX   rY   r=   auth_usernameauth_password   okfetchassertEqualbodyr   r.   r   r   r   test_digest_authl   s   z'CurlHTTPClientTestCase.test_digest_authc                 C   s   |  d}| |jd d S )Nr\   rI   )rg   rh   reasonrj   r   r   r   test_custom_reasonr   s   
z)CurlHTTPClientTestCase.test_custom_reasonc                 C   s    |  d}| t|jd d S )Nr]   zHTTP 400: Custom reason)rg   rh   strerrorrj   r   r   r   test_fail_custom_reasonv   s   
z.CurlHTTPClientTestCase.test_fail_custom_reasonc                 C   ra   )NrZ   rE   rX   r[   rb   re   rf   rj   r   r   r   test_digest_auth_non_asciiz   s   z1CurlHTTPClientTestCase.test_digest_auth_non_ascii)r   r   r   rR   r^   rS   rk   rm   rp   rq   __classcell__r   r   rU   r   rP   S   s    rP   )hashlibr   unittesttornado.escaper   tornado.testingr   tornado.testr   tornado.webr   r   pycurlImportErrortornado.curl_httpclientr   skipIfHTTPClientCommonTestCaser
   r   rF   rO   rP   r   r   r   r   <module>   s(    -