§
    ÜŽ’j/  ã                  ó  — U d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	Z	ddl
mZ ddlmZ dd	lmZ d
gZ ej        e¦  «        Zded<    ej        ¦   «         Z e¦   «         Zded<   dd„Zdd„Zdd„Z G d„ d
e	j        ¦  «        ZdS )é    )ÚannotationsN)Ú	GeneratorÚAsyncGenerator)Úoverrideé   )Ú
TokenCacheé   )Úasyncify)ÚOAUTH_API_BETA_HEADERÚAccessTokenAuthzlogging.LoggerÚlogzset[str]Ú_warn_once_seenÚkeyÚstrÚmessageÚargsÚobjectÚreturnÚNonec                óÊ   — t           5  | t          v r	 ddd¦  «         dS t                               | ¦  «         ddd¦  «         n# 1 swxY w Y   t          j        |g|¢R Ž  dS )z8Emit a log warning at most once per ``key`` per process.N)Ú_warn_once_lockr   Úaddr   Úwarning)r   r   r   s      úMC:\Projects\DSCons\.venv\Lib\site-packages\anthropic\lib\credentials\_auth.pyÚ
_warn_oncer      sÉ   € å	ð !ð !Ø•/Ð!Ð!Øð!ð !ð !ñ !ô !ð !ð !ð !õ 	×Ò˜CÑ Ô Ð ð!ð !ð !ñ !ô !ð !ð !ð !ð !ð !ð !øøøð !ð !ð !ð !õ „K�Ð˜$ÐÐÐÐÐÐs   ˆA AÁA
ÁA
Úparamc                ó.   — t          d| › �d| ¦  «         dS )ag  Warn that an explicit ``api_key=`` / ``auth_token=`` argument shadows
    an explicit ``credentials=`` provider passed to the same constructor or
    ``copy()`` call. The static credential wins at the request-header level
    (``AccessTokenAuth.sync_auth_flow`` short-circuits on the pre-set header),
    which silently disables the credentials provider.
    zexplicit-shadow:z“`%s=` was passed alongside `credentials=`; the static credential takes precedence and the credentials provider is silently disabled. Pass only one.N©r   )r   s    r   Ú(warn_explicit_static_shadows_credentialsr      s5   € õ Ø"˜5Ð"Ð"ð	ð 	ñô ð ð ð ó    Úenv_varc                ó0   — t          d| › �d| | ¦  «         dS )a¥  Warn that an ``ANTHROPIC_API_KEY`` / ``ANTHROPIC_AUTH_TOKEN`` from the
    environment is shadowing the SDK's profile / federation auto-discovery.

    Per the credential-precedence spec, a static-credential env var silently
    disables the auto-discovered federation and profile paths. Surface a
    one-shot warning so migrating users can see why their ``ANTHROPIC_PROFILE``
    or WIF env vars are being ignored.
    zenv-shadow:z‚%s is set and takes precedence over the SDK's profile / federation auto-discovery; unset %s to use the auto-discovered credential.Nr   )r!   s    r   Ú&warn_env_static_shadows_auto_discoveryr#   /   s7   € õ Ø�gÐÐð	JàØñô ð ð ð r    c                  ón   — e Zd ZdZdZdd„Zedd„¦   «         Zdd„Ze	dd„¦   «         Z
e	dd„¦   «         ZdS )r   u’  Adapts a :class:`TokenCache` to httpx's :class:`~httpx.Auth` protocol.

    Used by :meth:`anthropic.Anthropic.custom_auth` to inject ``Authorization: Bearer``
    plus the OAuth beta header on every request, with proactive refresh handled by
    :class:`TokenCache`.

    Static credentials shadow federation: if the outgoing request already carries
    an ``X-Api-Key`` or ``Authorization`` header (set by the client's api_key /
    auth_token path), this auth flow is a no-op. That matches the Go SDK's
    ``authMiddleware`` and the documented precedence in the WIF user guide â€”
    a static ``ANTHROPIC_API_KEY`` shadows any credentials provider.
    FÚtoken_cacher   r   r   c                ó   — || _         d S ©N)Ú_token_cache)Úselfr%   s     r   Ú__init__zAccessTokenAuth.__init__Q   s   € Ø'ˆÔÐÐr    Úrequestúhttpx.RequestÚboolc                ó„   — t          | j                             d¦  «        p| j                             d¦  «        ¦  «        S )Nz	X-Api-KeyÚAuthorization)r-   ÚheadersÚget)r+   s    r   Ú_has_static_credentialz&AccessTokenAuth._has_static_credentialT   s5   € å�G”O×'Ò'¨Ñ4Ô4Ð\¸¼×8KÒ8KÈOÑ8\Ô8\Ñ]Ô]Ð]r    Útokenr   c                ó  — d|› �|j         d<   |j                              dd¦  «        }d„ |                     d¦  «        D ¦   «         }t          |vr9|                     t          ¦  «         d                     |¦  «        |j         d<   d S d S )NzBearer r/   zanthropic-betaÚ c                ó^   — g | ]*}|                      ¦   «         ¯|                      ¦   «         ‘Œ+S © )Ústrip)Ú.0Úflags     r   ú
<listcomp>z*AccessTokenAuth._apply.<locals>.<listcomp>c   s-   € Ð\Ð\Ð\¨4ÈtÏzÊzÉ|Ì|Ð\˜$Ÿ*š*™,œ,Ð\Ð\Ð\r    ú,z, )r0   r1   Úsplitr   ÚappendÚjoin)r)   r+   r3   Úexisting_betaÚexisting_flagss        r   Ú_applyzAccessTokenAuth._applyX   s™   € Ø+<°UÐ+<Ð+<ˆŒ˜Ñ(Øœ×+Ò+Ð,<¸bÑAÔAˆð ]Ð\°=×3FÒ3FÀsÑ3KÔ3KÐ\Ñ\Ô\ˆÝ ¨Ð6Ð6Ø×!Ò!Õ"7Ñ8Ô8Ð8Ø04·	²	¸.Ñ0IÔ0IˆGŒOÐ,Ñ-Ð-Ð-ð 7Ð6r    ú.Generator[httpx.Request, httpx.Response, None]c              #  ó¦   K  — |                       |¦  «        r|V — d S | j                             ¦   «         }|                      ||¦  «         |V — d S r'   )r2   r(   Ú	get_tokenrB   ©r)   r+   r3   s      r   Úsync_auth_flowzAccessTokenAuth.sync_auth_flowh   s_   è è € à×&Ò& wÑ/Ô/ð 	ØˆMˆMˆMØˆFØÔ!×+Ò+Ñ-Ô-ˆØ�Š�G˜UÑ#Ô#Ð#Øˆˆˆˆˆr    ú-AsyncGenerator[httpx.Request, httpx.Response]c               óÆ   K  — |                       |¦  «        r|W V — d S  t          | j        j        ¦  «        ¦   «         ƒ d {V —†}|                      ||¦  «         |W V — d S r'   )r2   r
   r(   rE   rB   rF   s      r   Úasync_auth_flowzAccessTokenAuth.async_auth_flowq   s~   è è € à×&Ò& wÑ/Ô/ð 	ØˆMˆMˆMˆMØˆFð <•h˜tÔ0Ô:Ñ;Ô;Ñ=Ô=Ð=Ð=Ð=Ð=Ð=Ð=ˆØ�Š�G˜UÑ#Ô#Ð#Øˆˆˆˆˆˆr    N)r%   r   r   r   )r+   r,   r   r-   )r+   r,   r3   r   r   r   )r+   r,   r   rC   )r+   r,   r   rH   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_response_bodyr*   Ústaticmethodr2   rB   r   rG   rJ   r7   r    r   r   r   A   s¶   € € € € € ðð ð #Ðð(ð (ð (ð (ð ð^ð ^ð ^ñ „\ð^ðJð Jð Jð Jð  ðð ð ñ „Xðð ð	ð 	ð 	ñ „Xð	ð 	ð 	r    )r   r   r   r   r   r   r   r   )r   r   r   r   )r!   r   r   r   )Ú
__future__r   ÚloggingÚ	threadingÚtypingr   r   Útyping_extensionsr   ÚhttpxÚ_cacher   Ú_utilsr
   Ú
_constantsr   Ú__all__Ú	getLoggerrK   r   Ú__annotations__ÚLockr   Úsetr   r   r   r#   ÚAuthr   r7   r    r   ú<module>r`      sV  ðØ "Ð "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø &Ð &Ð &Ð &Ð &Ð &à €€€à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -àÐ
€à'�gÔ'¨Ñ1Ô1€Ð 1Ð 1Ð 1Ñ 1à �)”.Ñ"Ô"€Ø˜C™EœE€Ð !Ð !Ð !Ñ !ð ð  ð  ð  ðð ð ð ð ð ð ð ð$:ð :ð :ð :ð :�e”jñ :ô :ð :ð :ð :r    