o
    Ëý°jYA  ã                   @   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)Ússhr"   r"   ÚSECURE_ORIGINS)ÚBUILD_BUILDIDÚBUILD_IDÚCIÚ	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© r1   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_internal/network/session.pyÚ	<genexpr>X   s   € z looks_like_ci.<locals>.<genexpr>)ÚanyÚCI_ENVIRONMENT_VARIABLESr1   r1   r1   r2   Úlooks_like_ciQ   s   r6   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)r0   Úversionr0   )Ú	installerÚpythonÚimplementationr;   ÚCPythonr8   ÚPyPyÚfinalNé   Ú.c                 S   s   g | ]}t |ƒ‘qS r1   )Ústr)r/   Úxr1   r1   r2   Ú
<listcomp>n   s    zuser_agent.<locals>.<listcomp>ÚJythonÚ
IronPythonÚlinuxr   )Údistroc                 S   ó   | d S ©Né   r1   ©rB   r1   r1   r2   Ú<lambda>}   ó    zuser_agent.<locals>.<lambda>)r0   r8   Úidc                 S   rH   rI   r1   rK   r1   r1   r2   rL   ƒ   rM   ÚlibÚlibcrG   ÚdarwinÚmacOSÚsystemÚreleaseÚcpuÚopenssl_versionÚ
setuptoolsÚsetuptools_versionÚrustcz	--versiong      à?)ÚstderrÚtimeouts   rustc ó    rJ   Úrustc_versionTÚciÚ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._vendorrG   r0   r8   ÚcodenameÚdictÚfilterÚzipr   Úmac_verrS   Ú
setdefaultrT   Úmachiner   Ú_sslÚOPENSSL_VERSIONr   Úget_distributionrA   ÚshutilÚwhichÚ
subprocessÚcheck_outputÚSTDOUTÚ	ExceptionÚsplitÚdecoder6   r-   r.   ÚgetÚformatrf   Údumps)
re   rk   rG   Úlinux_distributionÚdistro_infosrP   ÚsslÚsetuptools_distÚrustc_outputr`   r1   r1   r2   Ú
user_agent[   sŠ   ÿý
ÿþÿþÿ


ÿÿ
þrŠ   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Ústreamr[   Ú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�   r[   rŽ   r�   r�   ÚpathnameÚrespÚstatsÚexcÚmodifiedÚcontent_typer1   r1   r2   ÚsendÁ   s0   
	(€ìýÿ
zLocalFSAdapter.sendc                 C   s   d S r,   r1   )rª   r1   r1   r2   r©   è   s   zLocalFSAdapter.close)FNTNN)r+   N)rš   Ú
__module__Ú__qualname__r   Úboolr   r
   Úfloatr	   rA   r   r   r±   r©   r1   r1   r1   r2   r‹   À   s,    ùþýü
ûúù
ø'r‹   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__r1   r2   r½   í   ó   zInsecureHTTPAdapter.cert_verify©rš   r²   r³   r   rA   r
   r´   r   r	   r½   Ú__classcell__r1   r1   r¿   r2   r·   ì   ó    þý
üûúr·   c                       r¶   )	ÚInsecureCacheControlAdapterr¸   r•   rŽ   r�   r+   Nc                    r¹   rº   r»   r¾   r¿   r1   r2   r½   ø   rÁ   z'InsecureCacheControlAdapter.cert_verifyrÂ   r1   r1   r¿   r2   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 )"Ú
PipSessionNr[   r   r1   )Ú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_originsrŠ   r§   r   Úauthr   ÚRetryr·   r   r   rÅ   Ú_trusted_host_adapterr   Úmountr‹   Úadd_trusted_host)
rª   rÇ   rÈ   rÉ   rÊ   rË   rÌ   Úinsecure_adapterÚsecure_adapterÚhostr¿   r1   r2   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Ü   r1   r1   r2   Ú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ú/rJ   rb   )ÚloggerÚinfor   rÓ   Úappendr×   r   rÖ   )rª   rÛ   rÞ   rÑ   ÚmsgÚ	host_portr1   r1   r2   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Û   Úportr1   r1   r2   Ú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ú+rJ   éÿÿÿÿ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ÚurlparserA   rá   Úhostnamerè   Úrsplitré   Ú	ipaddressÚ
ip_addressÚ
ip_networkÚ
ValueErrorÚlowerrã   Úwarning)rª   rê   ÚparsedÚorigin_protocolÚorigin_hostÚorigin_portÚsecure_originÚsecure_protocolÚsecure_hostÚsecure_portÚaddrÚnetworkr1   r1   r2   Úis_secure_origin~  sD   
ý


ÿ€øú	zPipSession.is_secure_originÚmethodr•   c                    s*   |  d| j¡ tƒ j||g|¢R i |¤ŽS )Nr[   )ru   r[   r¼   rŒ   )rª   r  r•   rË   rÌ   r¿   r1   r2   rŒ   Á  s   zPipSession.request)NF)rš   r²   r³   r[   r   ÚintÚ__annotations__r   rA   r   r   rÒ   rÝ   r´   rØ   r   ÚSecureOriginré   r   r  r   rŒ   rÃ   r1   r1   r¿   r2   rÆ     sF   
 úþýüû
úùøMÿÿÿÿ
þ*CrÆ   )PÚ__doc__Úemail.utilsr    rœ   rò   rf   Úloggingr¤   r-   rg   rz   r|   rj   Úurllib.parserí   ÚwarningsÚtypingr   r   r   r   r   r   r   r	   r
   ro   r   r   Úpip._vendor.cachecontrolr   Úpip._vendor.requests.adaptersr   r   Úpip._vendor.requests.modelsr   r   Úpip._vendor.requests.structuresr   Ú"pip._vendor.urllib3.connectionpoolr   Úpip._vendor.urllib3.exceptionsr   r7   r   Úpip._internal.metadatar   Úpip._internal.models.linkr   Úpip._internal.network.authr   Úpip._internal.network.cacher   Úpip._internal.utils.compatr   Úpip._internal.utils.glibcr   Úpip._internal.utils.miscr   r   Úpip._internal.utils.urlsr   Ú	getLoggerrš   rã   rA   r  r  Úfilterwarningsr&   r  r5   r´   r6   rŠ   r‹   r·   rÅ   ÚSessionrÆ   r1   r1   r1   r2   Ú<module>   sT    ,

e,