
    g                     b   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 	 d dlZed dlmZ  ej                   edu d       G d	 d
ej"                               Z G d de      Z G d de      Z G d de      Z ej                   edu d       G d de             Zy# e$ r dZY w xY w)    )md5N)utf8)AsyncHTTPTestCase)httpclient_test)ApplicationRequestHandler)CurlAsyncHTTPClientzpycurl module not presentc                       e Zd Zd Zy)CurlHTTPClientCommonTestCasec                 p    t        t        d            }| j                  t        |t                      |S )NF
allow_ipv6)defaults)r	   dict
assertTrue
isinstance)selfclients     V/var/www/openai/venv/lib/python3.12/site-packages/tornado/test/curl_httpclient_test.pyget_http_clientz,CurlHTTPClientCommonTestCase.get_http_client   s*    $de.DE
6+>?@    N)__name__
__module____qualname__r    r   r   r   r      s    r   r   c                       e Zd Zd Zd Zy)DigestAuthHandlerc                      || _         || _        y Nusernamepassword)r   r!   r"   s      r   
initializezDigestAuthHandler.initialize   s      r   c           
         d}d}d}| j                   j                  j                  dd       }||j                  dd      \  }}|dk(  sJ i }|j                  d      D ]?  }|j	                         j                  d	d      \  }	}
|
d
   dk(  r|
d   dk(  r|
dd }
|
||	<   A |d   |k(  sJ |d   |k(  sJ |d   |k(  sJ |d   | j
                  k(  sJ |d   | j                   j                  k(  sJ t        t        | j
                  d|d| j                              j                         }t        t        | j                   j                  d| j                   j                              j                         }t        t        |d|d|            j                         }||d   k(  r| j                  d       y | j                  d       y | j                  d       | j                  dd|d|d|d       y )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   r0   r1   r2   auth_header	auth_modeparams
param_dictpairkvh1h2digests                 r   r:   zDigestAuthHandler.get!   s   ll**..E" + 1 1#q 9Iv(((JS)zz|))#q11Q43;1R5C<!BA !
1	 *
 g&%///h'6111g&%///j)T]]:::e$(9(99994==%GHik   3 3T\\5F5FGHik  Br:;<FFHFJ//

4 

6"OOC OO"@EufUr   N)r   r   r   r#   r:   r   r   r   r   r      s    !%r   r   c                       e Zd Zd Zy)CustomReasonHandlerc                 (    | j                  dd       y )N   Custom reasonrA   r   s    r   r:   zCustomReasonHandler.getJ       _-r   Nr   r   r   r:   r   r   r   rN   rN   I       .r   rN   c                       e Zd Zd Zy)CustomFailReasonHandlerc                 (    | j                  dd       y )Ni  rQ   rR   rS   s    r   r:   zCustomFailReasonHandler.getO   rT   r   NrU   r   r   r   rX   rX   N   rV   r   rX   c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )CurlHTTPClientTestCasec                 L    t         |           | j                         | _        y r   )supersetUpcreate_clienthttp_client)r   	__class__s    r   r^   zCurlHTTPClientTestCase.setUpU   s    --/r   c                 `    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   rN   rX   rS   s    r   get_appzCurlHTTPClientTestCase.get_appY   sK    -Eu/UV'%!&J?
 "#67&(?@	
 	
r   c                 2    t        ddt        d      d|S )NTFr   )force_instancer   r   )r	   r   )r   kwargss     r   r_   z$CurlHTTPClientTestCase.create_clientg   s&    " 
$%*@
DJ
 	
r   c                 f    | j                  dddd      }| j                  |j                  d       y )Nrc   rL   rd   re   rD   auth_usernameauth_password   okfetchassertEqualbodyr   r5   s     r   test_digest_authz'CurlHTTPClientTestCase.test_digest_authl   s4    ::e  
 	.r   c                 ^    | j                  d      }| j                  |j                  d       y )Nrh   rQ   )rt   ru   reasonrw   s     r   test_custom_reasonz)CurlHTTPClientTestCase.test_custom_reasonr   s%    ::.//:r   c                 p    | j                  d      }| j                  t        |j                        d       y )Nri   zHTTP 400: Custom reason)rt   ru   strerrorrw   s     r   test_fail_custom_reasonz.CurlHTTPClientTestCase.test_fail_custom_reasonv   s+    ::34X^^,.GHr   c                 f    | j                  dddd      }| j                  |j                  d       y )Nrf   rL   rd   rg   ro   rr   rs   rw   s     r   test_digest_auth_non_asciiz1CurlHTTPClientTestCase.test_digest_auth_non_asciiz   s7    ::$	  
 	.r   )r   r   r   r^   rj   r_   rx   r{   r   r   __classcell__)ra   s   @r   r[   r[   S   s'    0


/;I/r   r[   )hashlibr   unittesttornado.escaper   tornado.testingr   tornado.testr   tornado.webr   r   pycurlImportErrortornado.curl_httpclientr	   skipIfHTTPClientCommonTestCaser   r   rN   rX   r[   r   r   r   <module>r      s       - ( 3 
; 4!<=?#K#K  >* *Z.. .
.n .
 4!<=-/. -/ >-/Q  Fs   B$ $B.-B.