ó
Ý²k^c           @` 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 Z d  d l Z d  d l Z d  d l m Z d d l 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 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/ m0 Z0 e e1 ƒ Z2 d „  Z3 d „  Z4 e) d ƒ d d d d d „ ƒ Z6 d e7 f d „  ƒ  YZ8 d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   DEBUGt	   getLogger(   t   basenamet   existst   join(   t   find_libraryi   (   t   ConnectionErrort	   HTTPErrort   InsecureRequestWarningt   InvalidSchemat   SSLErrort   RequestsProxyError(   t   CondaSessioni   (   t   rm_rfi   (   t
   CondaError(   t   dals(   t	   stringify(   t   context(   t	   text_type(   t   time_recorder(   t   BasicClobberErrort   CondaDependencyErrort   CondaHTTPErrort   ChecksumMismatchErrort   maybe_raiset
   ProxyErrorc           C` s   t  j d t ƒ d  S(   Nu   ignore(   t   warningst   simplefilterR   (    (    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt   disable_ssl_verify_warning    s    c          C` sj  t  j j t j d d ƒ }  d } d } d } d } t j d k rK d	 } n  | | | } t  j j |  | ƒ } t | d
 ƒ s´ d } d } d } d } | } t  j j |  | ƒ } n  t | ƒ } | sÏ | } n  | | | } t | ƒ } | st  j j t j d d | ƒ } n  t j	 j
 }	 |	 j | ƒ }
 |
 sAt j | ƒ n  |	 j | ƒ }
 |
 sft j | ƒ n  d S(   u«   Because our openssl library lives in Librar/bin, and because that may not be on PATH
    if conda.exe in Scripts is called directly, try this preload to avoid user issues.u   Libraryu   binu   libsslu	   libcryptou   -1_1u    i   i    u   -x64u   .dllu   ssleay32u   libeay32NI       (   t   ost   pathR   t   syst   prefixt   maxsizeR   R	   t   ctypest   windllt   kernel32t   GetModuleHandleAt   WinDLL(   t   libbin_patht   libssl_dllnamet   libcrypto_dllnamet   libssl_versiont   libssl_archt   so_namet   libssl_path2t   libssl_patht   libcrypto_pathR(   t   h_mod(    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt   preload_openssl$   s<    		!u   downloadc         C` sJ  t  | ƒ r( t t | |  t ƒ t ƒ n  t j d k rA t ƒ  n  t j sT t ƒ  n  yt j	 t j
 f } t ƒ  } | j |  d t d | j d | ƒ} t j t ƒ rÁ t j t | d d ƒƒ n  | j ƒ  t | j j d d ƒ ƒ }	 d  }
 } } | rt j d	 ƒ }
 d	 } | } n0 | rH| r3t j d
 ƒ n d  }
 d
 } | } n  d } y7t | d ƒ Ý } d } xÍ | j d! ƒ D]¼ } | j j ƒ  } y | j | ƒ Wn4 t k
 rÕ} d } t  | d | d | j! ƒ‚ n X|
 oè|
 j" | ƒ | t# | ƒ 7} |	 ryd | k o|	 k n ry| r5| | |	 ƒ q5qyqyWWd  QX|	 r„| |	 k r„t$ d ƒ } t  | d |  d | d |	 d | ƒ‚ n  Wn? t t% f k
 rÆ} | j! d k rÀt j d | ƒ n  ‚  n X| r|
 j& ƒ  } | | k rt j d | |  | | ƒ t' |  | | | | ƒ ‚ qn  | d  k	 rn| } | | k rnt j d |  | | ƒ t' |  | d | | ƒ ‚ qnn  WnÔ t( k
 r‹t) ƒ  ‚ n» t* k
 rÍ} d t+ | ƒ k rÇt$ d ƒ } t, | ƒ ‚ qF‚  ny t- t. t/ f k
 rE} t$ d ƒ } t0 | |  t1 | j2 d d  ƒ t1 | j2 d d  ƒ t1 | j2 d d  ƒ | j2 d  | ƒ‚ n Xd  S("   Nu   win32t   streamt   proxiest   timeoutt   content_max_leni   u   Content-Lengthi    u   sha256u   md5u   wbi   i   u5   Failed to write to %(target_path)s
  errno: %(errno)dt   target_patht   errnou  
                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
                t   urlt   content_lengtht   downloaded_bytesih   u   %s, trying againu'   %s mismatch for download: %s (%s != %s)u)   size mismatch for download: %s (%s != %s)u   sizeu   SOCKSuQ  
                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.
                u£   
        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.
        u   status_codeu   reasonu   elapsedt	   caused_byi @  (3   R   R   R   R   R#   t   platformR5   t
   ssl_verifyR    t   remote_connect_timeout_secst   remote_read_timeout_secsR   t   gett   TrueR7   t   logt   isEnabledForR   t   debugR   t   raise_for_statust   intt   headerst   Nonet   hashlibt   newt   opent   iter_contentt   rawt   tellt   writet   IOErrorR   R;   t   updatet   lenR   t   OSErrort	   hexdigestR   R   R   R   R   R   R
   R   R   R   t   getattrt   response(   R<   t   target_full_patht   md5t   sha256t   sizet   progress_update_callbackR8   t   sessiont   respR=   t   checksum_buildert   checksum_typet   checksumt   size_buildert   fht   streamed_bytest   chunkt   et   messaget   actual_checksumt   actual_sizet   help_message(    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt   downloadI   sž    
	
	$
		"		"			t   TmpDownloadc           B` s,   e  Z d  Z e d „ Z d „  Z d „  Z RS(   u;   
    Context manager to handle downloads to a tempfile
    c         C` s   | |  _  | |  _ d  S(   N(   R<   t   verbose(   t   selfR<   Rp   (    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt   __init__Á   s    	c         C` sa   d |  j  k r d  |  _ |  j  St j ƒ  |  _ t |  j t |  j  ƒ ƒ } t |  j  | ƒ | Sd  S(   Nu   ://(   R<   RL   t   tmp_dirt   tempfilet   mkdtempR   R   Rn   (   Rq   t   dst(    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt	   __enter__Å   s    	c         C` s   |  j  r t |  j  ƒ n  d  S(   N(   Rs   R   (   Rq   t   exc_typet	   exc_valuet	   traceback(    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt   __exit__Ð   s    	(   t   __name__t
   __module__t   __doc__RE   Rr   Rw   R{   (    (    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyRo   ½   s   	(9   t
   __future__R    R   R   R   RM   t   loggingR   R   t   os.pathR   R   R   Rt   R   R#   R!   R&   t   ctypes.utilR	   t    R
   R   R   R   R   R   R`   R   t   disk.deleteR   R   t   _vendor.auxlib.ishR   t   _vendor.auxlib.logzR   t   base.contextR   t   common.compatR   t	   common.ioR   t
   exceptionsR   R   R   R   R   R   R|   RF   R    R5   RL   Rn   t   objectRo   (    (    (    sA   lib/python2.7/site-packages/conda/gateways/connection/download.pyt   <module>   s2   "..		%	r