
    .Ph7                     b    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dS )	z

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

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

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