B
    '\                 @   s"  d dl mZmZmZmZ d dlZd dlmZmZ d dl	m
Z
mZmZ d dlZd dlZddl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lmZ d
dlmZ d
dl m!Z! d
dl"m#Z# d
dl$m%Z%m&Z&m'Z'm(Z(m)Z) ee*Z+dd Z,e#ddddZ-G dd de.Z/dS )    )absolute_importdivisionprint_functionunicode_literalsN)DEBUG	getLogger)basenameexistsjoin   )ConnectionError	HTTPErrorInsecureRequestWarningInvalidSchemaSSLError)CondaSession   )rm_rf   )
CondaError)dals)	stringify)context)	text_type)time_recorder)BasicClobberErrorCondaDependencyErrorCondaHTTPErrorMD5MismatchErrormaybe_raisec               C   s   t dt d S )Nignore)warningssimplefilterr    r#   r#   Alib/python3.7/site-packages/conda/gateways/connection/download.pydisable_ssl_verify_warning   s    r%   downloadc             C   s  t |rtt|| tt tjs&t  ytjtjf}t }|j	| d|j
|d}ttrltt|dd |  t|j	dd}td}yt|d}	d}
x|d	D ]}|j }
y|	| W n8 tk
r } zd
}t|||jdW d d }~X Y nX || |rd|
  kr(|krn q|r||
|  qW W d Q R X |rt|
|krttd}t|| |||
dW nD ttfk
r } z |jdkrtd|   W d d }~X Y nX |  }|r||krtd| |  |f  t!| |||W n t"k
rB } z&dt#|kr0td}t$|n W d d }~X Y nh t%t&t'fk
r } zBtd}t(|| t)|j*dd t)|j*dd t)|j*dd |j*|dW d d }~X Y nX d S )NT)streamproxiestimeout   )Zcontent_max_lenzContent-Lengthr   Zmd5wbi @  z5Failed to write to %(target_path)s
  errno: %(errno)d)target_patherrnoa  
                Downloaded bytes did not match Content-Length
                  url: %(url)s
                  target_path: %(target_path)s
                  Content-Length: %(content_length)d
                  downloaded bytes: %(downloaded_bytes)d
                )urlr,   content_lengthZdownloaded_bytesh   z%s, trying againz;MD5 sums mismatch for download: %s (%s != %s), trying againZSOCKSaQ  
                Requests has identified that your current working environment is configured
                to use a SOCKS proxy, but pysocks is not installed.  To proceed, remove your
                proxy configuration, run `conda install pysocks`, and then you can re-enable
                your proxy configuration.
                z
        An HTTP error occurred when trying to retrieve this URL.
        HTTP errors are often intermittent, and a simple retry will get you on your way.
        Zstatus_codereasonelapsed)Z	caused_by)+r	   r   r   r   Z
ssl_verifyr%   Zremote_connect_timeout_secsZremote_read_timeout_secsr   getr(   logZisEnabledForr   debugr   Zraise_for_statusintZheadershashlibnewopenZiter_contentrawtellwriteIOErrorr   r-   updater   OSErrorZ	hexdigestr   r   r   r   r   r   r   r   getattrZresponse)r.   Ztarget_full_pathZmd5sumZprogress_update_callbackr)   sessionZrespr/   Zdigest_builderZfhZstreamed_byteschunkemessageZactual_md5sumZhelp_messager#   r#   r$   r&      st    


"

c               @   s*   e Zd ZdZd
ddZdd Zdd Zd	S )TmpDownloadz;
    Context manager to handle downloads to a tempfile
    Tc             C   s   || _ || _d S )N)r.   verbose)selfr.   rF   r#   r#   r$   __init__   s    zTmpDownload.__init__c             C   sH   d| j krd | _| j S t | _t| jt| j }t| j |d  |S d S )Nz://)r.   tmp_dirtempfileZmkdtempr
   r   r&   )rG   dstr#   r#   r$   	__enter__   s    

zTmpDownload.__enter__c             C   s   | j rt| j  d S )N)rI   r   )rG   exc_type	exc_value	tracebackr#   r#   r$   __exit__   s    zTmpDownload.__exit__N)T)__name__
__module____qualname____doc__rH   rL   rP   r#   r#   r#   r$   rE   |   s   
rE   )N)0Z
__future__r   r   r   r   r7   Zloggingr   r   os.pathr   r	   r
   rJ   r!    r   r   r   r   r   rA   r   Zdisk.deleter   r   Z_vendor.auxlib.ishr   Z_vendor.auxlib.logzr   Zbase.contextr   Zcommon.compatr   Z	common.ior   
exceptionsr   r   r   r   r   rQ   r4   r%   r&   objectrE   r#   r#   r#   r$   <module>   s(   \