a Æ*Na8ã@sHdZddlmZmZddlmZmZGdd„deƒZGdd„deƒZdS) zŽ requests_toolbelt.auth.handler ============================== This holds all of the implementation details of the Authentication Handler. é)ÚAuthBaseÚ HTTPBasicAuth)ÚurlparseÚ urlunparsec@sTeZdZdZdd„Zdd„Zdd„Zdd „Zed d „ƒZ d d „Z dd„Z dd„Z 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|ƒ|_| ¡dS©N)Ú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_forÚurl)r ÚrequestÚauthr r r Ú__call__:s zAuthHandler.__call__cCs d |j¡S)Nz)Úformatr ©r r r r Ú__repr__>szAuthHandler.__repr__cCs2t|j ¡ƒ}i|_|D]\}}| ||¡qdSr)Úlistr ÚitemsÚ add_strategy)r Zexisting_strategiesÚkÚvr r r r As zAuthHandler._make_uniformcCs(t|ƒ}t|j ¡|j ¡ddddfƒS)NÚ)rrÚschemeÚlowerÚnetloc)rÚparsedr r r Ú _key_from_urlHs  þzAuthHandler._key_from_urlcCs*t|tƒrt|Ž}| |¡}||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)Ú isinstanceÚtuplerr!r )r ÚdomainZstrategyÚkeyr r r rOs  zAuthHandler.add_strategycCs| |¡}|j |tƒ¡S)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 ÚgetÚNullAuthStrategy)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@seZdZdd„Zdd„ZdS)r'cCsdS)Nzr rr r r rŠszNullAuthStrategy.__repr__cCs|Srr )r Úrr r r r�szNullAuthStrategy.__call__N)r)r*r+rrr r r r r'‰sr'N) r,Z requests.authrrZrequests.compatrrrr'r r r r Ús z