
    b\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 :func:`_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     X/var/www/website/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 :class:`_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    * gt$$M**	$Y//#W-Gk!jS1A3&G&G$W\2GL  Nr   c                P    [        U [        5      (       a  U R                  5       $ U $ )zInverse of :func:`_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'C5!!#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>    %##%%''
od5k&:&:%;;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      ::gmDKKG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   