
    b\j                        % S SK Jr  S SKrS SKrS SKJrJr  S SKJr  S SK	r	SSK
Jr  SSKJr  SS	KJr  S
/r\R"                  " \5      rS\S'   \R*                  " 5       r\" 5       rS\S'   SS jrSS jrSS jr " S S
\	R8                  5      rg)    )annotationsN)	GeneratorAsyncGenerator)override   )
TokenCache   )asyncify)OAUTH_API_BETA_HEADERAccessTokenAuthzlogging.Loggerlogzset[str]_warn_once_seenc                    [            U [        ;   a
   SSS5        g[        R                  U 5        SSS5        [        R                  " U/UQ76   g! , (       d  f       N&= f)z8Emit a log warning at most once per ``key`` per process.N)_warn_once_lockr   addr   warning)keymessageargss      U/var/www/website/venv/lib/python3.13/site-packages/anthropic/lib/credentials/_auth.py
_warn_oncer      sG    	/! 
 	C  
 KK$	 
s   AA
Ac                $    [        SU  3SU 5        g)aS  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   )params    r   (warn_explicit_static_shadows_credentialsr      s      
5'"	 	    c                &    [        SU  3SU U 5        g)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   )env_vars    r   &warn_env_static_shadows_auto_discoveryr   /   s"     
gY	Jr   c                  l    \ rS rSrSrSrSS jr\SS j5       rSS jr	\
SS j5       r\
SS j5       rS	rg
)r   A   un  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.
Fc                    Xl         g N_token_cache)selftoken_caches     r   __init__AccessTokenAuth.__init__Q   s    'r   c                    [        U R                  R                  S5      =(       d    U R                  R                  S5      5      $ )Nz	X-Api-KeyAuthorization)boolheadersget)requests    r   _has_static_credential&AccessTokenAuth._has_static_credentialT   s0    GOO''4\8K8KO8\]]r   c                p   SU 3UR                   S'   UR                   R                  SS5      nUR                  S5       Vs/ s H)  oDR                  5       (       d  M  UR                  5       PM+     nn[        U;  a4  UR                  [        5        SR                  U5      UR                   S'   g g s  snf )NzBearer r+   zanthropic-beta ,z, )r-   r.   splitstripr   appendjoin)r&   r/   tokenexisting_betaflagexisting_flagss         r   _applyAccessTokenAuth._applyX   s    -4UG+<(++,<bA 4A3F3Fs3K\3K4zz|,$**,3K\ 6!!"7804		.0IGOO,- 7 ]s   B3B3c              #     #    U R                  U5      (       a  Uv   g U R                  R                  5       nU R                  X5        Uv   g 7fr#   )r0   r%   	get_tokenr=   r&   r/   r9   s      r   sync_auth_flowAccessTokenAuth.sync_auth_flowh   sC     &&w//M!!++-G#s   AAc                  #    U R                  U5      (       a  U7v   g [        U R                  R                  5      " 5       I S h  vN nU R	                  X5        U7v   g  N7fr#   )r0   r
   r%   r@   r=   rA   s      r   async_auth_flowAccessTokenAuth.async_auth_flowq   sR     &&w//M t00::;==G# >s   AA$A"A$r$   N)r'   r   returnNone)r/   httpx.RequestrG   r,   )r/   rI   r9   strrG   rH   )r/   rI   rG   z.Generator[httpx.Request, httpx.Response, None])r/   rI   rG   z-AsyncGenerator[httpx.Request, httpx.Response])__name__
__module____qualname____firstlineno____doc__requires_response_bodyr(   staticmethodr0   r=   r   rB   rE   __static_attributes__ r   r   r   r   A   sX     #( ^ ^J    	 	r   )r   rJ   r   rJ   r   objectrG   rH   )r   rJ   rG   rH   )r   rJ   rG   rH   )
__future__r   logging	threadingtypingr   r   typing_extensionsr   httpx_cacher   _utilsr
   
_constantsr   __all__	getLoggerrK   r   __annotations__Lockr   setr   r   r   r   Authr   rS   r   r   <module>rd      st    "   , &    -
''1^ 1.."E !  $:ejj :r   