o
    MfYA                     @   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   _/var/www/html/analyze/labelStudio/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rd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rt d rd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
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"   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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,