3
ÀÞL]™¦  ã               @   s  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mZ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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*Z*d dl+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK d dlLmMZM d dlNmOZO d dlPmQZQ d dlRmSZS eO�r@d dlTmUZUmVZVmWZWmXZXmYZYmZZZ d dl[m\Z\ d dl]m^Z^ d dl_m`Z` d dlambZbmcZc eVedededf Zed d!d"d#d$d%d&d'd(d)d*d+d,gZfejgehƒZiyd dljZjW nP ekk
�rŽ   dZjY n8 elk
�rÄ Zm zeijnd-edemƒƒ dZjW Y ddZm[mX nX dbZod2d3„ Zpd4d5„ Zqd6d7„ ZrG d8d9„ d9eƒZsG d:d;„ d;eƒZtG d<d=„ d=eƒZuG d>d?„ d?eƒZvG d@dA„ dAejwƒZxdcdBd „Zye
jzdCe
j{ƒZ|e
jzdDe
j{ƒZ}dEd!„ Z~dFd"„ ZdGd$„ Z€dHd%„ Z�dIdJ„ Z‚dKd'„ ZƒdLd(„ Z„dMdN„ Z…dOdP„ Z†dQdR„ Z‡dSdT„ ZˆdddVd)„Z‰dedWd&„ZŠG dXdY„ dYe$j‹ƒZŒdfd[d*„Z�d\d,„ ZŽd]d+„ Z�d^d_„ Z�d`da„ Z‘dS )gé    )Úabsolute_importN)ÚrequestsÚurllib3)ÚCacheControlAdapter)Ú	FileCache)Ú	LockError)ÚBaseAdapterÚHTTPAdapter)ÚAuthBaseÚHTTPBasicAuth)ÚCONTENT_CHUNK_SIZEÚResponse)ÚCaseInsensitiveDict)Úget_netrc_auth)Úxmlrpc_client)Úparse)Úrequest)ÚHashMismatchÚInstallationError)ÚPyPI)ÚHAS_TLSÚssl)Úauto_decode)Úcheck_path_owner)Úlibc_ver)Úwrite_delete_marker_file)ÚARCHIVE_EXTENSIONSÚaskÚ	ask_inputÚask_passwordÚask_path_existsÚ
backup_dirÚconsumeÚdisplay_pathÚformat_sizeÚget_installed_versionÚpath_to_urlÚremove_auth_from_urlÚrmtreeÚsplit_auth_netloc_from_urlÚsplitextÚunpack_file)ÚTempDirectory)ÚMYPY_CHECK_RUNNING)ÚDownloadProgressProvider)Úvcs)ÚOptionalÚTupleÚDictÚIOÚTextÚUnion)ÚValues)ÚLink)ÚHashes)ÚAuthInfoÚVersionControlÚget_file_contentÚis_urlÚurl_to_pathr&   Úis_archive_fileÚunpack_vcs_linkÚunpack_file_urlÚ
is_vcs_urlÚis_file_urlÚunpack_http_urlÚ
unpack_urlÚparse_content_dispositionÚsanitize_content_filenamez*Keyring is skipped due to an exception: %sÚ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© rO   ú5/tmp/pip-build-69lrc5qx/pip/pip/_internal/download.pyú	<genexpr>l   s    z looks_like_ci.<locals>.<genexpr>)ÚanyÚCI_ENVIRONMENT_VARIABLESrO   rO   rO   rP   Úlooks_like_cid   s    rT   c              C   sD  dt jdœtjƒ dtjƒ idœ} | d d dkrBtjƒ | d d< n’| d d dkr’tjjd	krntjd
d… }ntj}djdd„ |D ƒƒ| d d< nB| d d dkr´tjƒ | d d< n | d d dkrÔtjƒ | d d< tjj	dƒ�rJddl
m} ttdd„ tdddg|jƒ ƒƒƒ}ttdd„ tddgtƒ ƒƒƒ}|�r<||d< |�rJ|| d< tjj	dƒ�r|tjƒ d �r|dtjƒ d dœ| d< tjƒ �rštjƒ | jdi ƒd< tjƒ �r¸tjƒ | jdi ƒd< tjƒ �rÎtjƒ | d< t�rÞtj| d < td!ƒ}|d
k	�rø|| d"< tƒ �rd#nd
| d$< tjjd%ƒ}|d
k	�r*|| d&< d'j| tj | d,d#d*�d+�S )-z6
    Return a string representing the user agent.
    Úpip)rN   ÚversionrN   )Ú	installerÚpythonÚimplementationrY   ÚCPythonrV   ÚPyPyÚfinalNé   Ú.c             S   s   g | ]}t |ƒ‘qS rO   )Ústr)rM   ÚxrO   rO   rP   ú
<listcomp>ƒ   s    zuser_agent.<locals>.<listcomp>ÚJythonÚ
IronPythonÚlinuxr   )Údistroc             S   s   | d S )Né   rO   )r`   rO   rO   rP   Ú<lambda>�   s    zuser_agent.<locals>.<lambda>Úidc             S   s   | d S )Nrf   rO   )r`   rO   rO   rP   rg   “   s    ÚlibÚlibcre   ÚdarwinÚmacOSÚsystemÚreleaseÚcpuÚopenssl_versionÚ
setuptoolsÚsetuptools_versionTZciZPIP_USER_AGENT_USER_DATAÚ	user_dataz9{data[installer][name]}/{data[installer][version]} {json}ú,ú:)Ú
separatorsÚ	sort_keys)ÚdataÚjson)rt   ru   )!rU   Ú__version__ÚplatformÚpython_versionÚpython_implementationÚsysÚpypy_version_infoÚreleaselevelÚjoinÚ
startswithÚpip._vendorre   ÚdictÚfilterÚzipÚlinux_distributionr   Úmac_verrm   Ú
setdefaultrn   Úmachiner   r   ÚOPENSSL_VERSIONr%   rT   rK   rL   ÚgetÚformatry   Údumps)rx   r   re   Údistro_infosrj   rr   rs   rO   rO   rP   Ú
user_agento   s^    






r�   c             C   sÂ   |  st  rdS yzy
t j}W n tk
r0   Y n0X tjd| ƒ || |ƒ}|dk	r\|j|jfS dS |rˆtjd| ƒ t j| |ƒ}|rˆ||fS W n2 tk
r¼ } ztj	dt
|ƒƒ W Y dd}~X nX dS )z3Return the tuple auth for a given url from keyring.Nz'Getting credentials from keyring for %sz$Getting password from keyring for %sz*Keyring is skipped due to an exception: %s)ÚkeyringÚget_credentialÚAttributeErrorÚloggerÚdebugÚusernameÚpasswordZget_passwordÚ	ExceptionÚwarningr_   )Úurlr–   r’   Zcredr—   ÚexcrO   rO   rP   Ú_get_keyring_auth¾   s(    

rœ   c               @   s`   e Zd Zddd„Zdd„ Zddd„Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚMultiDomainBasicAuthTNc             C   s   || _ || _i | _d | _d S )N)Ú	promptingÚ
index_urlsÚ	passwordsÚ_credentials_to_save)Úselfrž   rŸ   rO   rO   rP   Ú__init__Ü   s    zMultiDomainBasicAuth.__init__c             C   sF   | s| j  rdS x.| j D ]$}t|ƒjdƒd }|j|ƒr|S qW dS )aí  Return the original index URL matching the requested URL.

        Cached or dynamically generated credentials may work against
        the original index URL rather than just the netloc.

        The provided url should have had its username and password
        removed already. If the original index url had credentials then
        they will be included in the return value.

        Returns None if no matching index was found, or if --no-index
        was specified by the user.
        Nú/)rŸ   r'   Úrstripr‚   )r¢   rš   ÚuÚprefixrO   rO   rP   Ú_get_index_urlè   s    
z#MultiDomainBasicAuth._get_index_urlc             C   sî   t |ƒ\}}}|\}}|dk	r6|dk	r6tjd|ƒ |S | j|ƒ}	|	rft |	ƒ}
|
rf|
\}	}}tjd|	ƒ |	rž|d dk	rž|\}}|dk	rž|dk	ržtjd|ƒ |S |r¾t|ƒ}|r¾tjd|ƒ |S |rêt|	|ƒpÔt||ƒ}|rêtjd|ƒ |S dS )	z2Find and return credentials for the specified URL.NzFound credentials in url for %szFound index url %sr   z%Found credentials in index url for %sz!Found credentials in netrc for %sz#Found credentials in keyring for %s)NN)r)   r”   r•   r¨   r   rœ   )r¢   Úoriginal_urlZallow_netrcZallow_keyringrš   ÚnetlocZurl_user_passwordr–   r—   Ú	index_urlZ
index_infoÚ_Zindex_url_user_passwordÚ
netrc_authZkr_authrO   rO   rP   Ú_get_new_credentialsý   s:    



z)MultiDomainBasicAuth._get_new_credentialsc             C   sf   t |ƒ\}}}| jj|dƒ\}}|dks0|dkr>| j|ƒ\}}|dk	r\|dk	r\||f| j|< |||fS )a_  Return the credentials to use for the provided URL.

        If allowed, netrc and keyring may be used to obtain the
        correct credentials.

        Returns (url_without_credentials, username, password). Note
        that even if the original URL contains credentials, this
        function may return a different username and password.
        N)NN)r)   r    rŒ   r®   )r¢   r©   rš   rª   r¬   r–   r—   rO   rO   rP   Ú_get_url_and_credentials,  s    
z-MultiDomainBasicAuth._get_url_and_credentialsc             C   sH   | j |jƒ\}}}||_|d k	r6|d k	r6t||ƒ|ƒ}|jd| jƒ |S )NÚresponse)r¯   rš   r   Úregister_hookÚ
handle_401)r¢   Úreqrš   r–   r—   rO   rO   rP   Ú__call__F  s    zMultiDomainBasicAuth.__call__c             C   sF   t d| ƒ}|sdS t||ƒ}|r4|d |d dfS tdƒ}||dfS )NzUser for %s: r   rf   Fz
Password: T)NN)r   rœ   r   )r¢   rª   r–   Úauthr—   rO   rO   rP   Ú_prompt_for_passwordW  s    
z)MultiDomainBasicAuth._prompt_for_passwordc             C   s   t sdS tdddgƒdkS )NFz#Save credentials to keyring [y/N]: ÚyÚn)r‘   r   )r¢   rO   rO   rP   Ú _should_save_password_to_keyringb  s    z5MultiDomainBasicAuth._should_save_password_to_keyringc       	      K   sà   |j dkr|S | js|S tj|jƒ}| j|jƒ\}}}d | _|d k	rv|d k	rv||f| j|j< |rv| j	ƒ rv|j||f| _|j
 |jjƒ  t|pŽd|p”dƒ|jƒ}|jd| jƒ | jrÀ|jd| jƒ |jj|f|Ž}|jj|ƒ |S )Ni‘  Ú r°   )Ústatus_coderž   Úurllib_parseÚurlparserš   r¶   rª   r¡   r    r¹   ÚcontentÚrawÚrelease_connr   r   r±   Úwarn_on_401Úsave_credentialsÚ
connectionÚsendÚhistoryÚappend)	r¢   ÚrespÚkwargsÚparsedr–   r—   Úsaver³   Únew_resprO   rO   rP   r²   g  s(    

zMultiDomainBasicAuth.handle_401c             K   s   |j dkrtjd|jjƒ dS )z6Response callback to warn about incorrect credentials.i‘  z)401 Error, Credentials not correct for %sN)r»   r”   r™   r   rš   )r¢   rÇ   rÈ   rO   rO   rP   rÁ   ”  s    
z MultiDomainBasicAuth.warn_on_401c             K   sn   t dk	stdƒ‚t sdS | j}d| _|rj|jdk rjytjdƒ t j|Ž  W n tk
rh   tjdƒ Y nX dS )z1Response callback to save credentials on success.Nz'should never reach here without keyringi�  zSaving credentials to keyringzFailed to save credentials)	r‘   ÚAssertionErrorr¡   r»   r”   ÚinfoZset_passwordr˜   Ú	exception)r¢   rÇ   rÈ   ÚcredsrO   rO   rP   rÂ   š  s    
z%MultiDomainBasicAuth.save_credentials)TN)TT)Ú__name__Ú
__module__Ú__qualname__r£   r¨   r®   r¯   r´   r¶   r¹   r²   rÁ   rÂ   rO   rO   rO   rP   r�   Ú   s   
 
.-r�   c               @   s   e Zd Zddd„Zdd„ ZdS )ÚLocalFSAdapterNc             C   s®   t |jƒ}tƒ }d|_|j|_ytj|ƒ}	W n. tk
rZ }
 zd|_|
|_W Y d d }
~
X nPX tj	j
|	jdd�}tj|ƒ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=   rš   r   r»   rK   ÚstatÚOSErrorr¿   ÚemailÚutilsÚ
formatdateÚst_mtimeÚ	mimetypesÚ
guess_typer   Úst_sizeÚheadersÚopenÚclose)r¢   r   ÚstreamÚtimeoutÚverifyÚcertÚproxiesÚpathnamerÇ   Ústatsr›   ÚmodifiedÚcontent_typerO   rO   rP   rÄ   ¬  s$    

zLocalFSAdapter.sendc             C   s   d S )NrO   )r¢   rO   rO   rP   râ   Ç  s    zLocalFSAdapter.close)NNNNN)rÐ   rÑ   rÒ   rÄ   râ   rO   rO   rO   rP   rÓ   ª  s    
rÓ   c                   sD   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡ fdd„Z‡ fdd	„Z‡  ZS )
ÚSafeFileCachezw
    A file based cache which is safe to use even when the target directory may
    not be accessible or writable.
    c                s4   t t| ƒj||Ž t| jƒs0tjd| jƒ d | _d S )NzßThe directory '%s' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.)Úsuperrì   r£   r   Ú	directoryr”   r™   )r¢   ÚargsrÈ   )Ú	__class__rO   rP   r£   Ñ  s    
zSafeFileCache.__init__c                s@   | j d krd S ytt| ƒj||ŽS  tttfk
r:   Y nX d S )N)rî   rí   rì   rŒ   r   rØ   ÚIOError)r¢   rï   rÈ   )rð   rO   rP   rŒ   å  s    
zSafeFileCache.getc                s@   | j d krd S ytt| ƒj||ŽS  tttfk
r:   Y nX d S )N)rî   rí   rì   Úsetr   rØ   rñ   )r¢   rï   rÈ   )rð   rO   rP   rò   ò  s    
zSafeFileCache.setc                s@   | j d krd S ytt| ƒj||ŽS  tttfk
r:   Y nX d S )N)rî   rí   rì   Údeleter   rØ   rñ   )r¢   rï   rÈ   )rð   rO   rP   ró   ÿ  s    
zSafeFileCache.delete)	rÐ   rÑ   rÒ   Ú__doc__r£   rŒ   rò   ró   Ú__classcell__rO   rO   )rð   rP   rì   Ë  s
   rì   c               @   s   e Zd Zdd„ ZdS )ÚInsecureHTTPAdapterc             C   s   d|_ d |_d S )NÚ	CERT_NONE)Ú	cert_reqsÚca_certs)r¢   Úconnrš   rå   ræ   rO   rO   rP   Úcert_verify  s    zInsecureHTTPAdapter.cert_verifyN)rÐ   rÑ   rÒ   rû   rO   rO   rO   rP   rö     s   rö   c                   s4   e Zd ZdZ‡ fdd„Zdd„ Z‡ fdd„Z‡  ZS )Ú
PipSessionNc       
         sè   |j ddƒ}|j dd ƒ}|j dg ƒ}|j dd ƒ}tt| ƒj||Ž tƒ | jd< t|d�| _tj	|dd	d
dgdd�}|rŒt
t|dd�|d�}n
t|d�}t|d�}|| _| jd|ƒ | jd|ƒ | jdtƒ ƒ x|D ]}	| j|	ƒ qÒW d S )NÚretriesr   ÚcacheÚinsecure_hostsrŸ   z
User-Agent)rŸ   iô  i÷  i  i  g      Ð?)ÚtotalÚstatus_forcelistÚbackoff_factorT)Úuse_dir_lock)rþ   Úmax_retries)r  zhttps://zhttp://zfile://)Úpoprí   rü   r£   r�   rà   r�   rµ   r   ÚRetryr   rì   r	   rö   Ú_insecure_adapterÚmountrÓ   Úadd_insecure_host)
r¢   rï   rÈ   rý   rþ   rÿ   rŸ   Úsecure_adapterÚinsecure_adapterÚhost)rð   rO   rP   r£     s.    





zPipSession.__init__c             C   s   | j dj|ƒ| jƒ d S )Nzhttps://{}/)r  r�   r  )r¢   r  rO   rO   rP   r	  Y  s    zPipSession.add_insecure_hostc                s(   |j d| jƒ tt| ƒj||f|ž|ŽS )Nrä   )r‰   rä   rí   rü   r   )r¢   Úmethodrš   rï   rÈ   )rð   rO   rP   r   ]  s    zPipSession.request)rÐ   rÑ   rÒ   rä   r£   r	  r   rõ   rO   rO   )rð   rP   rü     s   Arü   c       
      C   sL  |dkrt dƒ‚tj| ƒ}|rè|jdƒjƒ }|dkrR|rR|jdƒrRtd|| f ƒ‚|dkrÊ| jddƒd }|jdd	ƒ}t	j
|ƒ}|r¢|jdƒd |jd
dƒd  }tj|ƒ}|jd	ƒrÄd	|jd	ƒ }|} n|j| ƒ}|jƒ  |j|jfS y&t| dƒ�}t|jƒ ƒ}W dQ R X W n4 tk
�rB }	 ztdt|	ƒ ƒ‚W Y dd}	~	X nX | |fS )a*  Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.

    :param url:         File path or url.
    :param comes_from:  Origin description of requirements.
    :param session:     Instance of pip.download.PipSession.
    NzAget_file_content() missing 1 required keyword argument: 'session'rf   ÚfileÚhttpz6Requirements file %s references URL %s, which is localru   ú\r¤   ú|rÖ   z$Could not open requirements file: %s)Ú	TypeErrorÚ
_scheme_reÚsearchÚgroupÚlowerr‚   r   ÚsplitÚreplaceÚ_url_slash_drive_reÚmatchr¼   ÚunquoteÚlstriprŒ   Úraise_for_statusrš   Útextrá   r   Úreadrñ   r_   )
rš   Ú
comes_fromÚsessionr  ÚschemeÚpathrÇ   Úfr¾   r›   rO   rO   rP   r;   e  s>    	





 z^(http|https|file):z/*([a-z])\|c             C   s6   d| krdS | j ddƒd jƒ }|ddddgtj kS )	z)Returns true if the name looks like a URLru   Frf   r   r  Úhttpsr  Úftp)r  r  r/   Úall_schemes)rN   r"  rO   rO   rP   r<   ˜  s    c             C   sp   | j dƒstd|  ƒ‚tj| ƒ\}}}}}| s8|dkr>d}n tjdkrRd| }ntd|  ƒ‚tj|| ƒ}|S )z(
    Convert a file: URL to a path.
    zfile:z4You can only turn file: urls into filenames (not %r)Ú	localhostrº   Úwin32z\\z:non-local file URIs are not supported on this platform: %r)	r‚   rÌ   r¼   Úurlsplitr~   r{   Ú
ValueErrorÚurllib_requestÚurl2pathname)rš   r¬   rª   r#  rO   rO   rP   r=   ¡  s    


c             C   s    t | ƒd jƒ }|tkrdS dS )z9Return True if `name` is a considered as an archive file.rf   TF)r*   r  r   )rN   ÚextrO   rO   rP   r>   »  s    c             C   s   t | ƒ}|j|| jd� d S )N)rš   )Ú_get_used_vcs_backendÚunpackrš   )ÚlinkÚlocationÚvcs_backendrO   rO   rP   r?   Ä  s    c             C   s$   xt jD ]}| j|jkr|S qW dS )z1
    Return a VersionControl object or None.
    N)r/   Úbackendsr"  Úschemes)r1  r3  rO   rO   rP   r/  É  s    r/  c             C   s   t t| ƒƒS )N)Úboolr/  )r1  rO   rO   rP   rA   Ô  s    c             C   s   | j jƒ jdƒS )Nzfile:)rš   r  r‚   )r1  rO   rO   rP   rB   Ù  s    c             C   s   t | jƒ}tjj|ƒS )z’Return whether a file:// Link points to a directory.

    ``link`` must not have any other scheme but file://. Call is_file_url()
    first.

    )r=   Úurl_without_fragmentrK   r#  Úisdir)r1  Ú	link_pathrO   rO   rP   Ú
is_dir_urlÞ  s    
r:  c             O   s   | S )NrO   )Úiterablerï   rÈ   rO   rO   rP   Ú_progress_indicatorê  s    r<  c                sD  yt ˆjd ƒ}W n tttfk
r0   d}Y nX tˆddƒ}tjƒ tj	krRd}n&|r\d}n|dkrjd}n|std}nd}|j
}‡fdd	„}	‡ fd
d„}
t}|jtjkr¬|}n|j}|rèt||d�}|rÚtjd|t|ƒƒ ntjd|ƒ n |� rütjd|ƒ ntjd|ƒ tjd|ƒ |
||	tƒtƒƒ}|�r8|j|ƒ nt|ƒ d S )Nzcontent-lengthr   Ú
from_cacheFé(   iè  Tc             3   s\   y$xˆ j j| dd�D ]
}|V  qW W n2 tk
rV   xˆ j j| ƒ}|sHP |V  q6W Y nX d S )NF)Údecode_content)r¿   rã   r“   r  )Ú
chunk_sizeÚchunk)rÇ   rO   rP   Ú	resp_read	  s    z _download_url.<locals>.resp_readc             3   s"   x| D ]}ˆ j |ƒ |V  qW d S )N)Úwrite)ÚchunksrA  )Úcontent_filerO   rP   Úwritten_chunks.  s    

z%_download_url.<locals>.written_chunks)ÚmaxzDownloading %s (%s)zDownloading %szUsing cached %szDownloading from URL %si@œ  )Úintrà   r+  ÚKeyErrorr  Úgetattrr”   ÚgetEffectiveLevelÚloggingÚINFOÚshow_urlr<  rª   r   r7  r.   rÍ   r$   r•   r   Úcheck_against_chunksr"   )rÇ   r1  rE  ÚhashesÚprogress_barÚtotal_lengthÚcached_respÚshow_progressrN  rB  rF  Úprogress_indicatorrš   Údownloaded_chunksrO   )rE  rÇ   rP   Ú_download_urlî  sL    
%rW  c             C   sÎ   d}t jj||jƒ}t jj|ƒrªtdt|ƒ dƒ}|dkr@d}nj|dkrdtjdt|ƒƒ t j	|ƒ nF|dkr˜t
|ƒ}tjd	t|ƒt|ƒƒ tj||ƒ n|dkrªtjdƒ |rÊtj| |ƒ tjdt|ƒƒ d S )NTz8The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abortÚiÚwÚbÚaFzDeleting %szBacking up %s to %srf   zSaved %s)rX  rY  rZ  r[  éÿÿÿÿ)rK   r#  r�   ÚfilenameÚexistsr    r#   r”   r™   Úremover!   ÚshutilÚmover~   ÚexitÚcopyrÍ   )r]  r2  r1  rc  Údownload_locationr°   Ú	dest_filerO   rO   rP   Ú
_copy_fileT  s.    

rf  Úonc       
      C   sž   |d krt dƒ‚tdd��z}d }|r0t| ||ƒ}|rH|}tj|ƒd }	nt| ||j||ƒ\}}	t|||	| ƒ |r‚| r‚t||| ƒ |s�t	j
|ƒ W d Q R X d S )Nz@unpack_http_url() missing 1 required keyword argument: 'session'r0  )Úkindr   )r  r,   Ú_check_download_dirrÝ   rÞ   Ú_download_http_urlr#  r+   rf  rK   Úunlink)
r1  r2  Údownload_dirr!  rP  rQ  Útemp_dirÚalready_downloaded_pathÚ	from_pathrë   rO   rO   rP   rC   o  s,    	

c             C   s®   t | jƒ}t| ƒrHtjj|ƒr&t|ƒ tj||dd� |rDt	j
dƒ dS |rV|j|ƒ d}|rjt| ||ƒ}|rt|}n|}tj|ƒd }t|||| ƒ |rª| rªt||| ƒ dS )z‘Unpack link into location.

    If download_dir is provided and link points to a file, make a copy
    of the link file inside download_dir.
    T)Úsymlinksz*Link is a directory, ignoring download_dirNr   )r=   r7  r:  rK   r#  r8  r(   r`  Úcopytreer”   rÍ   Úcheck_against_pathri  rÝ   rÞ   r+   rf  )r1  r2  rl  rP  r9  rn  ro  rë   rO   rO   rP   r@   œ  s,    



c               @   s$   e Zd ZdZddd„Zd	dd„ZdS )
ÚPipXmlrpcTransportzRProvide a `xmlrpclib.Transport` implementation via a `PipSession`
    object.
    Fc             C   s*   t jj| |ƒ tj|ƒ}|j| _|| _d S )N)r   Ú	Transportr£   r¼   r½   r"  Ú_schemeÚ_session)r¢   r«   r!  Úuse_datetimeÚindex_partsrO   rO   rP   r£   ×  s    
zPipXmlrpcTransport.__init__c       
      C   s�   | j ||d d d f}tj|ƒ}y6ddi}| jj|||dd�}|jƒ  || _| j|jƒS  t	j
k
rŠ }	 ztjd|	jj|ƒ ‚ W Y d d }	~	X nX d S )NzContent-Typeztext/xmlT)rx   rà   rã   zHTTP error %s while getting %s)ru  r¼   Ú
urlunparserv  Úpostr  ÚverboseÚparse_responser¿   r   Ú	HTTPErrorr”   Úcriticalr°   r»   )
r¢   r  ÚhandlerÚrequest_bodyr{  Úpartsrš   rà   r°   r›   rO   rO   rP   r   Ý  s    


zPipXmlrpcTransport.requestN)F)F)rÐ   rÑ   rÒ   rô   r£   r   rO   rO   rO   rP   rs  Ò  s   
rs  Fc             C   s`   t | ƒrt| |ƒ n<t| ƒr.t| |||d� n"|dkr<tƒ }t| |||||d� |r\t|ƒ dS )av  Unpack link.
       If link is a VCS link:
         if only_download, export into download_dir and ignore location
          else unpack into location
       for other types of link:
         - unpack into location
         - if download_dir, copy the file into download_dir
         - if only_download, mark location for deletion

    :param hashes: A Hashes object, one of whose embedded hashes must match,
        or HashMismatch will be raised. If the Hashes is empty, no matches are
        required, and unhashable types of requirements (like VCS ones, which
        would ordinarily raise HashUnsupported) are allowed.
    )rP  N)rP  rQ  )rA   r?   rB   r@   rü   rC   r   )r1  r2  rl  Úonly_downloadr!  rP  rQ  rO   rO   rP   rD   ï  s    c             C   s   t jj| ƒS )zJ
    Sanitize the "filename" value from a Content-Disposition header.
    )rK   r#  Úbasename)r]  rO   rO   rP   rF      s    c             C   s,   t j| ƒ\}}|jdƒ}|r$t|ƒ}|p*|S )zƒ
    Parse the "filename" value from a Content-Disposition header, and
    return the default filename if the result is empty.
    r]  )ÚcgiÚparse_headerrŒ   rF   )Úcontent_dispositionZdefault_filenameÚ_typeÚparamsr]  rO   rO   rP   rE   (  s
    
c             C   s,  | j jddƒd }y |j|ddidd�}|jƒ  W n8 tjk
rj } ztjd|jj	| ƒ ‚ W Y d	d	}~X nX |j
jd
dƒ}| j}	|j
jdƒ}
|
ršt|
|	ƒ}	t|	ƒd }|sÀtj|ƒ}|rÀ|	|7 }	| rð| j |j krðtjj|j ƒd }|rð|	|7 }	tjj||	ƒ}t|dƒ�}t|| |||ƒ W d	Q R X ||fS )z6Download link url into temp_dir using provided sessionú#rf   r   zAccept-EncodingÚidentityT)rà   rã   zHTTP error %s while getting %sNzcontent-typerº   zcontent-dispositionÚwb)rš   r  rŒ   r  r   r}  r”   r~  r°   r»   rà   r]  rE   r*   rÝ   Úguess_extensionrK   r#  r�   rá   rW  )r1  r!  rm  rP  rQ  Ú
target_urlrÇ   r›   rë   r]  r†  r.  Ú	file_pathrE  rO   rO   rP   rj  7  s:    	

rj  c             C   sn   t jj|| jƒ}t jj|ƒrjtjd|ƒ |rfy|j|ƒ W n* tk
rd   tj	d|ƒ t j
|ƒ dS X |S dS )z† Check download_dir for previously downloaded file with correct hash
        If a correct file is found return its path else None
    zFile was already downloaded %sz;Previously-downloaded file %s has bad hash. Re-downloading.N)rK   r#  r�   r]  r^  r”   rÍ   rr  r   r™   rk  )r1  rl  rP  Údownload_pathrO   rO   rP   ri  v  s    
ri  )rG   rH   rI   rJ   )NN)NNNrg  )NN)NFNNrg  )’Ú
__future__r   r„  Úemail.utilsrÙ   ry   rL  rÝ   rK   r{   Úrer`  r~   rƒ   r   r   Zpip._vendor.cachecontrolr   Úpip._vendor.cachecontrol.cachesr   Zpip._vendor.lockfiler   Úpip._vendor.requests.adaptersr   r	   Zpip._vendor.requests.authr
   r   Zpip._vendor.requests.modelsr   r   Zpip._vendor.requests.structuresr   Zpip._vendor.requests.utilsr   Zpip._vendor.six.movesr   Zpip._vendor.six.moves.urllibr   r¼   r   r,  rU   Zpip._internal.exceptionsr   r   Zpip._internal.models.indexr   Zpip._internal.utils.compatr   r   Zpip._internal.utils.encodingr   Zpip._internal.utils.filesystemr   Zpip._internal.utils.glibcr   Z pip._internal.utils.marker_filesr   Zpip._internal.utils.miscr   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   Zpip._internal.utils.temp_dirr,   Zpip._internal.utils.typingr-   Zpip._internal.utils.uir.   Zpip._internal.vcsr/   Útypingr0   r1   r2   r3   r4   r5   Úoptparser6   Zpip._internal.models.linkr7   Zpip._internal.utils.hashesr8   Z pip._internal.vcs.versioncontrolr9   r:   r_   ZCredentialsÚ__all__Ú	getLoggerrÐ   r”   r‘   ÚImportErrorr˜   r›   r™   rS   rT   r�   rœ   r�   rÓ   rì   rö   ÚSessionrü   r;   ÚcompileÚIr  r  r<   r=   r>   r?   r/  rA   rB   r:  r<  rW  rf  rC   r@   rt  rs  rD   rF   rE   rj  ri  rO   rO   rO   rP   Ú<module>   sÈ   H 

   O Q!BQ
/		f   
* 
2     
*?