Your IP : 18.119.118.151


Current Path : /opt/alt/python34/lib/python3.4/site-packages/pip/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib/python3.4/site-packages/pip/__pycache__/download.cpython-34.pyc

�
�Re4X�
@sMddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZmZddlmZmZddlmZmZmZmZmZmZmZmZmZddlmZddl m!Z!ddl"m#Z#m$Z$ddl%m&Z&dd	l'm(Z(m)Z)dd
l*m+Z+ddl,m-Z-m.Z.ddl/m0Z0dd
l1m2Z2ddddddddddg
Z3dd�Z4Gdd�de(�Z5Gdd�de6�Z7Gdd�de&�Z8Gd d!�d!e#j9�Z:ddd"d�Z;ej<d#ej=�Z>ej<d$ej=�Z?d%d�Z@d&d�ZAej<d'ej=�ZBej<d(ej=�ZCd)d�ZDd*d�ZEd+d,d�ZFd-d.�ZGd/d�ZHd0d�ZId1d2�ZJd3d4�ZKd5d6�ZLd7d8�ZMddd9d�ZNdd:d�ZOdS);�N)�urllib�urlparse�	raw_input)�InstallationError�HashMismatch)	�splitext�rmtree�format_size�display_path�
backup_dir�ask_path_exists�unpack_file�create_download_cache_folder�cache_download)�vcs)�logger)�requests�six)�BaseAdapter)�AuthBase�
HTTPBasicAuth)�IncompleteRead)�
InvalidURL�ChunkedEncodingError)�Response)�CaseInsensitiveDict�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_urlcCs5tj�}|dkr'tj�}n�|dkr�dtjjtjjtjjf}tjjdkr�dj	|tjjg�}q�n<|dkr�tj�}n!|dkr�tj�}nd}ytj
�}tj�}Wntk
rd}d}YnXd	j	d
t
jd||fd||fg�S)z,Return a string representing the user agent.�CPython�PyPyz%s.%s.%s�final��Jython�
IronPython�Unknown� zpip/%sz%s/%s)�platform�python_implementation�python_version�sys�pypy_version_info�major�minor�micro�releaselevel�join�system�release�IOError�pip�__version__)�_implementation�_implementation_version�p_system�	p_release�rA�'/tmp/pip-ztkk0jow-build/pip/download.py�
user_agent$s2	

rCc@sCeZdZddd�Zdd�Zdd�Zdd	�Zd
S)�MultiDomainBasicAuthTcCs||_i|_dS)N)�	prompting�	passwords)�selfrErArArB�__init__Hs	zMultiDomainBasicAuth.__init__cCs�tj|j�}|jjdd�d}tj|dd�|f|dd��|_|jj|d�\}}|dkr�|j|j�\}}n|s�|r�||f|j|<t|p�d|p�d�|�}n|j	d|j
�|S)N�@��r)�response���)NN)r�url�netloc�split�
urlunparserF�get�parse_credentialsr�
register_hook�
handle_401)rG�req�parsedrO�username�passwordrArArB�__call__Ls1$zMultiDomainBasicAuth.__call__cKs�|jdkr|S|js |Stj|j�}td|j�}tjd�}|s`|ry||f|j|j<n|j|j	j
�t|p�d|p�d�|j�}|j
j||�}|jj|�|S)Ni�z
User for %s: z
Password: r))�status_coderErrNrrO�getpassrF�content�raw�release_connr�request�
connection�send�history�append)rG�resp�kwargsrWrXrYrV�new_resprArArBrUhs	
$zMultiDomainBasicAuth.handle_401cCsLd|krH|jdd�d}d|kr>|jdd�S|dfSdS)NrIrJr�:)NN)�rsplitrP)rGrO�userinforArArBrS�s
z&MultiDomainBasicAuth.parse_credentialsN)�__name__�
__module__�__qualname__rHrZrUrSrArArArBrDFs"rDc@sOeZdZdd�Zdd�Zddddd�Zed	d
��ZdS)�LocalFSResponsecCs
||_dS)N)�fileobj)rGrorArArBrH�szLocalFSResponse.__init__cCst|j|�S)N)�getattrro)rG�namerArArB�__getattr__�szLocalFSResponse.__getattr__NFcCs|jj|�S)N)ro�read)rG�amt�decode_content�
cache_contentrArArBrs�szLocalFSResponse.readcs9Gdd�dt��G�fdd�dt�}|�S)Nc@s(eZdZdd�Zdd�ZdS)z7LocalFSResponse._original_response.<locals>.FakeMessagecSsgS)NrA)rG�headerrArArB�
getheaders�szBLocalFSResponse._original_response.<locals>.FakeMessage.getheaderscSsgS)NrA)rGrw�defaultrArArB�get_all�sz?LocalFSResponse._original_response.<locals>.FakeMessage.get_allN)rkrlrmrxrzrArArArB�FakeMessage�sr{cs(eZdZe�fdd��ZdS)z8LocalFSResponse._original_response.<locals>.FakeResponsecs��S)NrA)rG)r{rArB�msg�sz<LocalFSResponse._original_response.<locals>.FakeResponse.msgN)rkrlrm�propertyr|rA)r{rArB�FakeResponse�sr~)�object)rGr~rA)r{rB�_original_response�sz"LocalFSResponse._original_response)rkrlrmrHrrrsr}r�rArArArBrn�srnc@s7eZdZddddddd�Zdd�ZdS)�LocalFSAdapterNc
Cstj|j�}|jj�dkr=td|j��ntj|dd�d|dd��}t|�}	t�}
d|
_||
_t	j
|	�}tjj
|jdd�}titj|	�d	p�d
d6|jd6|d
6�|
_tt|	d��|
_|
jj|
_|
S)N�	localhostz)Invalid URL %r: Only localhost is allowedrJr)rK���usegmtTrz
text/plainzContent-TypezContent-Lengthz
Last-Modified�rb)r))rrNrO�lowerrrQrrr[�os�stat�email�utils�
formatdate�st_mtimer�	mimetypes�
guess_type�st_size�headersrn�openr^�close)
rGr`�stream�timeout�verify�cert�proxies�
parsed_url�real_url�pathnamere�stats�modifiedrArArBrb�s$+			
zLocalFSAdapter.sendcCsdS)NrA)rGrArArBr��szLocalFSAdapter.close)rkrlrmrbr�rArArArBr��sr�cs:eZdZdZ�fdd�Z�fdd�Z�S)�
PipSessionNcsLtt|�j||�t�|jd<t�|_|jdt��dS)Nz
User-Agentzfile://)	�superr�rHrCr�rD�auth�mountr�)rG�argsrf)�	__class__rArBrH�szPipSession.__init__cs~tj|�}|jdkrLtj|dd�d|dd��}n|jd|j�tt|�j||||�S)N�filerJr�rKr�)z	localhost)r�schemerQ�
setdefaultr�r�r�r`)rG�methodrNr�rfrW)r�rArBr`�s
.zPipSession.request)rkrlrmr�rHr`rArA)r�rBr��sr�c
Cs�|dkrt�}ntj|�}|rq|jd�j�}|dkr||r||jd�r|td||f��n|dkr,|jdd�d}|jdd�}t	j
|�}|r�|jd�d|jd	d�d}ntj|�}|jd�r#d|j
d�}n|}qq|j|�}|j�tjr^|j|jfS|j|jfSnyt|�}|j�}Wn8tk
r�tj�d}	td
t|	���YnX|j�||fS)z�Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.NrJr��httpz6Requirements file %s references URL %s, which is localrh�\�/�|z$Could not open requirements file: %s)r��
_scheme_re�search�groupr��
startswithrrP�replace�_url_slash_drive_re�matchr�unquote�lstriprR�raise_for_statusr�PY3rN�textr]r�rsr:r1�exc_info�strr�)
rN�
comes_from�sessionr�r��pathre�fr]�erArArBr�sB*	
	

z^(http|https|file):z/*([a-z])\|cCsId|krdS|jdd�dj�}|ddddgtjkS)	z)Returns true if the name looks like a URLrhFrJrr��httpsr��ftp)rPr�r�all_schemes)rqr�rArArBr scCs�|jd�std|��|td�d�jd�}tj|�}tj|�r{|dd|dd�}n
d|}|S)z(
    Convert a file: URL to a path.
    zfile:z4You can only turn file: urls into filenames (not %r)Nr�rrhrK)r��AssertionError�lenr�rr��
_url_drive_rer�)rNr�rArArBr(s

z	^([a-z]):z^([a-z])[:|]cCs�tjjtjj|��}tjj|�\}}|jtjj�}djdd�|D��}|s|jd�}nd||S)zh
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    r�cSsg|]}tj|��qSrA)r�quote)�.0�partrArArB�
<listcomp>Cs	zpath_to_url.<locals>.<listcomp>zfile:///)	r�r��normpath�abspath�
splitdriverP�sepr7r�)r��drive�filepathrNrArArBr;scCs0d}t|�dj�}||kr,d	Sd
S)z9Return True if `name` is a considered as an archive file.�.zip�.tar.gz�.tar.bz2�.tgz�.tar�	.pybundle�.whlrJTF)r�r�r�r�r�r�r�)rr�)rq�archives�extrArArBr IsFcCs3t|�}|r"|j|�n
|j|�dS)N)�_get_used_vcs_backend�export�unpack)�link�location�
only_download�vcs_backendrArArBr!SscCs=x6tjD]+}|j|jkr
||j�}|Sq
WdS)N)r�backendsr��schemesrN)r��backendr�rArArBr�[sr�cCstt|��S)N)�boolr�)r�rArArBr#bscCs|jj�jd�S)Nzfile:)rNr�r�)r�rArArBr$fscCs�|jtj|j�jkrQtjd|j||jf�td|��n|j�|jkr�tjd||j�|jf�td|j|f��ndS)NzPHash digest size of the package %d (%s) doesn't match the expected hash name %s!z!Hash name mismatch for package %sz?Hash of the package %s (%s) doesn't match the expected hash %s!zBad %s hash for package %s)	�digest_size�hashlib�new�	hash_namer�fatalr�	hexdigest�hash)�
download_hashr�rArArB�_check_hashjs		r�cCs�ytj|j�}Wn6ttfk
rNtjd|j|f�dSYnXt|d�}x*|jd�}|szPn|j	|�qaW|j
�|S)Nz'Unsupported hash name %s for package %sr�i)r�r�r��
ValueError�	TypeErrorr�warnr�rs�updater�)�target_filer�r��fp�chunkrArArB�_get_hash_from_fileus	
r�cst|d�}d}|jro|jroytj|j�}Wqotk
rktjd|j|f�YqoXnyt�j	d�}Wn!tt
tfk
r�d}YnXd}|dkp�|}|j}z |r|r�tj
d|t|�f�q tj
d|�ntjd	|�tjd
|��fdd�}	x�|	d
�D]�}
|t|
�7}|r�|s�tjdt|��q�tjdd||t|�f�n|dk	r�|j|
�n|j|
�qPW|j�Wd|rtjdt|��nX|S)N�wbz'Unsupported hash name %s for package %szcontent-lengthr�(i�zDownloading %s (%s): zDownloading %s (unknown size): zDownloading %szDownloading from URL %sc3s�ydy,x%�jj|dd�D]}|VqWWn1tk
rb}zt|��WYdd}~XnXWn:tk
r�x%�jj|�}|s�Pn|VqwWYnXdS)NruF)r^r�rr�AttributeErrorrs)�
chunk_sizer�r�)rerArB�	resp_read�s
#
z _download_url.<locals>.resp_readiz%sz	%3i%%  %s�dz
%s downloadedi@�)r�r�r�r�r�r�rr��intr��KeyErrorr��show_url�start_progressr	�notify�infor��
show_progressr��writer��end_progress)rer��
temp_locationr�r��total_length�
downloadedr�r�r�r�rA)rerB�
_download_url�sF
"	 (rcCsd}tjj||j�}tjj|�r�tdt|�d
�}|dkr^d}q�|dkr�tjdt|��tj	|�q�|dkr�t
|�}tjdt|�t|�f�tj||�q�n|rtj
||�tjd	t|��ndS)NTz/The file %s exists. (i)gnore, (w)ipe, (b)ackup �i�w�bFzDeleting %szBacking up %s to %szSaved %s)rrr)r�r�r7�filename�existsrr
rr��remover�shutil�move�copyr�)r	r��content_typer�r�download_locationrL�	dest_filerArArB�
_copy_file�s&		rc)Cs�|dkrt�}ntjdd�}d}|jjdd�d}d}d}	d}
d}|r�tjj|tj	|d��}	|	d}
tjj
|	�o�tjj
|
�}tjj|�s�t|�q�nd}|rtjj||j
�}tjj
|�sd}qn|r�|}tj|�d}
tjd	|�|jr�t||�}yt||�Wq�tk
r�tjd
|�d}tj|�d}Yq�Xq�n|r�|r�t|
��}|j�j�}
WdQX|	}tjd|	�|jr�|jr�t|	|�}yt||�Wq�tk
r�tjd|�d}tj|	�tj|
�d}Yq�Xq�n|s-y#|j|d
d�}|j�WnHtjk
r�}z%tj d|j!j"|f��WYdd}~XnX|j#jdd�}
|j
}|j#jd�}|r^t$j%|�\}}|jd�pX|}nt&|�d}|s�tj'|
�}|r�||7}q�n|r�|j|jkr�tjj&|j�d}|r�||7}q�ntjj||�}t(|||�}|jr-|jr-t||�q-n|rP|rPt)|||
|�nt*|||
|�|	r�|r�t+|	||
�n|p�|s�tj|�ntj,|�dS)Nz-unpackzpip-�#rJrFr)z
.content-typezFile was already downloaded %sz;Previously-downloaded file %s has bad hash, re-downloading.zUsing download cache from %sz,Cached file %s has bad hash, re-downloading.r�TzHTTP error %s while getting %szcontent-typezcontent-dispositionr	)-r��tempfile�mkdtemprNrPr�r�r7rr�r
�isdirrr	r�r�rr�r�r�r�rr��unlinkr�rs�stripr�rRr�r�	HTTPErrorr�rLr[r��cgi�parse_headerr�guess_extensionrrr
r�rmdir)r�r��download_cache�download_dirr��temp_dirr�
target_url�already_cached�
cache_file�cache_content_type_filer��already_downloadedrr�re�excr	�content_disposition�type�paramsr�rArArBr%�s�
	





		

c

Cs�t|j�}d}tjj|�r`tjj|�rFt|�ntj||dd�dS|jr�t	||�}t
||�n|rMtjj||j�}tjj
|�rMtj|�d}tjd|�|jrAt	||�}yt
||�d}WqGtk
r=tjd|�tj|�YqGXqJd}qMn|r\|}	n|}	tj|	�d}t|	|||�|r�|r�t|	|||�ndS)NF�symlinksTrzFile was already downloaded %sz;Previously-downloaded file %s has bad hash, re-downloading.)r�url_without_fragmentr�r�rrr�copytreer�r�r�r7r	r
r�r�rr�rr�rr
r)
r�r�r�	link_pathr%�link_path_hash�
download_pathrr��	from_pathrArArBr"RsB
		


	
)Pr�email.utilsr�r�r\r�r�r.�rerr1rr;Zpip.backwardcompatrrr�pip.exceptionsrr�pip.utilrrr	r
rrr
rr�pip.vcsr�pip.logr�pip._vendorrrZpip._vendor.requests.adaptersrZpip._vendor.requests.authrrZpip._vendor.requests.compatrZpip._vendor.requests.exceptionsrrZpip._vendor.requests.modelsrZpip._vendor.requests.structuresr�__all__rCrDrrnr��Sessionr�r�compile�Ir�r�rr�	_drive_rer�rr r!r�r#r$r�r�rrr%r"rArArArB�<module>sh@	"M#,
<y

?>