a
    d=ic                     @   s4   d Z ddlZG dd dejdZG dd deZdS )z9Experimental framework for authentication in TensorBoard.    Nc                   @   s   e Zd ZdZdd ZdS )AuthProviderz:Authentication provider for a specific kind of credential.c                 C   s   dS )ae  Produce an opaque auth token from a WSGI request environment.

        Args:
          environ: A WSGI environment `dict`; see PEP 3333.

        Returns:
          A Python object representing an auth token. The representation
          and semantics depend on the particular `AuthProvider`
          implementation.

        Raises:
          Exception: Any error, usually `tensorboard.errors.PublicError`
            subclasses (like `PermissionDenied`) but also possibly a
            custom error type that should propagate to a WSGI middleware
            for effecting a redirect-driven auth flow.
        N )selfenvironr   r   a/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/tensorboard/auth.pyauthenticate   s    zAuthProvider.authenticateN)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   )	metaclassc                   @   s,   e Zd ZdZdd Zedd Zdd ZdS )	AuthContexta  Authentication context within the scope of a single request.

    Auth providers are keyed within an `AuthContext` by arbitrary
    unique keys. It may often make sense for the key used for an
    auth provider to simply be that provider's type object.
    c                 C   s   || _ || _i | _dS )zCreate an auth context.

        Args:
          providers: A mapping from provider keys (opaque values) to
            `AuthProvider` implementations.
          environ: A WSGI environment (see PEP 3333).
        N)_environ
_providers_cache)r   	providersr   r   r   r   __init__3   s    zAuthContext.__init__c                 C   s
   | i i S )zCreate an auth context with no registered providers.

        Returns:
          A new `AuthContext` value for which any call to `get` will
          fail with a `KeyError`.
        r   )clsr   r   r   empty?   s    
zAuthContext.emptyc                 C   sD   | j | }t }| j||}||ur*|S || j}|| j|< |S )a  Get an auth token from the auth provider with the given key.

        If successful, the result will be cached on this auth context.
        If unsuccessful, nothing will be cached, so a future call will
        invoke the underlying `AuthProvider.authenticate` method again.

        This method is not thread-safe. If multiple threads share an
        auth context for a single request, then they must synchronize
        externally when calling this method.

        Returns:
          The result of `provider.authenticate(...)` for the auth
          provider specified by `provider_key`.

        Raises:
          KeyError: If the given `provider_key` does not correspond to
            any registered `AuthProvider`.
          Exception: As raised by the underlying `AuthProvider`.
        )r   objectr   getr   r   )r   Zprovider_keyprovidersentinelvaluer   r   r   r   K   s    

zAuthContext.getN)r   r	   r
   r   r   classmethodr   r   r   r   r   r   r   +   s
   
r   )r   abcABCMetar   r   r   r   r   r   r   <module>   s   