a *Na8@sHdZddlmZmZddlmZmZGdddeZGdddeZdS) z requests_toolbelt.auth.handler ============================== This holds all of the implementation details of the Authentication Handler. )AuthBase HTTPBasicAuth)urlparse urlunparsec@sTeZdZdZddZddZddZdd Zed d Z d d Z ddZ ddZ dS) AuthHandlera 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) # => r = requests.get('https://example.com/some/path', auth=auth) # => s = requests.Session() s.auth = auth r = s.get('https://api.github.com/user') # => .. 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. cCst||_|dSN)dict strategies _make_uniform)selfr r y/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/requests_toolbelt/auth/handler.py__init__6s zAuthHandler.__init__cCs||j}||Sr)get_strategy_forurl)r requestauthr r r __call__:s zAuthHandler.__call__cCs d|jS)Nz)formatr r r r r __repr__>szAuthHandler.__repr__cCs2t|j}i|_|D]\}}|||qdSr)listr items add_strategy)r Zexisting_strategieskvr r r r As zAuthHandler._make_uniformcCs(t|}t|j|jddddfS)N)rrschemelowernetloc)rparsedr r r _key_from_urlHs  zAuthHandler._key_from_urlcCs*t|trt|}||}||j|<dS)aAdd 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) isinstancetuplerr!r )r domainZstrategykeyr r r rOs  zAuthHandler.add_strategycCs||}|j|tS)aRetrieve 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 authentication to a request. .. code-block:: python import requests a = AuthHandler({'example.com', ('foo', 'bar')}) strategy = a.get_strategy_for('http://example.com/example') assert isinstance(strategy, requests.auth.HTTPBasicAuth) )r!r getNullAuthStrategy)r rr%r r r res zAuthHandler.get_strategy_forcCs ||}||jvr|j|=dS)akRemove the domain and strategy from the collection of strategies. :param str domain: The domain you wish remove. For example, ``'https://api.github.com'``. .. code-block:: python a = AuthHandler({'example.com', ('foo', 'bar')}) a.remove_strategy('example.com') assert a.strategies == {} N)r!r )r r$r%r r r remove_strategyws  zAuthHandler.remove_strategyN) __name__ __module__ __qualname____doc__rrrr staticmethodr!rrr(r r r r rs% rc@seZdZddZddZdS)r'cCsdS)Nzr rr r r rszNullAuthStrategy.__repr__cCs|Srr )r rr r r rszNullAuthStrategy.__call__N)r)r*r+rrr r r r r'sr'N) r,Z requests.authrrZrequests.compatrrrr'r r r r s z