???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
PfO                 @   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Zd dlZyd dlZdZW n ek
r   dZY nX 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	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) d dl*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZA d dlBmCZCmDZD d dlEmFZF d dlGmHZH d dl9mIZI d dlJmKZK d dlLmMZM d dlNmOZO d dlPmQZQ dddd d!d"d#d$d%d&d'd(d)gZRejSeTZUd*d+ ZVG d,d- d-e@ZWG d.d/ d/e=ZXG d0d1 d1eMZYG d2d3 d3e>ZZG d4d5 d5e:j[Z\dWd6dZ]ej^d7ej_Z`ej^d8ej_Zad9d Zbd:d Zcd;d  Zdd<d! Zed=d" Zfd>d? Zgd@d$ ZhdAd% ZidBdC ZjdDdE ZkdFdG ZldHdI ZmdXdJd&ZndYdKd#ZodLdM ZpG dNdO dOeQjqZrdZdPd'ZsdQd) ZtdRd( ZudSdT ZvdUdV ZwdS )[    )absolute_importNTF)parse)request)InstallationErrorHashMismatch)PyPI)
splitextrmtreeformat_sizedisplay_path
backup_dirask_path_existsunpack_fileARCHIVE_EXTENSIONSconsumecall_subprocess)auto_decode)check_path_owner)
indent_log)SETUPTOOLS_SHIM)libc_ver)DownloadProgressBarDownloadProgressSpinner)write_delete_marker_file)vcs)requestssix)BaseAdapterHTTPAdapter)AuthBaseHTTPBasicAuth)CONTENT_CHUNK_SIZEResponse)get_netrc_auth)CaseInsensitiveDict)urllib3)CacheControlAdapter)	FileCache)	LockError)xmlrpc_clientget_file_contentis_urlurl_to_pathpath_to_url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_filenamec              C   s  dt jdtj dtj id} | d d dkrBtj | d d< n| d d dkrtjjd	krntjd
d }ntj}djdd |D | d d< nB| d d dkrtj | d d< n | d d dkrt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 rtj | jdi d< tj rtj | jdi d< tj rtj | d< trtjd
d  d)krtj| d"< d#j| tj| d*d&d'd(S )+z6
    Return a string representing the user agent.
    pip)nameversionr8   )Z	installerpythonimplementationr;   ZCPythonr9   ZPyPyfinalN   .c             S   s   g | ]}t |qS  )str).0xr?   r?   /usr/lib/python3.6/download.py
<listcomp>T   s    zuser_agent.<locals>.<listcomp>ZJythonZ
IronPythonlinuxr   )distroc             S   s   | d S )N   r?   )rB   r?   r?   rC   <lambda>`   s    zuser_agent.<locals>.<lambda>idc             S   s   | d S )NrG   r?   )rB   r?   r?   rC   rH   d   s    liblibcrF   darwinZmacOSsystemreleaseZcpu      Zopenssl_versionz9{data[installer][name]}/{data[installer][version]} {json},:T)Z
separatorsZ	sort_keys)datajson)rO   rP   )rQ   rR   )r7   __version__platformZpython_versionZpython_implementationsyspypy_version_inforeleaseleveljoin
startswithpip._vendorrF   dictfilterzipZlinux_distributionr   Zmac_verrM   
setdefaultrN   machineHAS_TLSversion_infosslZOPENSSL_VERSIONformatrT   dumps)rS   rX   rF   Zdistro_infosrK   r?   r?   rC   
user_agent@   sP    




rg   c               @   s.   e Zd ZdddZdd Zdd Zdd	 Zd
S )MultiDomainBasicAuthTc             C   s   || _ i | _d S )N)	prompting	passwords)selfri   r?   r?   rC   __init__   s    zMultiDomainBasicAuth.__init__c             C   s   t j|j}|jjddd }t j|d d |f |dd   |_| jj|d\}}|d krn| j|j\}}|d kr|d krt	|j}|r|nd\}}|s|r||f| j|< t
|pd|pd|}|jd| j |S )	N@rG   rO    response)NN)NN)urllib_parseurlparseurlnetlocrsplit
urlunparserj   getparse_credentialsr#   r    Zregister_hook
handle_401)rk   reqparsedrt   usernamepasswordZ
netrc_authr?   r?   rC   __call__   s    &
zMultiDomainBasicAuth.__call__c             K   s   |j dkr|S | js|S tj|j}tjjd|j }t	j	d}|sH|rX||f| j
|j< |j |jj  t|ppd|pvd|j}|jj|f|}|jj| |S )Ni  zUser for %s: z
Password: rn   )status_coderi   rq   rr   rs   r   Zmovesinputrt   getpassrj   contentrawZrelease_connr    r   Z
connectionsendhistoryappend)rk   respkwargsr{   r|   r}   rz   Znew_respr?   r?   rC   ry      s    


zMultiDomainBasicAuth.handle_401c             C   s8   d|kr4|j ddd }d|kr,|jddS |d fS dS )Nrm   rG   r   rR   )NN)ru   split)rk   rt   Zuserinfor?   r?   rC   rx      s    z&MultiDomainBasicAuth.parse_credentialsN)T)__name__
__module____qualname__rl   r~   ry   rx   r?   r?   r?   rC   rh      s   
!"rh   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)Zusegmtr   z
text/plain)zContent-TypezContent-LengthzLast-Modifiedrb)r,   rs   r"   r   osstatOSErrorr   emailZutilsZ
formatdatest_mtime	mimetypes
guess_typer$   st_sizeheadersopenclose)rk   r   streamtimeoutverifycertZproxiespathnamer   ZstatsexcZmodifiedcontent_typer?   r?   rC   r      s$    

zLocalFSAdapter.sendc             C   s   d S )Nr?   )rk   r?   r?   rC   r      s    zLocalFSAdapter.close)NNNNN)r   r   r   r   r   r?   r?   r?   rC   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 )NzThe 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   rl   r   	directoryloggerwarning)rk   argsr   )	__class__r?   rC   rl      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   rw   r(   r   IOError)rk   r   r   )r   r?   rC   rw     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   )rk   r   r   )r   r?   rC   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   )rk   r   r   )r   r?   rC   r   )  s    
zSafeFileCache.delete)	r   r   r   __doc__rl   rw   r   r   __classcell__r?   r?   )r   rC   r      s
   r   c               @   s   e Zd Zdd ZdS )InsecureHTTPAdapterc             C   s   d|_ d |_d S )NZ	CERT_NONE)Z	cert_reqsZca_certs)rk   Zconnrs   r   r   r?   r?   rC   cert_verify9  s    zInsecureHTTPAdapter.cert_verifyN)r   r   r   r   r?   r?   r?   rC   r   7  s   r   c                   s,   e Zd ZdZ fddZ fddZ  ZS )
PipSessionNc       	         s   |j dd}|j dd }|j dg }tt| j|| t | jd< t | _tj	|dgdd}|rvt
t|d	d
|d}n
t|d}t|d}| jd| | jd| | jdt  x|D ]}| jdj|| qW d S )Nretriesr   cacheinsecure_hostsz
User-Agenti  g      ?)ZtotalZstatus_forcelistZbackoff_factorT)Zuse_dir_lock)r   max_retries)r   zhttps://zhttp://zfile://zhttps://{0}/)popr   r   rl   rg   r   rh   Zauthr%   ZRetryr&   r   r   r   Zmountr   re   )	rk   r   r   r   r   r   Zsecure_adapterZinsecure_adapterhost)r   r?   rC   rl   B  s*    




zPipSession.__init__c                s(   |j d| j tt| j||f||S )Nr   )r`   r   r   r   r   )rk   methodrs   r   r   )r   r?   rC   r   ~  s    zPipSession.request)r   r   r   r   rl   r   r   r?   r?   )r   rC   r   >  s   <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	rd	|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 )zGets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.NzAget_file_content() missing 1 required keyword argument: 'session'rG   filehttpz6Requirements file %s references URL %s, which is localrR   \/|r   z$Could not open requirements file: %s)	TypeError
_scheme_researchgrouplowerr[   r   r   replace_url_slash_drive_rematchrq   Zunquotelstriprw   raise_for_statusrs   textr   r   readr   r@   )
rs   Z
comes_fromsessionr   schemepathr   fr   r   r?   r?   rC   r*     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 URLrR   FrG   r   r   Zhttpsr   Zftp)r   r   r   Zall_schemes)r8   r   r?   r?   rC   r+     s    c             C   sH   | j dstd|  tj| \}}}}}|r6d| }tj|| }|S )z(
    Convert a file: URL to a path.
    zfile:z4You can only turn file: urls into filenames (not %r)z\\)r[   AssertionErrorrq   Zurlspliturllib_requestZurl2pathname)rs   _rt   r   r?   r?   rC   r,     s    
c             C   s*   t jjt jj| } tjdtj| }|S )zh
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    zfile:)r   r   normpathabspathrq   Zurljoinr   Zpathname2url)r   rs   r?   r?   rC   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.rG   TF)r   r   r   )r8   extr?   r?   rC   r.     s    c             C   s   t | }|j| d S )N)_get_used_vcs_backendunpack)linklocationvcs_backendr?   r?   rC   r/     s    c             C   s.   x(t jD ]}| j|jkr|| j}|S qW d S )N)r   Zbackendsr   Zschemesrs   )r   Zbackendr   r?   r?   rC   r     s    
r   c             C   s   t t| S )N)boolr   )r   r?   r?   rC   r1     s    c             C   s   | j j jdS )Nzfile:)rs   r   r[   )r   r?   r?   rC   r2     s    c             C   s   t | j}tjj|S )zReturn 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_fragmentr   r   isdir)r   	link_pathr?   r?   rC   
is_dir_url  s    
r   c             O   s   | S )Nr?   )iterabler   r   r?   r?   rC   _progress_indicator  s    r   c                sL  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|rtjd|t| t|dj}
ntjd| t j}
n |rtjd| ntjd| tjd| |	|
|tt}|r@|j| nt| d S )Nzcontent-lengthr   Z
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)Zdecode_content)r   r   AttributeErrorr   )Z
chunk_sizechunk)r   r?   rC   	resp_read  s    z _download_url.<locals>.resp_readc             3   s"   x| D ]} j | |V  qW d S )N)write)Zchunksr   )content_filer?   rC   written_chunks;  s    

z%_download_url.<locals>.written_chunkszDownloading %s (%s))maxzDownloading %szUsing cached %szDownloading from URL %si@  )intr   
ValueErrorKeyErrorr   getattrr   ZgetEffectiveLevelloggingINFOshow_urlr   rt   r   r   infor
   r   iterr   debugr!   Zcheck_against_chunksr   )r   r   r   hashesZtotal_lengthZcached_respZshow_progressr   r   r   Zprogress_indicatorrs   Zdownloaded_chunksr?   )r   r   rC   _download_url  sL    
%
r   c             C   s   d}t jj||j}t jj|rtdt| d}|dkr@d}nj|dkrdtjdt| t j	| nF|dkrt
|}tjd	t|t| tj|| n|dkrtjd |rt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 %srG   zSaved %s)r   r   r   r   rp   )r   r   rZ   filenameexistsr   r   r   r   remover   shutilZmoverW   exitcopyr   )r   r   r   r   Zdownload_locationro   Z	dest_filer?   r?   rC   
_copy_filea  s.    

r   c       	      C   s   |d krt dtjdd}d }|r0t| ||}|rH|}tj|d }nt| |||\}}t||||  |r~| r~t|||  |st	j
| t| d S )Nz@unpack_http_url() missing 1 required keyword argument: 'session'z-unpackzpip-r   )r   tempfileZmkdtemp_check_download_dirr   r   _download_http_urlr   r   r   unlinkr	   )	r   r   download_dirr   r   temp_diralready_downloaded_path	from_pathr   r?   r?   rC   r3   |  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| rt|||  dS )zUnpack 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)Zsymlinksz*Link is a directory, ignoring download_dirNr   )r,   r   r   r   r   r   r	   r   Zcopytreer   r   check_against_pathr   r   r   r   r   )r   r   r  r   r   r  r  r   r?   r?   rC   r0     s,    



c             C   s   t jj|rt| d}tjg}|jd |jt|  |jd |d|g7 }tj	d|  t
  t|| dd W dQ R X t jj|t j|d	 }tj	d
|| t||ddd dS )zCopy distribution files in `link_path` to `location`.

    Invoked when user requests to install a local directory. E.g.:

        pip install .
        pip install ~/dev/git-repos/python-prompt-toolkit

    zsetup.pyz-csdistz
--dist-dirzRunning setup.py sdist for %sF)cwdZshow_stdoutNr   zUnpacking sdist %s into %s)r   r   )r   r   r   r	   rW   
executabler   r   r   r   r   r   rZ   listdirr   )r   r   Zsetup_pyZ
sdist_argsr  r?   r?   rC   _copy_dist_from_dir  s    

r  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)   	Transportrl   rq   rr   r   _scheme_session)rk   Z	index_urlr   Zuse_datetimeZindex_partsr?   r?   rC   rl     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)rS   r   r   zHTTP error %s while getting %s)r  rq   rv   r  Zpostr   verboseZparse_responser   r   	HTTPErrorr   criticalro   r   )
rk   r   ZhandlerZrequest_bodyr  partsrs   r   ro   r   r?   r?   rC   r     s    


zPipXmlrpcTransport.requestN)F)F)r   r   r   r   rl   r   r?   r?   r?   rC   r    s   
r  c             C   s^   t | rt| | n:t| r.t| |||d n |dkr<t }t| ||||d |rZt| 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.
    )r   N)r1   r/   r2   r0   r   r3   r   )r   r   r  Zonly_downloadr   r   r?   r?   rC   r4     s    c             C   s   t jj| S )zJ
    Sanitize the "filename" value from a Content-Disposition header.
    )r   r   basename)r   r?   r?   rC   r6   <  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   )cgiZparse_headerrw   r6   )content_dispositionZdefault_filenameZ_typeZparamsr   r?   r?   rC   r5   D  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}	|	rt|	|}t|d }
|
stj|}
|
r||
7 }|
 r| j |j krt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#rG   r   zAccept-EncodingZidentityT)r   r   zHTTP error %s while getting %sNzcontent-typern   zcontent-dispositionwb)rs   r   rw   r   r   r  r   r  ro   r   r   r   r5   r   r   Zguess_extensionr   r   rZ   r   r   )r   r   r  r   Z
target_urlr   r   r   r   r  r   Z	file_pathr   r?   r?   rC   r   S  s:    

r   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)r   r   rZ   r   r   r   r   r  r   r   r  )r   r  r   Zdownload_pathr?   r?   rC   r     s    
r   )NN)NNN)NN)NFNN)xZ
__future__r   r  Zemail.utilsr   r   rT   r   r   r   rV   rer   rW   r   rd   rb   ImportErrorZpip._vendor.six.moves.urllibr   rq   r   r   r7   Zpip.exceptionsr   r   Z
pip.modelsr   Z	pip.utilsr   r	   r
   r   r   r   r   r   r   r   Zpip.utils.encodingr   Zpip.utils.filesystemr   Zpip.utils.loggingr   Zpip.utils.setuptools_buildr   Zpip.utils.glibcr   Zpip.utils.uir   r   Zpip.locationsr   Zpip.vcsr   r\   r   r   Zpip._vendor.requests.adaptersr   r   Zpip._vendor.requests.authr   r    Zpip._vendor.requests.modelsr!   r"   Zpip._vendor.requests.utilsr#   Zpip._vendor.requests.structuresr$   r%   Zpip._vendor.cachecontrolr&   Zpip._vendor.cachecontrol.cachesr'   Zpip._vendor.lockfiler(   Zpip._vendor.six.movesr)   __all__Z	getLoggerr   r   rg   rh   r   r   r   ZSessionr   r*   compileIr   r   r+   r,   r-   r.   r/   r   r1   r2   r   r   r   r   r3   r0   r  r  r  r4   r6   r5   r   r   r?   r?   r?   rC   <module>   s   
0
BR!BH
)
` 
&
0$ 
'8