ó
    °"³j¤  ã                  ó¤   • S SK Jr  S SKrS SKJrJrJrJr  S SKJ	r	  / SQr
 " S S\5      r\" S5      rSS	 jrSS
 jrSS jrSS.SS jjrSS jrg)é    )ÚannotationsN)ÚAnyÚDictÚOptionalÚcast)Ú	SecretStr)r   Ú_NonObjectPayloadErrorÚ_wrap_secret_fieldsÚ_unwrap_secretÚ_json_dumps_secretsÚ_strip_tracebackc                  ó0   ^ • \ rS rSrSrSU 4S jjrSrU =r$ )r	   é   u  Raised by `_wrap_secret_fields` for JSON payloads that are not
objects. Carries only the payload's type name â€” a non-object payload can
be an echo of the request (assertion included), so it must never bind in
a caller's frame or ride along in an exception.
c                ó6   >• [         TU ]  SU 35        Xl        g )Nzexpected a JSON object, got )ÚsuperÚ__init__Ú	type_name)Úselfr   Ú	__class__s     €Ú_/home/mande/repo/quber/.venv/lib/python3.13/site-packages/anthropic/lib/credentials/_secrets.pyr   Ú_NonObjectPayloadError.__init__   s   ø€ Ü‰ÑÐ7¸	°{ÐCÔDØ"�ó    )r   )r   ÚstrÚreturnÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__static_attributes__Ú__classcell__)r   s   @r   r	   r	      s   ø† ñ÷#õ #r   r	   )	ÚtypeÚversionÚ
expires_atÚ
token_typeÚ
expires_inÚscopeÚerrorÚerror_descriptionÚ	error_uric                ó  • [        U [        5      (       d!  [        U 5      R                  nA [	        U5      e[        SU 5      nU HD  nU[        ;  d  M  [        UR                  U5      [        5      (       d  M5  [        X#   5      X#'   MF     U$ )u  Wrap the secret fields of a parsed JSON object in `SecretStr`.

Called at every boundary where credential material enters SDK code.
Traceback frames retain their locals, so any dict a raise site (or a
frame an error merely propagates through) still holds must already be
redacted â€” `SecretStr` renders as `SecretStr('**********')` under
crash reporters that capture and render locals.

String values are secret unless their key is in `_PLAIN_KEYS`; wrapped
empty strings stay falsy (`SecretStr` defines `__len__` across the
supported pydantic range), so `if not creds.get("access_token")` checks
behave unchanged. Only top-level values are wrapped â€” the credential
formats are flat; revisit if a nested shape ever appears. Mutates
`payload` in place â€” a copy would leave the raw-valued original
reachable â€” and returns it.

Non-object payloads raise `_NonObjectPayloadError` from this frame,
with the payload unbound first, so the raw value never lands in any frame
of the traceback â€” callers translate to their own redacted error.
úDict[str, Any])
Ú
isinstanceÚdictr#   r   r	   r   Ú_PLAIN_KEYSÚgetr   r   )Úpayloadr   ÚmappingÚkeys       r   r
   r
   3   sw   € ô* �gœt×$Ñ$Ü˜“M×*Ñ*ˆ	ØÜ$ YÓ/Ð/ÜÐ# WÓ-€GÛˆØ”kÕ!¤j°·±¸SÓ1AÄ3×&GÓ&GÜ$ W¡\Ó2ˆG‹Lñ ð €Nr   c                óP   • [        U [        5      (       a  U R                  5       $ U $ )zƒInverse of `_wrap_secret_fields` for a single value; pass-through
for values that were never wrapped (absent or non-string fields).)r.   r   Úget_secret_value©Úvalues    r   r   r   S   s$   € ô (2°%¼×'CÑ'Cˆ5×!Ñ!Ó#ÐNÈÐNr   c                ó�   • [        U [        5      (       a  U R                  5       $ [        S[	        U 5      R
                   S35      e)NzObject of type z is not JSON serializable)r.   r   r6   Ú	TypeErrorr#   r   r7   s    r   Ú_json_defaultr;   Y   s>   € Ü�%œ×#Ñ#Ø×%Ñ%Ó'Ð'Ü
�o¤d¨5£k×&:Ñ&:Ð%;Ð;TÐUÓ
VÐVr   )Úindentc               óR   • [         R                  " X[        S9R                  S5      $ )zÅ`json.dumps` with `SecretStr` values unwrapped at dump time.

Returns bytes so call sites can pass the result inline (request content,
`os.write`) without binding the raw serialization to a local.
)r<   Údefaultzutf-8)ÚjsonÚdumpsr;   Úencode)r2   r<   s     r   r   r   _   s    € ô �:Š:�g´mÑD×KÑKÈGÓTÐTr   c                ó   • SU l         U $ )u�  Detach the frames chained onto `err` before raising from it.

Foreign frames (json decoder, httpx transport) hold raw payloads â€”
request bodies, response text, credentials-file contents â€” as locals.
Dropping the traceback removes them from every renderer and programmatic
chain-walker, while the cause's type and message (which never carry the
payload) stay visible in renderings.
N)Ú__traceback__)Úerrs    r   r   r   h   s   € ð €CÔØ€Jr   )r2   r   r   r-   )r8   r   r   r   )r2   r   r<   zOptional[int]r   Úbytes)rD   ÚBaseExceptionr   rF   )Ú
__future__r   r?   Útypingr   r   r   r   Úpydanticr   Ú__all__r:   r	   Ú	frozensetr0   r
   r   r;   r   r   © r   r   Ú<module>rM      s\   ðÝ "ã ß ,Ó ,å ò€ô	#˜Yô 	#ñ  ðó€ô"ô@OôWð BF÷ Uõ
r   