
    NgE$                         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dS )z@Lightweight wrapper around requests library, with async support.    )asynccontextmanager)AnyAsyncGeneratorDictLiteralOptionalUnionN)	BaseModel
ConfigDict)Responsec                   6   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
j        df         fd            Zed
ededee
j        df         fd            Zed
edeeef         dedee
j        df         fd            Zed
edeeef         dedee
j        df         fd            Zed
edeeef         dedee
j        df         fd            Z ed
ededee
j        df         fd            Z!dS )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                 L    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      b/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/requests.pyr   zRequests.get   s8    |
DIdk
 
MS
 
 	
    datac                 N    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?    }
L;
 
 
 
 	
r"   c                 N    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?    ~
L;
 
 
 
 	
r"   c                 N    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?    |
L;
 
 
 
 	
r"   c                 L    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   s8    
DIdk
 
MS
 
 	
r"   methodc                  K   | j         st          j                    4 d{V } |j        ||f| j        | j        d|4 d{V 	 }|W V  ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  dS # 1 d{V swxY w Y   dS  | j         j        ||f| j        | j        d|4 d{V 	 }|W V  ddd          d{V  dS # 1 d{V swxY w Y   dS )zMake an async request.N)r   r   )r   aiohttpClientSessionrequestr   r   )r    r3   r   r   sessionresponses         r!   	_arequestzRequests._arequestJ   s     
  	,.. # # # # # # #'*7? !L	 
   # # # # # # # # "NNNN# # # # # # # # # # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # /t. Y	 
                                        sG   #BAB
A)	)B,A)	-B
BB>C
C!$C!c                   K    | j         d|fi |4 d{V }|W V  ddd          d{V  dS # 1 d{V swxY w Y   dS )/GET the URL and return the text asynchronously.GETNr:   r    r   r   r9   s       r!   agetzRequests.agetc   s      
 "4>%7777 	 	 	 	 	 	 	8NNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   1
;;c                   K    | j         d|fd|i|4 d{V }|W V  ddd          d{V  dS # 1 d{V swxY w Y   dS )3POST to the URL and return the text asynchronously.POSTr'   Nr>   r    r   r#   r   r9   s        r!   apostzRequests.apostk   s      
 "4>&#CCDCFCC 	 	 	 	 	 	 	xNNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   3
= =c                   K    | j         d|fd|i|4 d{V }|W V  ddd          d{V  dS # 1 d{V swxY w Y   dS )1PATCH the URL and return the text asynchronously.PATCHr'   Nr>   rE   s        r!   apatchzRequests.apatchs   s      
 "4>'3DDTDVDD 	 	 	 	 	 	 	NNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rG   c                   K    | j         d|fd|i|4 d{V }|W V  ddd          d{V  dS # 1 d{V swxY w Y   dS )/PUT the URL and return the text asynchronously.PUTr'   Nr>   rE   s        r!   aputzRequests.aput{   s      
 "4>%BB4B6BB 	 	 	 	 	 	 	hNNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rG   c                   K    | j         d|fi |4 d{V }|W V  ddd          d{V  dS # 1 d{V swxY w Y   dS )2DELETE the URL and return the text asynchronously.DELETENr>   r?   s       r!   adeletezRequests.adelete   s      
 "4>(C::6:: 	 	 	 	 	 	 	hNNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	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66D(3-!FHTN!!!: $  L

s 
c 
h.? 
 
 
 
	
 	
4S> 	
S 	
XEV 	
 	
 	
 	
	
 	
DcN 	
c 	
hFW 	
 	
 	
 	
	
s 	
$sCx. 	
C 	
HDU 	
 	
 	
 	

# 
 
1B 
 
 
 
  #/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
j        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%dS )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-    L;	
 
 
 	
r"   r9   c                     | j         dk    r|j        S | j         dk    r|                                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1==??"QT5OQQRRRr"   c                    K   | j         dk    r|                                 d {V S | j         dk    r|                                 d {V S t          d| j                    re   rf   rh   s     r!   _aget_resp_contentz)GenericRequestsWrapper._aget_resp_content   s~       %//!((((((('611!(((((((QT5OQQRRRr"   r   r   c                 N    |                       | j        j        |fi |          S )r   )ri   r   r   r   s      r!   r   zGenericRequestsWrapper.get   s.    %%&7dm&7&F&Fv&F&FGGGr"   r#   c                 P    |                       | j        j        ||fi |          S )r%   )ri   r   r(   r)   s       r!   r(   zGenericRequestsWrapper.post   s2     %%&8dm&8d&M&Mf&M&MNNNr"   c                 P    |                       | j        j        ||fi |          S )r+   )ri   r   r,   r)   s       r!   r,   zGenericRequestsWrapper.patch   s2     %%&9dm&9#t&N&Nv&N&NOOOr"   c                 P    |                       | j        j        ||fi |          S )r.   )ri   r   r/   r)   s       r!   r/   zGenericRequestsWrapper.put   s2     %%&7dm&7T&L&LV&L&LMMMr"   c                 N    |                       | j        j        |fi |          S )r1   )ri   r   r2   r   s      r!   r2   zGenericRequestsWrapper.delete   s.    %%&:dm&:3&I&I&&I&IJJJr"   c                    K    | j         j        |fi |4 d{V }|                     |           d{V cddd          d{V  S # 1 d{V swxY w Y   dS )r<   N)r   r@   rk   r?   s       r!   r@   zGenericRequestsWrapper.aget   s     %4=%c44V44 	; 	; 	; 	; 	; 	; 	;00::::::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;   A


AAc                    K    | j         j        ||fi |4 d{V }|                     |           d{V cddd          d{V  S # 1 d{V swxY w Y   dS )rC   N)r   rF   rk   rE   s        r!   rF   zGenericRequestsWrapper.apost   s      '4=&sD;;F;; 	; 	; 	; 	; 	; 	; 	;x00::::::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;   A
AAc                    K    | j         j        ||fi |4 d{V }|                     |           d{V cddd          d{V  S # 1 d{V swxY w Y   dS )rI   N)r   rK   rk   rE   s        r!   rK   zGenericRequestsWrapper.apatch   s      (4='T<<V<< 	; 	; 	; 	; 	; 	; 	;00::::::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;rt   c                    K    | j         j        ||fi |4 d{V }|                     |           d{V cddd          d{V  S # 1 d{V swxY w Y   dS )rM   N)r   rO   rk   rE   s        r!   rO   zGenericRequestsWrapper.aput   s      &4=%c4::6:: 	; 	; 	; 	; 	; 	; 	;h00::::::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;rt   c                    K    | j         j        |fi |4 d{V }|                     |           d{V cddd          d{V  S # 1 d{V swxY w Y   dS )rQ   N)r   rS   rk   r?   s       r!   rS   zGenericRequestsWrapper.adelete   s     (4=(77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6(,GXd38n%,,,26J./666D(3-5;7>2;;;FD: $  L
 
( 
 
 
 X
S( SuS$sCx.=P7Q S S S SS.S	sDcN"	#S S S SHs Hc HeCc3h4G.H H H H HOO"38nO8;O	sDcN"	#O O O OPP"38nP8;P	sDcN"	#P P P PNN"38nN8;N	sDcN"	#N N N NK# K KsDcN7J1K K K K 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<   dS )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      6         K K 6<7>2;;;;;r"   rz   c                   .    e Zd ZU dZdZed         ed<   dS )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      sP   F F * * * * * * F F F F F F F F F F F F F F F F   * * * * * * * *      } } } } }y } } }@`; `; `; `; `;Y `; `; `;F< < < < <0 < < << < < < <0 < < < &r"   