a
    0f5I                     @   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ZddlmZ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& ddl'm(Z(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?m@Z@ ddlAmBZB erddlCmDZD ddlEmFZF eGeHZIeeJeJeeeKeJf  f ZLejMde/d g dZNeeL eOd< dZPeQdddZRejSdd eJdd!d"ZTG d#d$ d$e$ZUG d%d& d&ZVG d'd( d(eVe&Z%G d)d* d*eVe!Z G d+d, d,e%ZWG d-d. d.e ZXG d/d0 d0ejYZZdS )1zhPipSession and supporting code, containing all pip-specific
network request configuration and behavior.
    N)
TYPE_CHECKINGAnyDict	GeneratorListMappingOptionalSequenceTupleUnion)requestsurllib3)CacheControlAdapter)DEFAULT_POOLBLOCK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)
SSLContext)PoolManager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 r6   V/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_internal/network/session.py	<genexpr>k       z looks_like_ci.<locals>.<genexpr>)anyCI_ENVIRONMENT_VARIABLESr6   r6   r6   r7   looks_like_cid   s    r<      )maxsizec            
      C   s  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rl|d
d }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rRddl	m
} | | | f}ttdd tg d|}ttdd tddgt }|rD||d< |rR|| 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rvztj d#d$gtj!d%d&}W n t"yR   Y n$0 |d'rv|#d(d) $ | d*< t% rd+nd
| d,< t&j'(d-}	|	d
ur|	| d.< d/j)| t*j+| d0d+d1d2S )3z6
    Return a string representing the user agent.
    pip)r5   versionr5   )	installerpythonimplementationrC   CPythonr@   PyPyfinalN   .c                 S   s   g | ]}t |qS r6   )str)r4   xr6   r6   r7   
<listcomp>   r9   zuser_agent.<locals>.<listcomp>Jython
IronPythonlinuxr   )distroc                 S   s   | d S Nr=   r6   rJ   r6   r6   r7   <lambda>   r9   zuser_agent.<locals>.<lambda>)r5   r@   idc                 S   s   | d S rP   r6   rQ   r6   r6   r7   rR      r9   liblibcrO   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._vendorrO   r5   r@   codenamedictfilterzipr   mac_verrX   
setdefaultrY   machiner   _sslOPENSSL_VERSIONr   get_distributionrI   shutilwhich
subprocesscheck_outputSTDOUT	Exceptionsplitdecoder<   r2   r3   getformatrk   dumps)
rj   rp   rO   linux_distributiondistro_infosrU   sslsetuptools_distrustc_outputre   r6   r6   r7   
user_agentn   s    







r   c                   @   sr   e Zd Zd
eeeeeeeef f  eee	f eee	ee	e	f f  ee
e	e	f  edddZdddd	ZdS )LocalFSAdapterFNT)requeststreamr`   verifycertproxiesr0   c              
   C   s   t |j}t }d|_|j|_zt|}	W nR ty~ }
 z:d|_t|
j|_	t
|j	 d|
  |_W Y d }
~
nXd }
~
0 0 tjj|	jdd}t|d pd}t||	j|d|_t|d	|_|jj|_|S )
N   i  z: T)usegmtr   z
text/plain)zContent-TypezContent-LengthzLast-Modifiedrb)r    urlr   status_coder2   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_typer6   r6   r7   send   s*    	
2
zLocalFSAdapter.sendr/   c                 C   s   d S r1   r6   )r   r6   r6   r7   r      s    zLocalFSAdapter.close)FNTNN)r   
__module____qualname__r   boolr   r   floatr
   rI   r   r   r   r   r6   r6   r6   r7   r      s        
'r   c                       sR   e Zd ZdZdded edd fddZefeee	ed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!   )r   kwargsr0   c                   s   || _ t jf i | d S r1   )_ssl_contextsuper__init__)r   r   r   	__class__r6   r7   r     s    z _SSLContextAdapterMixin.__init__r"   )connectionsr>   blockpool_kwargsr0   c                    s2   | j d ur|d| j  t jf |||d|S )Nr   )r   r>   r   )r   rz   r   init_poolmanager)r   r   r>   r   r   r   r6   r7   r     s    
z(_SSLContextAdapterMixin.init_poolmanager)r   r   r   __doc__r   r   r   r   intr   r   __classcell__r6   r6   r   r7   r      s   
r   c                   @   s   e Zd ZdS )r   Nr   r   r   r6   r6   r6   r7   r   "  s   r   c                   @   s   e Zd ZdS )r   Nr   r6   r6   r6   r7   r   &  s   r   c                	       sF   e Zd Zeeeeef eeeeeef f  dd fddZ	  Z
S )InsecureHTTPAdapterNconnr   r   r   r0   c                    s   t  j||d|d d S NF)r   r   r   r   r   cert_verifyr   r   r   r   r   r   r6   r7   r   +  s    zInsecureHTTPAdapter.cert_verifyr   r   r   r   rI   r   r   r   r
   r   r   r6   r6   r   r7   r   *  s   
r   c                	       sF   e Zd Zeeeeef eeeeeef f  dd fddZ	  Z
S )InsecureCacheControlAdapterNr   c                    s   t  j||d|d d S r   r   r   r   r6   r7   r   6  s    z'InsecureCacheControlAdapter.cert_verifyr   r6   r6   r   r7   r   5  s   
r   c                
       s   e Zd ZU dZee ed< ddddddeeee e	e ee
e  ed edd fdd	Ze
e dd
ddZdeee eddddZeeddf dddZeedddZeeeeed fddZ  ZS )
PipSessionNr`   r   r6   )retriescachetrusted_hosts
index_urlsr   r!   )argsr   r   r   r   r   r   r0   c                   s   t  j|i | g | _t | jd< t|d| _tj|g ddd}t	|d}|rxt
t|||d}	tt||d| _n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.
        z
User-Agent)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_loggingN)r   r   pip_trusted_originsr   r   r   authr   Retryr   r   r   r   _trusted_host_adapterr   mountr   add_trusted_host)r   r   r   r   r   r   r   r   insecure_adaptersecure_adapterhostr   r6   r7   r   C  s6    

zPipSession.__init__)new_index_urlsr0   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   r6   r6   r7   update_index_urls  s    zPipSession.update_index_urlsF)r   sourcer   r0   c                 C   s   |s0d|}|dur&|d| d7 }t | t|\}}|du rRtd|||f| jvrp| j||f | t|ddd | j | t|d | j |s| t|ddd	 | j | 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: Nz (from )z+Trusted host URL must include a host part: http)scheme/rg   )	loggerinfor   
ValueErrorr   appendr   r   r   )r   r   r   r   msgZparsed_hostZparsed_portr6   r6   r7   r     s(    	

zPipSession.add_trusted_hostr/   c                 c   s6   t E d H  | jD ] \}}d||d u r(dn|fV  qd S )Nr&   )r*   r   )r   r   portr6   r6   r7   iter_secure_origins  s    
zPipSession.iter_secure_origins)locationr0   c              	   C   s   t jt|}|j|j|j  }}}|ddd }|  D ]}|\}}}	||kr^|dkr^q>zt	
|pjd}
t	|}W n2 ty   |r| | kr|dkrY q>Y n0 |
|vrq>||	kr|	dkr|	d urq> dS td|| dS )	N+r=   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urlparserI   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networkr6   r6   r7   is_secure_origin  sJ    



	zPipSession.is_secure_origin)methodr   r   r   r0   c                    s8   | d| j | d| j t j||g|R i |S )Nr`   r   )rz   r`   r   r   r   )r   r  r   r   r   r   r6   r7   r     s    zPipSession.request)NF)r   r   r   r`   r   r   __annotations__r   rI   r	   r   r   r   r   r   r   SecureOriginr   r   r  r   r   r   r6   r6   r   r7   r   @  s2   

P 
!Cr   )[r   email.utilsr   	functoolsr   r   rk   loggingr   r2   rl   r   r   ro   urllib.parser   warningstypingr   r   r   r   r   r   r   r	   r
   r   rt   r   r   pip._vendor.cachecontrolr   _BaseCacheControlAdapterZpip._vendor.requests.adaptersr   r   r   _BaseHTTPAdapterZpip._vendor.requests.modelsr   r   Zpip._vendor.requests.structuresr   Z"pip._vendor.urllib3.connectionpoolr   Zpip._vendor.urllib3.exceptionsr   r?   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    r   r!   Zpip._vendor.urllib3.poolmanagerr"   	getLoggerr   r   rI   r   r  filterwarningsr*   r  r;   r   r<   	lru_cacher   r   r   r   r   Sessionr   r6   r6   r6   r7   <module>   sd   0


e,"