
    8i7                     T    S r SSKJrJr  SSKJrJr   " S S\5      r " S S\5      rg)	z

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

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

    )AuthBaseHTTPBasicAuth)urlparse
urlunparsec                   R    \ rS rSrSrS rS rS rS r\	S 5       r
S rS	 rS
 rSrg)AuthHandler   aB  

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                 D    [        U5      U l        U R                  5         g N)dict
strategies_make_uniform)selfr   s     n/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/requests_toolbelt/auth/handler.py__init__AuthHandler.__init__6   s    z*    c                 H    U R                  UR                  5      nU" U5      $ r   )get_strategy_forurl)r   requestauths      r   __call__AuthHandler.__call__:   s     $$W[[1G}r   c                 8    SR                  U R                  5      $ )Nz<AuthHandler({!r})>)formatr   r   s    r   __repr__AuthHandler.__repr__>   s    $++DOO<<r   c                     [        U R                  R                  5       5      n0 U l        U H  u  p#U R                  X#5        M     g r   )listr   itemsadd_strategy)r   existing_strategieskvs       r   r   AuthHandler._make_uniformA   s;    "4??#8#8#:;)FQa# *r   c                     [        U 5      n[        UR                  R                  5       UR                  R                  5       SSSS45      $ )N )r   r   schemelowernetloc)r   parseds     r   _key_from_urlAuthHandler._key_from_urlH   sE    #6==..0!==..0r2r+ , 	,r   c                 |    [        U[        5      (       a  [        U6 nU R                  U5      nX R                  U'   g)a  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)
isinstancetupler   r.   r   )r   domainstrategykeys       r   r#   AuthHandler.add_strategyO   s7      h&&$h/H  ('r   c                 l    U R                  U5      nU R                  R                  U[        5       5      $ )a  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 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   r   r5   s      r   r   AuthHandler.get_strategy_fore   s/       %""3(8(:;;r   c                 `    U R                  U5      nX R                  ;   a  U R                  U	 gg)a3  Remove 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   r3   r5   s      r   remove_strategyAuthHandler.remove_strategyw   s/       (//!$ "r   )r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r   staticmethodr.   r#   r   r<   __static_attributes__ r   r   r   r      s?    #J=$ , ,(,<$%r   r   c                        \ rS rSrS rS rSrg)r9      c                     g)Nz<NullAuthStrategy>rE   r   s    r   r   NullAuthStrategy.__repr__   s    #r   c                     U$ r   rE   )r   rs     r   r   NullAuthStrategy.__call__   s    r   rE   N)r>   r?   r@   rA   r   r   rD   rE   r   r   r9   r9      s    $r   r9   N)	rB   requests.authr   r   requests.compatr   r   r   r9   rE   r   r   <module>rO      s-    2 0w%( w%tx r   