Ë
    A²Xj´  ã                  ó  — 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	j8                  «      Zy)é    )ÚannotationsN)Ú	GeneratorÚAsyncGenerator)Úoverrideé   )Ú
TokenCacheé   )Úasyncify)ÚOAUTH_API_BETA_HEADERÚAccessTokenAuthzlogging.LoggerÚlogzset[str]Ú_warn_once_seenc                ó´   — t         5  | t        v r
	 ddd«       yt        j                  | «       ddd«       t        j                  |g|¢­Ž  y# 1 sw Y   Œ xY w)z8Emit a log warning at most once per ``key`` per process.N)Ú_warn_once_lockr   Úaddr   Úwarning)ÚkeyÚmessageÚargss      úe/var/www/html/content_generation/venv/lib/python3.12/site-packages/anthropic/lib/credentials/_auth.pyÚ
_warn_oncer      sG   € æ	Ø”/Ñ!Ø÷ 
ˆô 	×Ñ˜CÔ ÷ 
ô ‡K�K�Ð˜$Ô÷	 
ˆús   ‡
AšAÁAc                ó$   — t        d| › �d| «       y)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   )Úparams    r   Ú(warn_explicit_static_shadows_credentialsr      s    € ô Ø
˜5˜'Ð"ð	ð 	õó    c                ó&   — t        d| › �d| | «       y)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"   € ô Ø
�g�YÐð	JàØõr   c                  óZ   — 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y)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.
    Fc                ó   — || _         y ©N)Ú_token_cache)ÚselfÚtoken_caches     r   Ú__init__zAccessTokenAuth.__init__Q   s
   € Ø'ˆÕr   c                ó„   — t        | j                  j                  d«      xs | j                  j                  d«      «      S )Nz	X-Api-KeyÚAuthorization)ÚboolÚheadersÚget)Úrequests    r   Ú_has_static_credentialz&AccessTokenAuth._has_static_credentialT   s0   € ä�G—O‘O×'Ñ'¨Ó4Ò\¸¿¹×8KÑ8KÈOÓ8\Ó]Ð]r   c                ó\  — d|› �|j                   d<   |j                   j                  dd«      }|j                  d«      D �cg c]#  }|j                  «       sŒ|j                  «       ‘Œ% }}t        |vr4|j                  t        «       dj                  |«      |j                   d<   y y c c}w )NzBearer r(   zanthropic-betaÚ Ú,z, )r*   r+   ÚsplitÚstripr   ÚappendÚjoin)r$   r,   ÚtokenÚexisting_betaÚflagÚexisting_flagss         r   Ú_applyzAccessTokenAuth._applyX   sš   € Ø-4°U°GÐ+<ˆ�‰˜Ñ(ØŸ™×+Ñ+Ð,<¸bÓAˆð 4A×3FÑ3FÀsÔ3KÓ\Ñ3K¨4ÈtÏzÉzÍ|˜$Ÿ*™*�,Ð3KˆÐ\Ü ¨Ñ6Ø×!Ñ!Ô"7Ô8Ø04·	±	¸.Ó0IˆG�O‰OÐ,Ò-ð 7ùò ]s   ÁB)ÁB)c              #  ó˜   K  — | j                  |«      r|–— y | j                  j                  «       }| j                  ||«       |–— y ­wr"   )r-   r#   Ú	get_tokenr9   ©r$   r,   r5   s      r   Úsync_auth_flowzAccessTokenAuth.sync_auth_flowh   sC   è ø€ à×&Ñ& wÔ/ØŠMØØ×!Ñ!×+Ñ+Ó-ˆØ�‰�G˜UÔ#Ø‹ùs   ‚AA
c               óÄ   K  — | j                  |«      r|­–— y  t        | j                  j                  «      «       ƒ d {  –—† }| j	                  ||«       |­–— y 7 Œ­wr"   )r-   r
   r#   r;   r9   r<   s      r   Úasync_auth_flowzAccessTokenAuth.async_auth_flowq   sT   è ø€ à×&Ñ& wÔ/Ø‹MØð <”h˜t×0Ñ0×:Ñ:Ó;Ó=×=ˆØ�‰�G˜UÔ#ØŒð >ús   ‚?A ÁAÁA N)r%   r   ÚreturnÚNone)r,   úhttpx.Requestr@   r)   )r,   rB   r5   Ústrr@   rA   )r,   rB   r@   z.Generator[httpx.Request, httpx.Response, None])r,   rB   r@   z-AsyncGenerator[httpx.Request, httpx.Response])Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrequires_response_bodyr&   Ústaticmethodr-   r9   r   r=   r?   © r   r   r   r   A   sX   „ ñð #Ðó(ð ò^ó ð^óJð  òó ðð ò	ó ñ	r   )r   rC   r   rC   r   Úobjectr@   rA   )r   rC   r@   rA   )r   rC   r@   rA   )Ú
__future__r   ÚloggingÚ	threadingÚtypingr   r   Útyping_extensionsr   ÚhttpxÚ_cacher   Ú_utilsr
   Ú
_constantsr   Ú__all__Ú	getLoggerrD   r   Ú__annotations__ÚLockr   Úsetr   r   r   r   ÚAuthr   rJ   r   r   Ú<module>r[      sx   ðÞ "ã Û ß ,Ý &ã å Ý Ý -àÐ
€à'�g×'Ñ'¨Ó1€€^Ó 1à �)—.‘.Ó"€Ù›E€�Ó !ó óó ô$:�e—j‘jõ :r   