o
    Vh7                     @   sH   d Z ddlmZmZ ddlmZmZ G dd deZG d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                   @   sT   e Zd ZdZdd Zdd Zdd Zdd	 Zed
d Z	dd Z
dd Zd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                 C   s   t || _|   d S N)dict
strategies_make_uniform)selfr	    r   r/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/requests_toolbelt/auth/handler.py__init__6   s   
zAuthHandler.__init__c                 C   s   |  |j}||S r   )get_strategy_forurl)r   requestauthr   r   r   __call__:   s   zAuthHandler.__call__c                 C   s   d | jS )Nz<AuthHandler({!r})>)formatr	   r   r   r   r   __repr__>   s   zAuthHandler.__repr__c                 C   s2   t | j }i | _|D ]
\}}| || qd S r   )listr	   itemsadd_strategy)r   existing_strategieskvr   r   r   r
   A   s
   zAuthHandler._make_uniformc                 C   s(   t | }t|j |j ddddfS )N )r   r   schemelowernetloc)r   parsedr   r   r   _key_from_urlH   s
   
zAuthHandler._key_from_urlc                 C   s*   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keyr   r   r   r   O   s   

zAuthHandler.add_strategyc                 C   s   |  |}| 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'   r   r   r   r   e   s   
zAuthHandler.get_strategy_forc                 C   s$   |  |}|| 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'   r   r   r   remove_strategyw   s   

zAuthHandler.remove_strategyN)__name__
__module____qualname____doc__r   r   r   r
   staticmethodr"   r   r   r*   r   r   r   r   r      s    %
r   c                   @   s   e Zd Zdd Zdd ZdS )r)   c                 C   s   dS )Nz<NullAuthStrategy>r   r   r   r   r   r         zNullAuthStrategy.__repr__c                 C   s   |S r   r   )r   rr   r   r   r      r0   zNullAuthStrategy.__call__N)r+   r,   r-   r   r   r   r   r   r   r)      s    r)   N)	r.   requests.authr   r   requests.compatr   r   r   r)   r   r   r   r   <module>   s
   	z