o
    f}”eYA  ã                   @   s  U d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZ ddlm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z& dd	l'm(Z( dd
l)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= e >e?¡Z@eeAeAeeeBeAf  f ZCejDde*d� g d¢ZEeeC eFd< dZGdeHfdd„ZIdeAfdd„ZJG dd„ de ƒZKG d d!„ d!e!ƒZLG d"d#„ d#eƒZMG d$d%„ d%ejNƒZOdS )&zhPipSession and supporting code, containing all pip-specific
network request configuration and behavior.
é    N)	ÚAnyÚDictÚIteratorÚListÚMappingÚOptionalÚSequenceÚTupleÚUnion)ÚrequestsÚurllib3)ÚCacheControlAdapter)ÚBaseAdapterÚHTTPAdapter)ÚPreparedRequestÚResponse)ÚCaseInsensitiveDict)ÚConnectionPool)ÚInsecureRequestWarning)Ú__version__)Úget_default_environment)ÚLink)ÚMultiDomainBasicAuth)ÚSafeFileCache)Úhas_tls)Úlibc_ver)Úbuild_url_from_netlocÚparse_netloc)Úurl_to_pathÚignore)Úcategory))ÚhttpsÚ*r"   )r"   Ú	localhostr"   )r"   z127.0.0.0/8r"   )r"   z::1/128r"   )Úfiler"   N)Zsshr"   r"   ÚSECURE_ORIGINS)ZBUILD_BUILDIDZBUILD_IDZCIZ	PIP_IS_CIÚreturnc                   C   s   t dd„ tD ƒƒS )z?
    Return whether it looks like pip is running under CI.
    c                 s   s   � | ]}|t jv V  qd S ©N)ÚosÚenviron)Ú.0Úname© r,   úf/Users/abhinavbhinder/Documents/map/venv/lib/python3.10/site-packages/pip/_internal/network/session.pyÚ	<genexpr>X   s   € z looks_like_ci.<locals>.<genexpr>)ÚanyÚCI_ENVIRONMENT_VARIABLESr,   r,   r,   r-   Úlooks_like_ciQ   s   r1   c            
      C   s°  dt dœt ¡ dt ¡ idœ} | d d dkr t ¡ | d d< nF| d d dkrEtj}|jd	kr6|d
d… }d dd„ |D ƒ¡| d d< n!| d d dkrVt ¡ | d d< n| d d dkrft ¡ | d d< tj d¡r¦ddl	m
} | ¡ | ¡ | ¡ f}ttdd„ tg d¢|ƒƒƒ}ttdd„ tddgtƒ ƒƒƒ}|r ||d< |r¦|| d< tj d¡r½t ¡ d r½dt ¡ d dœ| d< t ¡ rËt ¡ |  di ¡d< t ¡ rÙt ¡ |  di ¡d< t ¡ rãt ¡ | d< tƒ rïdd
l}|j| d < tƒ  d!¡}|d
u�rt|jƒ| d"< t d#¡d
u�r2ztj d#d$gtj!d%d&�}W n
 t"�y    Y nw | d'¡�r2| #d(¡d)  $¡ | d*< t%ƒ �r8d+nd
| d,< t&j' (d-¡}	|	d
u�rK|	| d.< d/j)| t*j+| d0d+d1�d2�S )3z6
    Return a string representing the user agent.
    Úpip)r+   Úversionr+   )Ú	installerÚpythonÚimplementationr6   ÚCPythonr3   ÚPyPyÚfinalNé   Ú.c                 S   s   g | ]}t |ƒ‘qS r,   )Ústr)r*   Úxr,   r,   r-   Ú
<listcomp>n   s    zuser_agent.<locals>.<listcomp>ÚJythonÚ
IronPythonÚlinuxr   )Údistroc                 S   ó   | d S ©Né   r,   ©r=   r,   r,   r-   Ú<lambda>}   ó    zuser_agent.<locals>.<lambda>)r+   r3   Úidc                 S   rC   rD   r,   rF   r,   r,   r-   rG   ƒ   rH   ÚlibÚlibcrB   ÚdarwinÚmacOSÚsystemÚreleaseZcpuZopenssl_versionÚ
setuptoolsZsetuptools_versionZrustcz	--versiong      à?)ÚstderrÚtimeouts   rustc ó    rE   Zrustc_versionTZciZPIP_USER_AGENT_USER_DATAÚ	user_dataz9{data[installer][name]}/{data[installer][version]} {json})ú,ú:)Ú
separatorsÚ	sort_keys)ÚdataÚjson),r   ÚplatformÚpython_versionÚpython_implementationÚsysÚpypy_version_infoÚreleaselevelÚjoinÚ
startswithÚpip._vendorrB   r+   r3   ZcodenameÚdictÚfilterÚzipr   Úmac_verrN   Ú
setdefaultrO   Úmachiner   Ú_sslÚOPENSSL_VERSIONr   Úget_distributionr<   ÚshutilÚwhichÚ
subprocessÚcheck_outputÚSTDOUTÚ	ExceptionÚsplitÚdecoder1   r(   r)   ÚgetÚformatrZ   Údumps)
rY   r_   rB   Zlinux_distributionZdistro_infosrK   ÚsslZsetuptools_distZrustc_outputrT   r,   r,   r-   Ú
user_agent[   sŠ   ÿý
ÿþÿþÿ


ÿÿ
þry   c                   @   s„   e Zd Z					ddededeeeeeef f  deee	f deee	ee	e	f f  d	ee
e	e	f  d
efdd„Zddd„ZdS )ÚLocalFSAdapterFNTÚrequestÚstreamrR   ÚverifyÚcertÚproxiesr&   c              
   C   sÖ   t |jƒ}tƒ }d|_|j|_zt |¡}	W n+ tyA }
 zd|_t|
ƒj|_	t
 |j	› d|
› � d¡¡|_W Y d }
~
|S d }
~
ww tjj|	jdd�}t |¡d pSd}t||	j|d	œƒ|_t|d
ƒ|_|jj|_|S )NéÈ   i”  z: Úutf8T)Úusegmtr   z
text/plain)zContent-TypezContent-LengthzLast-ModifiedÚrb)r   Úurlr   Ústatus_coder(   ÚstatÚOSErrorÚtypeÚ__name__ÚreasonÚioÚBytesIOÚencodeÚrawÚemailÚutilsÚ
formatdateÚst_mtimeÚ	mimetypesÚ
guess_typer   Úst_sizeÚheadersÚopenÚclose)Úselfr{   r|   rR   r}   r~   r   ÚpathnameÚrespÚstatsÚexcÚmodifiedÚcontent_typer,   r,   r-   ÚsendÁ   s0   
	(€ìýÿ
zLocalFSAdapter.sendc                 C   s   d S r'   r,   )r™   r,   r,   r-   r˜   è   s   zLocalFSAdapter.close)FNTNN)r&   N)r‰   Ú
__module__Ú__qualname__r   Úboolr   r
   Úfloatr	   r<   r   r   r    r˜   r,   r,   r,   r-   rz   À   s,    ùþýü
ûúù
ø'rz   c                       óN   e Zd Zdededeeef deeeeeef f  ddf
‡ fdd„Z	‡  Z
S )	ÚInsecureHTTPAdapterÚconnr„   r}   r~   r&   Nc                    ó   t ƒ j||d|d� d S ©NF)r§   r„   r}   r~   ©ÚsuperÚcert_verify©r™   r§   r„   r}   r~   ©Ú	__class__r,   r-   r¬   í   ó   zInsecureHTTPAdapter.cert_verify©r‰   r¡   r¢   r   r<   r
   r£   r   r	   r¬   Ú__classcell__r,   r,   r®   r-   r¦   ì   ó    þý
üûúr¦   c                       r¥   )	ÚInsecureCacheControlAdapterr§   r„   r}   r~   r&   Nc                    r¨   r©   rª   r­   r®   r,   r-   r¬   ø   r°   z'InsecureCacheControlAdapter.cert_verifyr±   r,   r,   r®   r-   r´   ÷   r³   r´   c                       sæ   e Zd ZU dZee ed< dddddœdededee d	e	e d
ee
e  deddf‡ fdd„Zde
e ddfdd„Z	d!dedee deddfdd„Zdee fdd„Zdedefdd„Zdededededef
‡ fdd „Z‡  ZS )"Ú
PipSessionNrR   r   r,   )ÚretriesÚcacheÚtrusted_hostsÚ
index_urlsÚargsr¶   r·   r¸   r¹   Úkwargsr&   c          
         sÈ   t ƒ j|i |¤Ž g | _tƒ | jd< t|d�| _tj|g d¢dd�}t	|d�}|r;t
t|ƒ|d�}tt|ƒ|d�| _nt|d�}|| _|  d|¡ |  d	|¡ |  d
tƒ ¡ |D ]	}	| j|	dd� qXdS )zj
        :param trusted_hosts: Domains not to emit warnings for when not using
            HTTPS.
        z
User-Agent)r¹   )iô  i÷  i  i  g      Ð?)ÚtotalÚstatus_forcelistÚbackoff_factor)Úmax_retries)r·   r¿   zhttps://zhttp://zfile://T)Úsuppress_loggingN)r«   Ú__init__Úpip_trusted_originsry   r–   r   Úauthr   ÚRetryr¦   r   r   r´   Ú_trusted_host_adapterr   Úmountrz   Úadd_trusted_host)
r™   r¶   r·   r¸   r¹   rº   r»   Zinsecure_adapterZsecure_adapterÚhostr®   r,   r-   rÁ     s6   ó
þ
þ
ÿzPipSession.__init__Únew_index_urlsc                 C   s   || j _dS )zn
        :param new_index_urls: New index urls to update the authentication
            handler with.
        N)rÃ   r¹   )r™   rÉ   r,   r,   r-   Úupdate_index_urlsS  s   zPipSession.update_index_urlsFrÈ   ÚsourcerÀ   c                 C   s¾   |sd|›�}|dur|d|› d�7 }t  |¡ t|ƒ}|| jvr'| j |¡ |  t|dd�d | j¡ |  t|ƒd | j¡ |d s]|  t|dd�d	 | j¡ |  t|ƒd	 | j¡ dS dS )
zÒ
        :param host: It is okay to provide a host that has previously been
            added.
        :param source: An optional source string, for logging where the host
            string came from.
        zadding trusted host: Nz (from ú)Úhttp)Úschemeú/rE   rV   )ÚloggerÚinfor   rÂ   ÚappendrÆ   r   rÅ   )r™   rÈ   rË   rÀ   ÚmsgÚ	host_portr,   r,   r-   rÇ   Z  s&   	


ÿþúzPipSession.add_trusted_hostc                 c   s8   � t E d H  | jD ]\}}d||d u rdn|fV  q	d S )Nr"   )r%   rÂ   )r™   rÈ   Úportr,   r,   r-   Úiter_secure_originsy  s
   €
ÿzPipSession.iter_secure_originsÚlocationc              	   C   sæ   t j t|ƒ¡}|j|j|j}}}| dd¡d }|  ¡ D ]J}|\}}}	||kr/|dkr/qzt	 
|¡}
t	 |¡}W n tyT   |rR| ¡ | ¡ krR|dkrRY qY nw |
|vrZq||	krg|	dkrg|	d urgq dS t d||¡ dS )Nú+rE   éÿÿÿÿr"   TzõThe repository located at %s is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host %s'.F)ÚurllibÚparseÚurlparser<   rÎ   ÚhostnamerÕ   ÚrsplitrÖ   Ú	ipaddressÚ
ip_addressÚ
ip_networkÚ
ValueErrorÚlowerrÐ   Úwarning)r™   r×   ÚparsedZorigin_protocolZorigin_hostZorigin_portZsecure_originZsecure_protocolZsecure_hostZsecure_portÚaddrÚnetworkr,   r,   r-   Úis_secure_origin~  sN   
ý


ÿþý€øÿþýú	zPipSession.is_secure_originÚmethodr„   c                    s*   |  d| j¡ tƒ j||g|¢R i |¤ŽS )NrR   )rh   rR   r«   r{   )r™   ré   r„   rº   r»   r®   r,   r-   r{   Á  s   zPipSession.request)NF)r‰   r¡   r¢   rR   r   ÚintÚ__annotations__r   r<   r   r   rÁ   rÊ   r£   rÇ   r   ÚSecureOriginrÖ   r   rè   r   r{   r²   r,   r,   r®   r-   rµ     sF   
 úþýüû
úùøMÿÿÿÿ
þ*Crµ   )PÚ__doc__Úemail.utilsr�   r‹   rß   rZ   Úloggingr“   r(   r[   rm   ro   r^   Úurllib.parserÚ   ÚwarningsÚtypingr   r   r   r   r   r   r   r	   r
   rc   r   r   Zpip._vendor.cachecontrolr   Zpip._vendor.requests.adaptersr   r   Zpip._vendor.requests.modelsr   r   Zpip._vendor.requests.structuresr   Z"pip._vendor.urllib3.connectionpoolr   Zpip._vendor.urllib3.exceptionsr   r2   r   Úpip._internal.metadatar   Úpip._internal.models.linkr   Zpip._internal.network.authr   Zpip._internal.network.cacher   Úpip._internal.utils.compatr   Zpip._internal.utils.glibcr   Úpip._internal.utils.miscr   r   Úpip._internal.utils.urlsr   Ú	getLoggerr‰   rÐ   r<   rê   rì   Úfilterwarningsr%   rë   r0   r£   r1   ry   rz   r¦   r´   ÚSessionrµ   r,   r,   r,   r-   Ú<module>   sT    ,

e,