U
    @vgn9                     @   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)https*r    )r    	localhostr    )r    z127.0.0.0/8r    )r    z::1/128r    )filer    N)sshr    r    )BUILD_BUILDIDBUILD_IDCI	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-   A/tmp/pip-unpacked-wheel-gw11q0wt/pip/_internal/network/session.py	<genexpr>`   s     z looks_like_ci.<locals>.<genexpr>)anyCI_ENVIRONMENT_VARIABLESr-   r-   r-   r.   looks_like_ciX   s    r2   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,   )	installerpythonimplementationr7   CPythonr4   PyPyfinalN   .c                 S   s   g | ]}t |qS r-   )str)r+   xr-   r-   r.   
<listcomp>w   s     zuser_agent.<locals>.<listcomp>Jython
IronPythonlinuxr   )distroc                 S   s   | d S N   r-   r>   r-   r-   r.   <lambda>       zuser_agent.<locals>.<lambda>idc                 S   s   | d S rD   r-   rF   r-   r-   r.   rG      rH   liblibcrC   darwinmacOSsystemreleasecpuopenssl_version
setuptoolssetuptools_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._vendorrC   dictfilterziplinux_distributionr   mac_verrN   
setdefaultrO   machiner   _sslOPENSSL_VERSIONr   r2   r)   r*   getformatr\   dumps)r[   ra   rC   distro_infosrK   sslrS   rV   r-   r-   r.   
user_agentc   sn     





rt   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)usegmtr   z
text/plain)zContent-TypezContent-LengthzLast-Modifiedrb)r   urlr   status_coder)   statOSErrorrawemailutils
formatdatest_mtime	mimetypes
guess_typer	   st_sizeheadersopenclose)selfrequeststreamtimeoutverifycertproxiespathnamerespstatsexcmodifiedcontent_typer-   r-   r.   send   s&    


zLocalFSAdapter.sendc                 C   s   d S r(   r-   )r   r-   r-   r.   r      s    zLocalFSAdapter.close)NNNNN)__name__
__module____qualname__r   r   r-   r-   r-   r.   ru      s     
ru   c                       s   e Zd Z fddZ  ZS )InsecureHTTPAdapterc                    s   t t| j||d|d d S )NF)connry   r   r   )superr   cert_verify)r   r   ry   r   r   	__class__r-   r.   r      s    
   zInsecureHTTPAdapter.cert_verify)r   r   r   r   __classcell__r-   r-   r   r.   r      s   r   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      ?)totalstatus_forcelistbackoff_factor)r   max_retries)r   zhttps://zhttp://zfile://T)suppress_logging)popr   r   __init__pip_trusted_originsrt   r   r   authr   Retryr   r   r   r   _insecure_adaptermountru   add_trusted_host)
r   argskwargsr   r   r   r   secure_adapterinsecure_adapterhostr   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 {})/rE   rX   )	rp   loggerinfor   r   appendr   r   r   )r   r   sourcer   msg	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   )r   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+rE   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_parseurlparser=   schemehostnamer   rsplitr   r   
ip_addressr   ensure_text
ip_network
ValueErrorlowerr   warning)r   locationparsedorigin_protocolorigin_hostorigin_portr   secure_protocolsecure_hostsecure_portaddrnetworkr-   r-   r.   is_secure_originH  sV      


	zPipSession.is_secure_originc                    s(   | d| j tt| j||f||S )Nr   )rk   r   r   r   r   )r   methodry   r   r   r   r-   r.   r     s    zPipSession.request)NF)
r   r   r   r   r   r   r   r   r   r   r-   r-   r   r.   r      s   G
Hr   )F__doc__email.utilsr~   r\   loggingr   r)   r]   r`   warningsre   r   r   r   Zpip._vendor.cachecontrolr   pip._vendor.requests.adaptersr   r   pip._vendor.requests.modelsr   Zpip._vendor.requests.structuresr	   Zpip._vendor.six.moves.urllibr
   r   pip._vendor.urllib3.exceptionsr   r3   r   pip._internal.network.authr   pip._internal.network.cacher   pip._internal.utils.compatr   r   pip._internal.utils.glibcr   pip._internal.utils.miscr   r   r   pip._internal.utils.typingr   pip._internal.utils.urlsr   typingr   r   r   r   r   pip._internal.models.linkr   r=   intZSecureOrigin	getLoggerr   r   filterwarningsr   r1   r2   rt   ru   r   Sessionr   r-   r-   r-   r.   <module>   sT   
P!