o
    ­—ŽjÔM  ã                   @  sŠ  U d Z ddlm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ZddlmZmZ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!m"Z" dd	l 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l0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZBmCZCmDZD ddlEmFZF erßddlGmHZH ddlImJZJ e	 KeL¡ZMeNeOeOePeOB dB f ZQejRde-d� g d¢ZSdeTd< ejUd d!�d4d$d%„ƒZVG d&d'„ d'e"ƒZWG d(d)„ d)ƒZXG d*d+„ d+eXe$ƒZ#G d,d-„ d-eXeƒZG d.d/„ d/e#ƒZYG d0d1„ d1eƒZZG d2d3„ d3ej[ƒZ\dS )5zhPipSession and supporting code, containing all pip-specific
network request configuration and behavior.
é    )ÚannotationsN)Ú	GeneratorÚMappingÚSequence)ÚTYPE_CHECKINGÚAny)ÚrequestsÚurllib3)ÚCacheControlAdapter)ÚDEFAULT_POOLBLOCKÚBaseAdapter)ÚHTTPAdapter)ÚPreparedRequestÚResponse)ÚCaseInsensitiveDict)ÚConnectionPool)ÚInsecureRequestWarning)Ú__version__)ÚSSLMissingError)Úget_default_environment)ÚLink)ÚMultiDomainBasicAuth)ÚSafeFileCache)Úraise_connection_error)Úhas_tls)Úlibc_ver)Úbuild_url_from_netlocÚlooks_like_ciÚparse_netlocÚredact_auth_from_url)Úurl_to_path)Ú
SSLContext)ÚProxyManagerÚignore)Úcategory))ÚhttpsÚ*r&   )r&   Ú	localhostr&   )r&   z127.0.0.0/8r&   )r&   z::1/128r&   )Úfiler&   N)Ússhr&   r&   zlist[SecureOrigin]ÚSECURE_ORIGINSé   )ÚmaxsizeÚreturnÚstrc            
      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)ÚnameÚversionr0   )Ú	installerÚpythonÚimplementationr4   ÚCPythonr1   ÚPyPyÚfinalNé   Ú.c                 S  s   g | ]}t |ƒ‘qS © )r.   )Ú.0Úxr:   r:   úZ/var/www/kodo/Anonymous/send/lib/python3.10/site-packages/pip/_internal/network/session.pyÚ
<listcomp>g   s    zuser_agent.<locals>.<listcomp>ÚJythonÚ
IronPythonÚlinuxr   )Údistroc                 S  ó   | d S ©Nr+   r:   ©r<   r:   r:   r=   Ú<lambda>v   ó    zuser_agent.<locals>.<lambda>)r0   r1   Úidc                 S  rC   rD   r:   rE   r:   r:   r=   rF   |   rG   ÚlibÚlibcrB   ÚdarwinÚmacOSÚsystemÚreleaseÚcpuÚopenssl_versionÚ
setuptoolsÚsetuptools_versionÚrustcz	--versiong      à?)ÚstderrÚtimeouts   rustc ó    r+   Ú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._vendorrB   r0   r1   ÚcodenameÚdictÚfilterÚzipr   Úmac_verrM   Ú
setdefaultrN   Úmachiner   Ú_sslÚOPENSSL_VERSIONr   Úget_distributionr.   ÚshutilÚwhichÚ
subprocessÚcheck_outputÚSTDOUTÚ	ExceptionÚsplitÚdecoder   ÚosÚenvironÚgetÚformatr`   Údumps)
r_   re   rB   Úlinux_distributionÚdistro_infosrJ   ÚsslÚsetuptools_distÚrustc_outputrZ   r:   r:   r=   Ú
user_agentS   sŠ   ÿý
ÿþÿþÿ


ÿÿ
þr†   c                   @  s,   e Zd Z					dddd„Zddd„ZdS )ÚLocalFSAdapterFNTÚrequestr   ÚstreamÚboolrU   ú0float | tuple[float | None, float | None] | NoneÚverifyú
bool | strÚcertú4bytes | str | tuple[bytes | str, bytes | str] | NoneÚproxiesúMapping[str, str] | Noner-   r   c              
   C  sæ   |j d usJ ‚t|j ƒ}tƒ }d|_|j |_ zt |¡}	W n* tyG }
 zd|_t|
ƒj|_	t
 |j	› d|
› � ¡ ¡|_W Y d }
~
|S d }
~
ww tjj|	jdd�}t |¡d pYd}t|t|	jƒ|dœƒ|_t|d	ƒ|_|jj|_|S )
NéÈ   i”  z: T)Úusegmtr   z
text/plain)zContent-TypezContent-LengthzLast-ModifiedÚrb)Úurlr    r   Ústatus_coder|   ÚstatÚOSErrorÚtypeÚ__name__ÚreasonÚioÚBytesIOÚencodeÚrawÚemailÚutilsÚ
formatdateÚst_mtimeÚ	mimetypesÚ
guess_typer   r.   Úst_sizeÚheadersÚopenÚclose)Úselfrˆ   r‰   rU   rŒ   rŽ   r�   ÚpathnameÚrespÚstatsÚexcÚmodifiedÚcontent_typer:   r:   r=   Úsendº   s2   	
&€ìýÿ
zLocalFSAdapter.sendÚNonec                 C  s   d S )Nr:   )rª   r:   r:   r=   r©   â   s   zLocalFSAdapter.close)FNTNN)rˆ   r   r‰   rŠ   rU   r‹   rŒ   r�   rŽ   r�   r�   r‘   r-   r   )r-   r²   )rš   Ú
__module__Ú__qualname__r±   r©   r:   r:   r:   r=   r‡   ¹   s    ù(r‡   c                      sH   e Zd ZdZddœd‡ fd
d„Zefd‡ fdd„Zd‡ fdd„Z‡  ZS )Ú_SSLContextAdapterMixina#  Mixin to add the ``ssl_context`` constructor argument to HTTP adapters.

    The additional argument is forwarded directly to the pool manager. This allows us
    to dynamically decide what SSL store to use at runtime, which is used to implement
    the optional ``truststore`` backend.
    N)Ússl_contextr¶   úSSLContext | NoneÚkwargsr   r-   r²   c                  s   || _ tƒ jdi |¤Ž d S )Nr:   )Ú_ssl_contextÚsuperÚ__init__)rª   r¶   r¸   ©Ú	__class__r:   r=   r»   î   s   z _SSLContextAdapterMixin.__init__ÚconnectionsÚintr,   ÚblockrŠ   Úpool_kwargsc                   s6   | j d ur| d| j ¡ tƒ jd|||dœ|¤Ž d S )Nr¶   )r¾   r,   rÀ   r:   )r¹   ro   rº   Úinit_poolmanager)rª   r¾   r,   rÀ   rÁ   r¼   r:   r=   rÂ   ÷   s   
ý
üz(_SSLContextAdapterMixin.init_poolmanagerÚproxyr.   Úproxy_kwargsr"   c                   s:   | j d ur| d| j ¡ | d| j ¡ tƒ j|fi |¤ŽS )Nr¶   Úproxy_ssl_context)r¹   ro   rº   Úproxy_manager_for)rª   rÃ   rÄ   r¼   r:   r=   rÆ     s   
z)_SSLContextAdapterMixin.proxy_manager_for)r¶   r·   r¸   r   r-   r²   )
r¾   r¿   r,   r¿   rÀ   rŠ   rÁ   r   r-   r²   )rÃ   r.   rÄ   r   r-   r"   )	rš   r³   r´   Ú__doc__r»   r   rÂ   rÆ   Ú__classcell__r:   r:   r¼   r=   rµ   æ   s    
ýürµ   c                   @  ó   e Zd ZdS )r   N©rš   r³   r´   r:   r:   r:   r=   r     ó    r   c                   @  rÉ   )r
   NrÊ   r:   r:   r:   r=   r
     rË   r
   c                      ó   e Zd Zd‡ fdd„Z‡  ZS )ÚInsecureHTTPAdapterÚconnr   r•   r.   rŒ   r�   rŽ   ústr | tuple[str, str] | Noner-   r²   c                   ó   t ƒ j||d|d� d S ©NF)rÎ   r•   rŒ   rŽ   ©rº   Úcert_verify©rª   rÎ   r•   rŒ   rŽ   r¼   r:   r=   rÓ     ó   zInsecureHTTPAdapter.cert_verify©
rÎ   r   r•   r.   rŒ   r�   rŽ   rÏ   r-   r²   ©rš   r³   r´   rÓ   rÈ   r:   r:   r¼   r=   rÍ     ó    rÍ   c                      rÌ   )ÚInsecureCacheControlAdapterrÎ   r   r•   r.   rŒ   r�   rŽ   rÏ   r-   r²   c                   rÐ   rÑ   rÒ   rÔ   r¼   r:   r=   rÓ   (  rÕ   z'InsecureCacheControlAdapter.cert_verifyrÖ   r×   r:   r:   r¼   r=   rÙ   '  rØ   rÙ   c                      sx   e Zd ZU dZded< ddddddddœd3‡ fdd„Zd4dd„Z	d5d6d%d&„Zd7d(d)„Zd8d,d-„Z	d9‡ fd1d2„Z
‡  ZS ):Ú
PipSessionNz
int | NonerU   r   r:   )ÚretriesÚresume_retriesÚcacheÚtrusted_hostsÚ
index_urlsr¶   Úrefresh_packageÚargsr   rÛ   r¿   rÜ   rÝ   ú
str | NonerÞ   úSequence[str]rß   úlist[str] | Noner¶   r·   rà   úset[str] | Noner¸   r-   r²   c                  sø   t ƒ j|i |	¤Ž g | _d| _d| _|ptƒ | _tƒ | jd< d| jd< t	|d�| _
tj|g d¢dd	�}|| _t|d
�}
|  |rRtt|ƒ||d�}tt|ƒ|d�| _n	t||d�}|
| _|  d|¡ |  d|
¡ |  dtƒ ¡ |D ]	}| j|dd� qpdS )zj
        :param trusted_hosts: Domains not to emit warnings for when not using
            HTTPS.
        NFz
User-Agentzgzip, deflatezAccept-Encoding)rß   )iô  iö  i÷  i  i  g      Ð?)ÚtotalÚstatus_forcelistÚbackoff_factor)Úmax_retries)rÝ   ré   r¶   )rÝ   ré   )ré   r¶   zhttps://zhttp://zfile://T)Úsuppress_logging)rº   r»   Úpip_trusted_originsÚ	pip_proxyÚpip_no_proxy_envÚsetrà   r†   r§   r   Úauthr	   ÚRetryrÜ   rÍ   r
   r   rÙ   Ú_trusted_host_adapterr   Úmountr‡   Úadd_trusted_host)rª   rÛ   rÜ   rÝ   rÞ   rß   r¶   rà   rá   r¸   Úinsecure_adapterÚsecure_adapterÚhostr¼   r:   r=   r»   5  sD   
ò
ý
þÿzPipSession.__init__Únew_index_urlsú	list[str]c                 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_urls’  s   zPipSession.update_index_urlsFrö   r.   Úsourcerê   rŠ   c                 C  sÜ   |sd|›�}|dur|d|› d�7 }t  |¡ t|ƒ\}}|du r)td|›�ƒ‚||f| jvr8| j ||f¡ |  t|dd�d | j¡ |  t|ƒd | j¡ |sl|  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 ú)z+Trusted host URL must include a host part: Úhttp)Úschemeú/r\   )	ÚloggerÚinfor   Ú
ValueErrorrë   Úappendrò   r   rñ   )rª   rö   rú   rê   ÚmsgÚparsed_hostÚparsed_portr:   r:   r=   ró   ™  s*   	

ÿþúzPipSession.add_trusted_hostú#Generator[SecureOrigin, None, None]c                 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_originsº  s
   €
ÿzPipSession.iter_secure_originsÚlocationr   c              	   C  sê   t j t|ƒ¡}|j|j|j}}}| dd¡d }|  ¡ D ]L}|\}}}	||kr/|dkr/qzt	 
|p5d¡}
t	 |¡}W n tyV   |rT| ¡ | ¡ krT|dkrTY qY nw |
|vr\q||	kri|	dkri|	d uriq dS t d||¡ dS )	Nú+r+   éÿÿÿÿ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_networkr  Úlowerrÿ   Úwarning)rª   r	  ÚparsedÚorigin_protocolÚorigin_hostÚorigin_portÚsecure_originÚsecure_protocolÚsecure_hostÚsecure_portÚaddrÚnetworkr:   r:   r=   Úis_secure_origin¿  sD   
ý

ÿ€øú	zPipSession.is_secure_originÚmethodr•   r   c              
     sÌ   |  d| j¡ |  d| j¡ ztƒ j||g|¢R i |¤ŽW S  tjtjfyK } zt|dd ƒ}t|dd ƒp6|}t	|||d d� W Y d }~d S d }~w t
ye } zdt|ƒ ¡ v r`tt|ƒƒ‚‚ d }~ww )NrU   r�   rˆ   r•   )r•   rU   rƒ   )ro   rU   r�   rº   rˆ   r   ÚConnectionErrorÚTimeoutÚgetattrr   ÚImportErrorr.   r  r   r   )rª   r"  r•   rá   r¸   Úerˆ   Ú
failed_urlr¼   r:   r=   rˆ     s    €€ûzPipSession.request)rá   r   rÛ   r¿   rÜ   r¿   rÝ   râ   rÞ   rã   rß   rä   r¶   r·   rà   rå   r¸   r   r-   r²   )r÷   rø   r-   r²   )NF)rö   r.   rú   râ   rê   rŠ   r-   r²   )r-   r  )r	  r   r-   rŠ   )
r"  r.   r•   r.   rá   r   r¸   r   r-   r   )rš   r³   r´   rU   Ú__annotations__r»   rù   ró   r  r!  rˆ   rÈ   r:   r:   r¼   r=   rÚ   2  s    
 ÷
]ÿ
!
CrÚ   )r-   r.   )]rÇ   Ú
__future__r   Úemail.utilsr    Ú	functoolsrœ   r  r`   Úloggingr¤   r|   ra   rt   rv   rd   Úurllib.parser  ÚwarningsÚcollections.abcr   r   r   Útypingr   r   ri   r   r	   Úpip._vendor.cachecontrolr
   Ú_BaseCacheControlAdapterÚpip._vendor.requests.adaptersr   r   r   Ú_BaseHTTPAdapterÚpip._vendor.requests.modelsr   r   Úpip._vendor.requests.structuresr   Ú"pip._vendor.urllib3.connectionpoolr   Úpip._vendor.urllib3.exceptionsr   r/   r   Úpip._internal.exceptionsr   Úpip._internal.metadatar   Úpip._internal.models.linkr   Úpip._internal.network.authr   Úpip._internal.network.cacher   Úpip._internal.network.utilsr   Úpip._internal.utils.compatr   Úpip._internal.utils.glibcr   Úpip._internal.utils.miscr   r   r   r   Úpip._internal.utils.urlsr    rƒ   r!   Úpip._vendor.urllib3r"   Ú	getLoggerrš   rÿ   Útupler.   r¿   ÚSecureOriginÚfilterwarningsr*   r)  Ú	lru_cacher†   r‡   rµ   rÍ   rÙ   ÚSessionrÚ   r:   r:   r:   r=   Ú<module>   sj    

e-.