σ
έ²k^c           @` s΄  d  d l  m Z m Z m Z 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 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" m# Z# d d l$ m% Z% m& Z& m' Z' m( Z( d d l) m* Z* e e+  Z, d Z- d e f d     YZ. d e/ f d     YZ0 e# e0  d e f d     Y Z1 d e
 f d     YZ2 d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t	   getLogger(   t   locali   (	   t   AuthBaset   BaseAdaptert   HTTPAdaptert   Sessiont   _basic_auth_strt   extract_cookies_to_jart   get_auth_from_urlt   get_netrc_autht   Retry(   t
   FTPAdapter(   t   LocalFSAdapter(   t	   S3Adapteri   (   t   read_binstar_tokensi   (   t   dals(   t   CONDA_HOMEPAGE_URL(   t   context(   t	   iteritemst   with_metaclass(   t   add_username_and_passwordt   get_proxy_username_and_passt   split_anaconda_tokent   urlparse(   t
   ProxyErrort   EnforceUnusedAdapterc           B` s   e  Z d    Z d   Z RS(   c         O` s#   t  d | j  } t |   d  S(   Nu|   
        EnforceUnusedAdapter called with url %s
        This command is using a remote connection in offline mode.
        (   R   t   urlt   RuntimeError(   t   selft   requestt   argst   kwargst   message(    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyt   send   s    c         C` s   t     d  S(   N(   t   NotImplementedError(   R    (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyt   close$   s    (   t   __name__t
   __module__R%   R'   (    (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR      s   	t   CondaSessionTypec           B` s    e  Z d  Z d   Z d   Z RS(   u   
    Takes advice from https://github.com/requests/requests/issues/1871#issuecomment-33327847
    and creates one Session instance per thread.
    c         C` s,   t    | d <t t |   j |  | | |  S(   Nu   _thread_local(   R   t   superR*   t   __new__(   t   mcst   namet   basest   dct(    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR,   .   s    c         C` sF   y |  j  j SWn1 t k
 rA t t |   j   } |  j  _ | SXd  S(   N(   t   _thread_localt   sessiont   AttributeErrorR+   R*   t   __call__(   t   clsR2   (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR4   2   s
    (   R(   R)   t   __doc__R,   R4   (    (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR*   (   s   	t   CondaSessionc           B` s   e  Z d    Z RS(   c         C` sc  t  t |   j   t   |  _ |  j j t j  t j	 r t
   } |  j d |  |  j d |  |  j d |  |  j d |  np t d t j d t j  } t d |  } |  j d |  |  j d |  |  j d t    |  j d t    |  j d t    t j |  j d	 <t j |  _ t j rGt j t j f |  _ n t j r_t j |  _ n  d  S(
   Nu   http://u   https://u   ftp://u   s3://t   totalt   backoff_factort   max_retriesu   file://u
   User-Agent(   R+   R7   t   __init__t   CondaHttpAutht   autht   proxiest   updateR   t   proxy_serverst   offlineR   t   mountR   t   remote_max_retriest   remote_backoff_factorR   R   R   R   t
   user_agentt   headerst
   ssl_verifyt   verifyt   client_ssl_cert_keyt   client_ssl_certt   cert(   R    t   unused_adaptert   retryt   http_adapter(    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR;   =   s.    				(   R(   R)   R;   (    (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR7   :   s   R<   c           B` s>   e  Z d    Z e d    Z e d    Z e d    Z RS(   c         C` s9   t  j | j  | _ |  j |  | j d |  j  | S(   Nu   response(   R<   t   add_binstar_tokenR   t   _apply_basic_autht   register_hookt
   handle_407(   R    R!   (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR4   d   s    c         C` s   t  |  j  } t |  r! | n d  } | d  k rE t |  j  } n  t | t  r| t |  d k r| t |   |  j	 d <n  |  S(   Ni   u   Authorization(
   R   R   t   anyt   NoneR   t
   isinstancet   tuplet   lenR
   RF   (   R!   t   url_authR=   (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyRP   j   s    !c         C` s   t  |   \ } } | r t j r xt t t    D]` \ } } | j |  r2 t j d |  d d l m	 } | |  } | | _
 | j d t  Sq2 Wn  |  S(   Nu"   Adding anaconda token for url <%s>i   (   t   Channelt   with_credentials(   R   R   t   add_anaconda_tokenR   R   t
   startswitht   logt   debugt   models.channelRY   t   tokenR   t   True(   R   t	   clean_urlR`   t   binstar_urlRY   t   channel(    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyRO   y   s    	c   
      K` s8  |  j  d k r |  S|  j |  j   | j d  } t |  j  j } | | k rp t t d | t	 f    n  | | } t
 |  \ } } t | | |  } t | |  } | | | <| | d <|  j j   } t | j |  j |  j  | j | j  | | j d <|  j j | |  }	 |	 j j |   | |	 _ |	 S(   uρ  
        Prompts the user for the proxy username and password and modifies the
        proxy in the session object to include it.

        This method is modeled after
          * requests.auth.HTTPDigestAuth.handle_401()
          * requests.auth.HTTPProxyAuth
          * the previous conda.fetch.handle_proxy_407()

        It both adds 'username:password' to the proxy URL, as well as adding a
        'Proxy-Authorization' header.  If any of this is incorrect, please file an issue.

        i  u   proxiesuΑ   
            Could not find a proxy for %r. See
            %s/docs/html#configure-conda-for-use-behind-a-proxy-server
            for more information on how to configure proxies.
            u   Proxy-Authorization(   t   status_codet   contentR'   t   popR   R   t   schemeR   R   R   R   R   R
   R!   t   copyR   t   _cookiest   rawt   prepare_cookiesRF   t
   connectionR%   t   historyt   append(
   t   responseR#   R>   t   proxy_schemet	   proxy_urlt   usernamet   passwordt   proxy_authorization_headert   prept	   _response(    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyRR      s.    



	(   R(   R)   R4   t   staticmethodRP   RO   RR   (    (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyR<   a   s   	N(3   t
   __future__R    R   R   R   t   loggingR   t	   threadingR   t    R   R   R   R	   R
   R   R   R   R   t   adapters.ftpR   t   adapters.localfsR   t   adapters.s3R   t   anaconda_clientR   t   _vendor.auxlib.ishR   t   base.constantsR   t   base.contextR   t   common.compatR   R   t
   common.urlR   R   R   R   t
   exceptionsR   R(   R]   t   RETRIESR   t   typeR*   R7   R<   (    (    (    s@   lib/python2.7/site-packages/conda/gateways/connection/session.pyt   <module>   s(   "@"&