U
    Ehn9                     @   s  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
mZ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
lmZ ddl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)m*Z* ddl+m,Z, ddl-m.Z. e,rXddl/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 e3e7e7e2e4e8e7f  f Z9e:e;Z<e	j=ded ddddddgZ>dZ?dd Z@dd  ZAG d!d" d"eZBG d#d$ d$eZCG d%d& d&ejDZEdS )'zhPipSession and supporting code, containing all pip-specific
network request configuration and behavior.
    N)requestssixurllib3)CacheControlAdapter)BaseAdapterHTTPAdapter)Response)CaseInsensitiveDict)parse)InsecureRequestWarning)__version__)MultiDomainBasicAuth)SafeFileCache)has_tls	ipaddress)libc_ver)build_url_from_netlocget_installed_versionparse_netloc)MYPY_CHECK_RUNNING)url_to_path)IteratorListOptionalTupleUnion)Linkignore)category)Zhttps*r   )r   Z	localhostr   )r   z127.0.0.0/8r   )r   z::1/128r   )filer   N)Zsshr   r   )ZBUILD_BUILDIDZBUILD_IDZCIZ	PIP_IS_CIc                   C   s   t dd tD S )z?
    Return whether it looks like pip is running under CI.
    c                 s   s   | ]}|t jkV  qd S N)osenviron).0name r&   C./venv/lib/python3.8/site-packages/pip/_internal/network/session.py	<genexpr>`   s     z looks_like_ci.<locals>.<genexpr>)anyCI_ENVIRONMENT_VARIABLESr&   r&   r&   r'   looks_like_ciX   s    r+   c                  C   sL  dt dt dt id} | d d dkr@t | d d< n| d d dkrtjjd	krltjd
d }ntj}ddd |D | d d< nB| d d dkrt | d d< n | d d dkrt | d d< tjdrHddl	m
} ttdd tdddg| }ttdd tddgt }|r:||d< |rH|| d< tjdrzt d rzdt d d| d< t rt | di d< t rt | di d< t rt | d< t rdd
l}|j| d < td!}|d
k	r || d"< t rd#nd
| d$< tjd%}|d
k	r2|| d&< d'j| tj| d(d#d)d*S )+z6
    Return a string representing the user agent.
    pip)r%   versionr%   )Z	installerpythonimplementationr/   ZCPythonr-   ZPyPyfinalN   .c                 S   s   g | ]}t |qS r&   )str)r$   xr&   r&   r'   
<listcomp>w   s     zuser_agent.<locals>.<listcomp>ZJythonZ
IronPythonZlinuxr   )distroc                 S   s   | d S N   r&   r4   r&   r&   r'   <lambda>       zuser_agent.<locals>.<lambda>idc                 S   s   | d S r7   r&   r9   r&   r&   r'   r:      r;   liblibcr6   darwinZmacOSsystemreleaseZcpuZopenssl_versionZ
setuptoolssetuptools_versionTZciZPIP_USER_AGENT_USER_DATA	user_dataz9{data[installer][name]}/{data[installer][version]} {json}),:)Z
separatorsZ	sort_keys)datajson) r   platformZpython_versionZpython_implementationsyspypy_version_inforeleaseleveljoin
startswithpip._vendorr6   dictfilterzipZlinux_distributionr   Zmac_verr@   
setdefaultrA   machiner   Z_sslZOPENSSL_VERSIONr   r+   r"   r#   getformatrG   dumps)rF   rJ   r6   Zdistro_infosr>   ZsslrB   rC   r&   r&   r'   
user_agentc   sn     





rW   c                   @   s   e Zd ZdddZdd ZdS )LocalFSAdapterNc              
   C   s   t |j}t }d|_|j|_zt|}	W n. tk
rZ }
 zd|_|
|_W 5 d }
~
X Y nPX tj	j
|	jdd}t|d p~d}t||	j|d|_t|d|_|jj|_|S )	N   i  T)Zusegmtr   z
text/plain)zContent-TypezContent-LengthzLast-Modifiedrb)r   urlr   Zstatus_coder"   statOSErrorrawemailZutilsZ
formatdatest_mtime	mimetypesZ
guess_typer	   st_sizeheadersopenclose)selfrequeststreamtimeoutverifycertZproxiespathnameZrespZstatsexcZmodifiedZcontent_typer&   r&   r'   send   s&    


zLocalFSAdapter.sendc                 C   s   d S r!   r&   )rf   r&   r&   r'   re      s    zLocalFSAdapter.close)NNNNN)__name__
__module____qualname__rn   re   r&   r&   r&   r'   rX      s     
rX   c                       s   e Zd Z fddZ  ZS )InsecureHTTPAdapterc                    s   t t| j||d|d d S )NF)connr[   rj   rk   )superrr   cert_verify)rf   rs   r[   rj   rk   	__class__r&   r'   ru      s    
   zInsecureHTTPAdapter.cert_verify)ro   rp   rq   ru   __classcell__r&   r&   rv   r'   rr      s   rr   c                       sF   e Zd ZdZ fddZdddZdd Zd	d
 Z fddZ  Z	S )
PipSessionNc           
         s   | dd}| dd}| dg }| dd}tt| j|| g | _t | jd< t|d| _t	j
|d	d
ddgdd}|rtt||d}n
t|d}t|d}|| _| d| | d| | dt  |D ]}	| j|	dd qdS )zj
        :param trusted_hosts: Domains not to emit warnings for when not using
            HTTPS.
        retriesr   cacheNtrusted_hosts
index_urlsz
User-Agent)r}   i  i  i  i  g      ?)totalZstatus_forcelistZbackoff_factor)r{   max_retries)r   zhttps://zhttp://zfile://T)suppress_logging)poprt   ry   __init__pip_trusted_originsrW   rc   r   Zauthr   ZRetryr   r   r   rr   _insecure_adaptermountrX   add_trusted_host)
rf   argskwargsrz   r{   r|   r}   Zsecure_adapterZinsecure_adapterhostrv   r&   r'   r      s4    


zPipSession.__init__Fc                 C   s   |s.d |}|dk	r$|d |7 }t| t|}|| jkrL| j| | t|d | j |d s| t|d | j 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: {!r}Nz
 (from {})/r8   rE   )	rU   loggerinfor   r   appendr   r   r   )rf   r   sourcer   msgZ	host_portr&   r&   r'   r   '  s    



zPipSession.add_trusted_hostc                 c   s<   t D ]
}|V  q| jD ] \}}d||d kr.dn|fV  qd S )Nr   )SECURE_ORIGINSr   )rf   secure_originr   portr&   r&   r'   iter_secure_originsA  s    zPipSession.iter_secure_originsc              	   C   s   t t|}|j|j|j  }}}|ddd }|  D ]}|\}}}	||kr\|dkr\q<z0t	|d krnd nt
|}
tt
|}W n4 tk
r   |r| | kr|dkrY q<Y nX |
|krq<||	kr|	dkr|	d k	rq< dS td|| dS )N+r8   r   TzThe 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_parseZurlparser3   ZschemeZhostnamer   rsplitr   r   Z
ip_addressr   Zensure_textZ
ip_network
ValueErrorlowerr   Zwarning)rf   locationZparsedZorigin_protocolZorigin_hostZorigin_portr   Zsecure_protocolZsecure_hostZsecure_portZaddrZnetworkr&   r&   r'   is_secure_originH  sV      


	zPipSession.is_secure_originc                    s(   | d| j tt| j||f||S )Nri   )rR   ri   rt   ry   rg   )rf   methodr[   r   r   rv   r&   r'   rg     s    zPipSession.request)NF)
ro   rp   rq   ri   r   r   r   r   rg   rx   r&   r&   rv   r'   ry      s   G
Hry   )F__doc__Zemail.utilsr_   rG   Zloggingra   r"   rH   rI   warningsrN   r   r   r   Zpip._vendor.cachecontrolr   Zpip._vendor.requests.adaptersr   r   Zpip._vendor.requests.modelsr   Zpip._vendor.requests.structuresr	   Zpip._vendor.six.moves.urllibr
   r   Zpip._vendor.urllib3.exceptionsr   r,   r   Zpip._internal.network.authr   Zpip._internal.network.cacher   Zpip._internal.utils.compatr   r   Zpip._internal.utils.glibcr   Zpip._internal.utils.miscr   r   r   Zpip._internal.utils.typingr   Zpip._internal.utils.urlsr   typingr   r   r   r   r   Zpip._internal.models.linkr   r3   intZSecureOriginZ	getLoggerro   r   filterwarningsr   r*   r+   rW   rX   rr   ZSessionry   r&   r&   r&   r'   <module>   sT   
P!