
    i+                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ ddl	m
Z
 ddlmZmZmZ d dlZddlmZ dd	lmZmZ  G d
 d      Z ej,                  e      Z	  G d de      Zy)    N)Optional)	urlencodequote   )Configuration   )raise_exceptions_or_returnRESTResponseRestClientInterface)JitterRetry)PineconeApiExceptionPineconeApiValueErrorc                   0    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zy
)bcolorsz[95mz[94mz[96mz[92mz[93mz[91mz[0mz[1mz[4mN)__name__
__module____qualname__HEADEROKBLUEOKCYANOKGREENWARNINGFAILENDCBOLD	UNDERLINE     w/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/openapi_support/rest_urllib3.pyr   r      s/    FFFGGDDDIr   r   c            	       b    e Zd ZU ej                  ed<   	 d	dededee   ddfdZ		 	 	 	 	 	 d
dZ
y)Urllib3RestClientpool_managerNconfiguration
pools_sizemaxsizereturnc                    |j                   rt        j                  }nt        j                  }i }|j                  |j                  |d<   |j
                  |j
                  |d<   nt        dddd       |d<   |j                  |j                  |d<   ||j                  |j                  }nd}|j                  rVt        j                  d||||j                  |j                  |j                  |j                  |j                  d	|| _        y t        j"                  d||||j                  |j                  |j                  d
|| _        y )Nassert_hostnameretries   g      ?)i  i  i  i  )totalbackoff_factorstatus_forcelistallowed_methodssocket_options   )	num_poolsr%   	cert_reqsca_certs	cert_filekey_file	proxy_urlproxy_headers)r1   r%   r2   r3   r4   r5   r   )
verify_sslsslCERT_REQUIRED	CERT_NONEr(   r)   r   r/   connection_pool_maxsizeproxyurllib3ProxyManagerssl_ca_certr4   r5   r7   r"   PoolManager)selfr#   r$   r%   r2   addition_pool_argss         r   __init__zUrllib3RestClient.__init__"   sj    ##))II((44A4Q4Q01  ,,9,A,Ay),7#!5 $	-y) ''33@3O3O/0?44@'??  ' 4 4 
!$#&22'11&//'--+99
! %
!D !( 3 3 !$#&22'11&//! %!Dr   c	           
      
   t         j                  d       |j                         }|dv sJ t        j                  j                  d      rdj                  |j                         D 	
cg c]  \  }	}
dj                  |	|
       c}
}	      }t        |      }|r| d| }n|}|@t        t        j                  dj                  |||	      z   t        j                  z          nUt        j                  |      }t        t        j                  d
j                  ||||      z   t        j                  z          |r|rt!        d      |xs i }|xs i }d}|rht#        |t$        t&        f      rt)        j*                  |      }n;t#        |t,              r+t/        |      dk(  rt)        j*                  |d   |d         }	 |dv rP|dk7  r	d|vrd|d<   |r|dt        |t0              z   z  }|j                  dd      j3                         }|dk(  sd|v rZ|d}n3|dk(  rdj                  d |D              }nt        j                  |      }| j4                  j7                  ||||||      }n|dk(  r#| j4                  j7                  |||d|||      }n|d k(  r&|d= | j4                  j7                  |||d!|||      }nt#        |t8              st#        |t:              r$|}| j4                  j7                  ||||||      }nHd"}t=        d|#      |r|dt        |t0              z   z  }| j4                  j7                  |||||$      }t        j                  j                  d      rtG        |jH                  |jJ                  |jL                  |jN                        }|jH                  d&k  rGt        t        jP                  |jJ                  jS                  d'      z   t        j                  z          nFt        t        jT                  |jJ                  jS                  d'      z   t        j                  z          |rVtG        |jH                  |jJ                  |jL                  |jN                        }t         j                  d(|jJ                         tW        |      S c c}
}	w # t(        j>                  j@                  $ r@}d%j                  tC        |      jD                  t9        |            }t=        d|#      d}~ww xY w))a  Perform requests.

        :param method: http request method
        :param url: http request url
        :param query_params: query parameters in the url
        :param headers: http request headers
        :param body: request json body, for `application/json`
        :param post_params: request post parameters,
                            `application/x-www-form-urlencoded`
                            and `multipart/form-data`
        :param _preload_content: if False, the urllib3.HTTPResponse object will
                                 be returned without reading/decoding response
                                 data. Default is True.
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        zCalling urllib3 request())GETHEADDELETEPOSTPUTPATCHOPTIONSPINECONE_DEBUG_CURL z-H '{0}: {1}'?Nz,curl -X {method} '{url}' {formatted_headers})methodurlformatted_headersz8curl -X {method} '{url}' {formatted_headers} -d '{data}')rP   rQ   rR   dataz9body parameter cannot be used with post_params parameter.)r+   r   r   r   )connectread)rI   rJ   rK   rL   rH   rH   zContent-Typezapplication/json)	quote_via jsonzapplication/x-ndjson
c              3   F   K   | ]  }t        j                  |        y w)N)rX   dumps).0elements     r   	<genexpr>z,Urllib3RestClient.request.<locals>.<genexpr>   s     4]WTZZ5H4]s   !)bodypreload_contenttimeoutheadersz!application/x-www-form-urlencodedF)fieldsencode_multipartr`   ra   rb   zmultipart/form-dataTzCannot prepare a request message for provided
                             arguments. Please check that your arguments match
                             declared content type.)statusreason)r`   ra   rb   z{0}
{1}i,  zutf-8zresponse body: %s),loggerdebugupperosenvirongetjoinitemsformatr   printr   r   r   rX   r[   r   
isinstanceintfloatr>   Timeouttuplelenr   lowerr"   requeststrbytesr   
exceptionsSSLErrortyper   r
   re   rS   rb   rf   r   decoder   r	   )rB   rP   rQ   query_paramsrb   r_   post_params_preload_content_request_timeoutkvrR   formatted_queryformatted_urlformatted_bodyra   content_typerequest_bodyrmsgeos                         r   rx   zUrllib3RestClient.request`   s   : 	01UUUU::>>/0 #SZS`S`Sb)c41a/*@*@A*F)c d'5O#&%q(9 : #|NNDKK%=L] L  ll	# "&D!1NNPWW%)*;+	 X  ll#	 4'(cdd!'R-R*S%L9!//0@A,e4=M9NRS9S!//2B12EL\]^L_`Q	=FFh&^7-J.@GN+3<5!IIIC&{{>2>DDF2%&L*@|'+'+AA ,0994]X\4]+]L+/::d+;L))11)(8 ' ' 2 A "%HH))11*).(8 ' ' 2 A "%::  /))11*)-(8 ' ' 2 A  c*ju.E#'L))11)(8 ' ' 2 A7C /aDD  3<5!IIIC%%--C1A7\c .  ::>>/0QXXqvvqyy!((CAxx3goog(>>MNgllQVV]]7%;;gllJKQXXqvvqyy!((CA LL,aff5)!,,S *dn !!** 	=##DG$4$4c!f=C&a<<	=s   )R%
FR+ +T;TT)r0   N)NNNNTN)r   r   r   r>   rA   __annotations__r   rr   r   rD   rx   r   r   r   r!   r!      sZ    %%% [_<*<8;<JRSV-<	<D k-r   r!   )rX   loggingr9   rj   typingr   urllib.parser   r   config.openapi_configurationr   
rest_utilsr	   r
   r   r>   retry_urllib3r   r{   r   r   r   	getLoggerr   rg   r!   r   r   r   <module>r      sY      
 	  ) 8 U U  & C	 	 
		8	$ l-+ l-r   