
    |h7                     T    d Z ddlmZmZ ddlmZmZ  G d de      Z G d de      Zy)	z

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

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

    )AuthBaseHTTPBasicAuth)urlparse
urlunparsec                   J    e Zd ZdZd Zd Zd Zd Zed        Z	d Z
d Zd	 Zy
)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)
        # => <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    t        |      | _        | j                          y N)dict
strategies_make_uniform)selfr   s     ]/var/www/html/test/engine/venv/lib/python3.12/site-packages/requests_toolbelt/auth/handler.py__init__zAuthHandler.__init__6   s    z*    c                 H    | j                  |j                        } ||      S r
   )get_strategy_forurl)r   requestauths      r   __call__zAuthHandler.__call__:   s     $$W[[1G}r   c                 8    dj                  | j                        S )Nz<AuthHandler({!r})>)formatr   r   s    r   __repr__zAuthHandler.__repr__>   s    $++DOO<<r   c                     t        | j                  j                               }i | _        |D ]  \  }}| j                  ||        y r
   )listr   itemsadd_strategy)r   existing_strategieskvs       r   r   zAuthHandler._make_uniformA   sD    "4??#8#8#:;) 	$FQa#	$r   c                     t        |       }t        |j                  j                         |j                  j                         ddddf      S )N )r   r   schemelowernetloc)r   parseds     r   _key_from_urlzAuthHandler._key_from_urlH   sE    #6==..0!==..0r2r+ , 	,r   c                 t    t        |t              rt        | }| j                  |      }|| j                  |<   y)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   zAuthHandler.add_strategyO   s6      h&$h/H  ('r   c                 l    | j                  |      }| j                  j                  |t                     S )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   r/   s      r   r   zAuthHandler.get_strategy_fore   s/       %""3(8(:;;r   c                 ^    | j                  |      }|| j                  v r| j                  |= yy)ak  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   r-   r/   s      r   remove_strategyzAuthHandler.remove_strategyw   s1       ($//!$ "r   N)__name__
__module____qualname____doc__r   r   r   r   staticmethodr)   r   r   r4    r   r   r   r      s?    #J=$ , ,(,<$%r   r   c                       e Zd Zd Zd Zy)r2   c                      y)Nz<NullAuthStrategy>r:   r   s    r   r   zNullAuthStrategy.__repr__   s    #r   c                     |S r
   r:   )r   rs     r   r   zNullAuthStrategy.__call__   s    r   N)r5   r6   r7   r   r   r:   r   r   r2   r2      s    $r   r2   N)	r8   requests.authr   r   requests.compatr   r   r   r2   r:   r   r   <module>rA      s-    2 0w%( w%tx r   