0
  "   ˆl–ßi~”ÊC]ŠnãB¸ËŠbÑ¿Áƒp À¿ y    ó
Óµ Yc           @   sb   d  Z  d d l m Z m Z d d l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(	   sŽ   

requests_toolbelt.auth.handler
==============================

This holds all of the implementation details of the Authentication Handler.

iÿÿÿÿ(   t   AuthBaset   HTTPBasicAuth(   t   urlparset
   urlunparset   AuthHandlerc           B   s\   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z RS(	   s¦  

    The ``AuthHandler`` object takes a dictionary of domains paired with
    authentication strategies and will use this to determine which credentials
    to use when making a request. For example, you could do the following:

    .. code-block:: python

        from requests import HTTPDigestAuth
        from requests_toolbelt.auth.handler import AuthHandler

        import requests

        auth = AuthHandler({
            'https://api.github.com': ('sigmavirus24', 'fakepassword'),
            'https://example.com': HTTPDigestAuth('username', 'password')
        })

        r = requests.get('https://api.github.com/user', auth=auth)
        # => <Response [200]>
        r = requests.get('https://example.com/some/path', auth=auth)
        # => <Response [200]>

        s = requests.Session()
        s.auth = auth
        r = s.get('https://api.github.com/user')
        # => <Response [200]>

    .. warning::

        :class:`requests.auth.HTTPDigestAuth` is not yet thread-safe. If you
        use :class:`AuthHandler` across multiple threads you should
        instantiate a new AuthHandler for each thread with a new
        HTTPDigestAuth instance for each thread.

    c         C   s   t  | ƒ |  _ |  j ƒ  d  S(   N(   t   dictt
   strategiest   _make_uniform(   t   selfR   (    (    sB   /usr/lib/python2.7/site-packages/requests_toolbelt/auth/handler.pyt   __init__6   s    c         C   s   |  j  | j ƒ } | | ƒ S(   N(   t   get_strategy_fort   url(   R   t   requestt   auth(    (    sB   /usr/lib/python2.7/site-packages/requests_toolbelt/auth/handler.pyt   __call__:   s    c         C   s   d j  |  j ƒ S(   Ns   <AuthHandler({0!r})>(   t   formatR   (   R   (    (    sB   /usr/lib/python2.7/site-packages/requests_toolbelt/auth/handler.pyt   __repr__>   s    c         C   sI   t  |  j j ƒ  ƒ } i  |  _ x$ | D] \ } } |  j | | ƒ q% Wd  S(   N(   t   listR   t   itemst   add_strategy(   R   t   existing_strategiest   kt   v(    (    sB   /usr/lib/python2.7/site-packages/requests_toolbelt/auth/handler.pyR   A   s    	c         C   s:   t  |  ƒ } t | j j ƒ  | j j ƒ  d d d d f ƒ S(   Nt    (   R   R   t   schemet   lowert   netloc(   R   t   parsed(    (    sB   /usr/lib/python2.7/site-packages/requests_toolbelt/auth/handler.pyt   _key_from_urlH   s    c         C   s>   t  | t ƒ r t | Œ  } n  |  j | ƒ } | |  j | <d S(   s  Add a new domain and authentication strategy.

        :param str domain: The domain you wish to match against. For example:
            ``'https://api.github.com'``
        :param str strategy: The authentication strategy you wish to use for
            that domain. For example: ``('username', 'password')`` or
            ``requests.HTTPDigestAuth('username', 'password')``

        .. code-block:: python

            a = AuthHandler({})
            a.add_strategy('https://api.github.com', ('username', 'password'))

        N(   t
   isinstancet   tupleR   R   R   (   R   t   domaint   strategyt   key(    (    sB   /usr/lib/python2.7/site-packages/requests_toolbelt/auth/handler.pyR   O   s    c         C   s%   |  j  | ƒ } |  j j | t ƒ  ƒ S(   s  Retrieve the authentication strategy for a specified URL.

        :param str url: The full URL you will be making a request against. For
            example, ``'https://api.github.com/user'``
        :returns: Callable that adds authentica