
    7|hE$                         d Z ddlmZ ddlmZmZmZmZmZm	Z	 ddl
Z
ddlZddlmZmZ ddlmZ  G d de      Z G d	 d
e      Z G d de      Z G d de      ZeZy)z@Lightweight wrapper around requests library, with async support.    )asynccontextmanager)AnyAsyncGeneratorDictLiteralOptionalUnionN)	BaseModel
ConfigDict)Responsec                      e Zd ZU dZdZeeeef      ed<   dZ	ee
j                     ed<   dZee   ed<   dZee   ed<    edd	      Zd
ededej&                  fdZd
edeeef   dedej&                  fdZd
edeeef   dedej&                  fdZd
edeeef   dedej&                  fdZd
ededej&                  fdZeded
ededee
j6                  df   fd       Zed
ededee
j6                  df   fd       Zed
edeeef   dedee
j6                  df   fd       Zed
edeeef   dedee
j6                  df   fd       Zed
edeeef   dedee
j6                  df   fd       Z ed
ededee
j6                  df   fd       Z!y)RequestszWrapper around requests to handle auth and async.

    The main purpose of this wrapper is to handle authentication (by saving
    headers) and enable easy async methods on the same base object.
    Nheaders
aiosessionauthTverifyforbidarbitrary_types_allowedextraurlkwargsreturnc                 r    t        j                  |f| j                  | j                  | j                  d|S ) GET the URL and return the text.r   r   r   )requestsgetr   r   r   selfr   r   s      e/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/utilities/requests.pyr   zRequests.get   s6    ||
DIIdkk
MS
 	
    datac                 t    t        j                  |f|| j                  | j                  | j                  d|S )$POST to the URL and return the text.jsonr   r   r   )r   postr   r   r   r    r   r#   r   s       r!   r(   zRequests.post#   s=    }}
LL;;
 
 	
r"   c                 t    t        j                  |f|| j                  | j                  | j                  d|S )"PATCH the URL and return the text.r&   )r   patchr   r   r   r)   s       r!   r,   zRequests.patch.   s=    ~~
LL;;
 
 	
r"   c                 t    t        j                  |f|| j                  | j                  | j                  d|S ) PUT the URL and return the text.r&   )r   putr   r   r   r)   s       r!   r/   zRequests.put9   s=    ||
LL;;
 
 	
r"   c                 r    t        j                  |f| j                  | j                  | j                  d|S )#DELETE the URL and return the text.r   )r   deleter   r   r   r   s      r!   r2   zRequests.deleteD   s6    
DIIdkk
MS
 	
r"   methodc                N  K   | j                   swt        j                         4 d{   } |j                  ||f| j                  | j
                  d|4 d{   }| ddd      d{    ddd      d{    y | j                   j                  ||f| j                  | j
                  d|4 d{   }| ddd      d{    y7 7 7 m# 1 d{  7  sw Y   }xY w7 t# 1 d{  7  sw Y   yxY w7 L7 9# 1 d{  7  sw Y   yxY ww)zMake an async request.N)r   r   )r   aiohttpClientSessionrequestr   r   )r    r3   r   r   sessionresponses         r!   	_arequestzRequests._arequestJ   s8    
 ,,. # #'*7?? !LL	
  # # "N# ## # # /t.. YY	
      ## # # # ## # # #    s   %D%CD%0C7CC7C %C70C1C75D% C5>D%?D D%D	D%DD%C7C7 C2	&C)'C2	.C75D%7D	=D >D	D%D%D"DD"D%c                   K    | j                   d|fi |4 d{   }| ddd      d{    y7 7 # 1 d{  7  sw Y   yxY ww)/GET the URL and return the text asynchronously.GETNr:   r    r   r   r9   s       r!   agetzRequests.agetc   sS     
 "4>>%77 	 	8N	 	 	 	 	 	 	<   A6A:A8AAA AAAc                   K    | j                   d|fd|i|4 d{   }| ddd      d{    y7 7 # 1 d{  7  sw Y   yxY ww)3POST to the URL and return the text asynchronously.POSTr'   Nr>   r    r   r#   r   r9   s        r!   apostzRequests.apostk   sX     
 "4>>&#CDCFC 	 	xN	 	 	 	 	 	 	<   A8A<A:AAAAA
Ac                   K    | j                   d|fd|i|4 d{   }| ddd      d{    y7 7 # 1 d{  7  sw Y   yxY ww)1PATCH the URL and return the text asynchronously.PATCHr'   Nr>   rE   s        r!   apatchzRequests.apatchs   sX     
 "4>>'3DTDVD 	 	N	 	 	 	 	 	 	rG   c                   K    | j                   d|fd|i|4 d{   }| ddd      d{    y7 7 # 1 d{  7  sw Y   yxY ww)/PUT the URL and return the text asynchronously.PUTr'   Nr>   rE   s        r!   aputzRequests.aput{   sX     
 "4>>%B4B6B 	 	hN	 	 	 	 	 	 	rG   c                   K    | j                   d|fi |4 d{   }| ddd      d{    y7 7 # 1 d{  7  sw Y   yxY ww)2DELETE the URL and return the text asynchronously.DELETENr>   r?   s       r!   adeletezRequests.adelete   sS     
 "4>>(C:6: 	 	hN	 	 	 	 	 	 	rA   )"__name__
__module____qualname____doc__r   r   r   str__annotations__r   r5   r6   r   r   r   boolr   model_configr   r   r   r(   r,   r/   r2   r   r   ClientResponser:   r@   rF   rK   rO   rS    r"   r!   r   r      s    )-GXd38n%,26J../6D(3-!FHTN! $L

s 
c 
h.?.? 
	
 	
4S> 	
S 	
XEVEV 	
	
 	
DcN 	
c 	
hFWFW 	
	
s 	
$sCx. 	
C 	
HDUDU 	

# 
 
1B1B 
  #/2	..4	5 0 "%	..4	5  "38n8;	..4	5  "38n8;	..4	5  "38n8;	..4	5  "%	..4	5 r"   r   c                      e Zd ZU dZdZeeeef      ed<   dZ	ee
j                     ed<   dZee   ed<   dZed   ed<   d	Zeed
<    ed	d      Zedefd       Zdedeeeeef   f   fdZde
j4                  deeeeef   f   fdZdededeeeeef   f   fdZdedeeef   dedeeeeef   f   fdZdedeeef   dedeeeeef   f   fdZdedeeef   dedeeeeef   f   fdZdededeeeeef   f   fdZ dededeeeeef   f   fdZ!dedeeef   dedeeeeef   f   fdZ"dedeeef   dedeeeeef   f   fdZ#dedeeef   dedeeeeef   f   fdZ$dededeeeeef   f   fdZ%y)GenericRequestsWrapperz,Lightweight wrapper around requests library.Nr   r   r   textr`   r'   response_content_typeTr   r   r   r   c                 p    t        | j                  | j                  | j                  | j                        S )N)r   r   r   r   )r   r   r   r   r   )r    s    r!   r   zGenericRequestsWrapper.requests   s+    LL;;	
 	
r"   r9   c                     | j                   dk(  r|j                  S | j                   dk(  r|j                         S t        d| j                          Nr`   r'   zInvalid return type: rb   r`   r'   
ValueErrorr    r9   s     r!   _get_resp_contentz(GenericRequestsWrapper._get_resp_content   sN    %%/== ''61==?"4T5O5O4PQRRr"   c                    K   | j                   dk(  r|j                          d {   S | j                   dk(  r|j                          d {   S t        d| j                          7 C7 wre   rf   rh   s     r!   _aget_resp_contentz)GenericRequestsWrapper._aget_resp_content   se      %%/!((''61!((4T5O5O4PQRR	 )(s!   #A-A)&A-A+A-+A-r   r   c                 Z    | j                   | j                  j                  |fi |      S )r   )ri   r   r   r   s      r!   r   zGenericRequestsWrapper.get   s*    %%&7dmm&7&7&Fv&FGGr"   r#   c                 \    | j                   | j                  j                  ||fi |      S )r%   )ri   r   r(   r)   s       r!   r(   zGenericRequestsWrapper.post   s.     %%&8dmm&8&8d&Mf&MNNr"   c                 \    | j                   | j                  j                  ||fi |      S )r+   )ri   r   r,   r)   s       r!   r,   zGenericRequestsWrapper.patch   s.     %%&9dmm&9&9#t&Nv&NOOr"   c                 \    | j                   | j                  j                  ||fi |      S )r.   )ri   r   r/   r)   s       r!   r/   zGenericRequestsWrapper.put   s.     %%&7dmm&7&7T&LV&LMMr"   c                 Z    | j                   | j                  j                  |fi |      S )r1   )ri   r   r2   r   s      r!   r2   zGenericRequestsWrapper.delete   s*    %%&:dmm&:&:3&I&&IJJr"   c                    K    | j                   j                  |fi |4 d{   }| j                  |       d{   cddd      d{    S 7 .7 7 	# 1 d{  7  sw Y   yxY ww)r<   N)r   r@   rk   r?   s       r!   r@   zGenericRequestsWrapper.aget   se     %4==%%c4V4 	; 	;00::	; 	; 	;:	; 	; 	; 	;T   "A.AA.AAAA.AA.AA.A+A" A+'A.c                    K    | j                   j                  ||fi |4 d{   }| j                  |       d{   cddd      d{    S 7 .7 7 	# 1 d{  7  sw Y   yxY ww)rC   N)r   rF   rk   rE   s        r!   rF   zGenericRequestsWrapper.apost   si      '4==&&sD;F; 	; 	;x00::	; 	; 	;:	; 	; 	; 	;T   #A/AA/AAAA/AA/AA/A, A#!A,(A/c                    K    | j                   j                  ||fi |4 d{   }| j                  |       d{   cddd      d{    S 7 .7 7 	# 1 d{  7  sw Y   yxY ww)rI   N)r   rK   rk   rE   s        r!   rK   zGenericRequestsWrapper.apatch   si      (4==''T<V< 	; 	;00::	; 	; 	;:	; 	; 	; 	;rt   c                    K    | j                   j                  ||fi |4 d{   }| j                  |       d{   cddd      d{    S 7 .7 7 	# 1 d{  7  sw Y   yxY ww)rM   N)r   rO   rk   rE   s        r!   rO   zGenericRequestsWrapper.aput   si      &4==%%c4:6: 	; 	;h00::	; 	; 	;:	; 	; 	; 	;rt   c                    K    | j                   j                  |fi |4 d{   }| j                  |       d{   cddd      d{    S 7 .7 7 	# 1 d{  7  sw Y   yxY ww)rQ   N)r   rS   rk   r?   s       r!   rS   zGenericRequestsWrapper.adelete   se     (4==((77 	; 	;800::	; 	; 	;:	; 	; 	; 	;rr   )&rT   rU   rV   rW   r   r   r   rX   rY   r   r5   r6   r   r   rb   r   r   rZ   r   r[   propertyr   r   r   r	   ri   r\   rk   r   r(   r,   r/   r2   r@   rF   rK   rO   rS   r]   r"   r!   r_   r_      s   6(,GXd38n%,26J../6D(3-5;7>2;FD $L
 
( 
 
S( SuS$sCx.=P7Q SS..S	sDcN"	#SHs Hc HeCc3h4G.H HOO"38nO8;O	sDcN"	#OPP"38nP8;P	sDcN"	#PNN"38nN8;N	sDcN"	#NK# K KsDcN7J1K K;c ;S ;U3S#X;N5O ;
;;"38n;8;;	sDcN"	#;;;"38n;8;;	sDcN"	#;;;"38n;8;;	sDcN"	#;; ; ;c4S>>Q8R ;r"   r_   c                   &    e Zd ZU dZdZed   ed<   y)JsonRequestsWrapperzLightweight wrapper around requests library, with async support.

    The main purpose of this wrapper is to always return a json output.r'   ra   rb   NrT   rU   rV   rW   rb   r   rY   r]   r"   r!   rz   rz          K 6<7>2;r"   rz   c                   &    e Zd ZU dZdZed   ed<   y)TextRequestsWrapperzLightweight wrapper around requests library, with async support.

    The main purpose of this wrapper is to always return a text output.r`   ra   rb   Nr{   r]   r"   r!   r~   r~      r|   r"   r~   )rW   
contextlibr   typingr   r   r   r   r   r	   r5   r   pydanticr
   r   r   r   r_   rz   r~   RequestsWrapperr]   r"   r!   <module>r      s\    F * F F   * }y }@`;Y `;F<0 <<0 < &r"   