
    b\j4                    J   % S SK Jr  S SKrS SKJrJrJrJrJrJ	r	  S SK
Jr  SSKJr  \(       a  SSKJrJr  / SQr\\/S	4   rS
\S'    \\/\	S   4   rS
\S'     " S S5      r\\\/S	4   rS
\S'   \\\/\	S   4   rS
\S'   \\\\4   rS
\S'   SS jrSS jrSS jrSS jrg)    )annotationsN)TYPE_CHECKINGAnyUnionCallableIterable	Awaitable)	TypeAlias   )
APIRequest)APIResponseAsyncAPIResponse)
MiddlewareCallNextAsyncCallNextMiddlewareCallableAsyncMiddlewareCallableMiddlewareInputAPIResponse[Any]r
   r   AsyncAPIResponse[Any]r   c                  ,    \ rS rSrSrSS jrSS jrSrg)	r   .   zBase class for client-level middleware.

Subclass and override `handle` (used by the sync client) and/or `handle_async`
(used by the async client). The default implementations delegate straight to
the rest of the chain.
c                    U" U5      $ N selfrequest	call_nexts      K/var/www/website/venv/lib/python3.13/site-packages/anthropic/_middleware.pyhandleMiddleware.handle6   s    !!    c                .   #    U" U5      I S h  vN $  N7fr   r   r   s      r    handle_asyncMiddleware.handle_async9   s     w''''s   r   N)r   r   r   r   returnr   )r   r   r   r   r'   r   )__name__
__module____qualname____firstlineno____doc__r!   r%   __static_attributes__r   r#   r    r   r   .   s    "(r#   r   r   r   r   c                    [        U [        5      (       a  [        U 5      R                  $ [	        U SS 5      n[        U[
        5      (       a  U$ [        U 5      $ )Nr(   )
isinstancer   typer(   getattrstrrepr)
middlewarenames     r    _middleware_namer6   B   sJ    *j))J(((:z40DdC((4>d:.>>r#   c                    [         R                  " U 5      (       a  g[        U SS5      nUSL=(       a    [         R                  " U5      $ )zWhether calling the given object returns a coroutine.

Unlike `inspect.iscoroutinefunction(obj)` this also handles class instances
that define an async `__call__` method.
T__call__N)inspectiscoroutinefunctionr1   )objcalls     r    _is_async_callabler=   I   sA     ""3''3
D)DtA ; ;D AAr#   c                   U  H  n[        U[        5      (       a  [        U5      R                  [        R                  L a  [	        S[        U5       S35      e[        R                  " [        U5      R                  5      (       a  [	        S[        U5       S35      eM  [        U5      (       d  [	        S[        U5       S35      e[        U5      (       d  M  [	        S[        U5       S35      e   g )Nmiddleware zW does not implement `handle()`; the synchronous client requires sync-capable middlewarezj defines `handle()` as an async function; the synchronous client requires `handle()` to be a sync function is not callablezP is an async function; the synchronous client requires sync middleware functions)
r/   r   r0   r!   	TypeErrorr6   r9   r:   callabler=   r4   entrys     r    validate_sync_middlewarerE   U   s    eZ((E{!!Z%6%66!"25"9!: ;N N  **4;+=+=>>!"25"9!: ;W W  ?
 %k*:5*A)BBRSTT&&.u56 7L L  r#   c                   U  H  n[        U[        5      (       a  [        U5      R                  [        R                  L a  [	        S[        U5       S35      e[        R                  " [        U5      R                  5      (       d  [	        S[        U5       S35      eM  [        U5      (       d  [	        S[        U5       S35      e[        U5      (       a  M  [	        S[        U5       S35      e   g )Nr?   z_ does not implement `handle_async()`; the asynchronous client requires async-capable middlewarezw defines `handle_async()` as a sync function; the asynchronous client requires `handle_async()` to be an async functionr@   zV is not an async function; the asynchronous client requires async middleware functions)
r/   r   r0   r%   rA   r6   r9   r:   rB   r=   rC   s     r    validate_async_middlewarerG   k   s    eZ((E{'':+B+BB!"25"9!: ;P P  ..tE{/G/GHH!"25"9!: ;` `  I
 %k*:5*A)BBRSTT#E**.u56 7N N  r#   )r4   objectr'   r2   )r;   rH   r'   bool)r4   zIterable[MiddlewareInput]r'   None)
__future__r   r9   typingr   r   r   r   r   r	   typing_extensionsr
   _requestr   	_responser   r   __all__r   __annotations__r   r   r   r   r   r6   r=   rE   rG   r   r#   r    <module>rR      s    "  K K '  8 
|-??@) @	 $ZL)<S2T$TUy U	( ( !)*h)?AS)S T I T%-z=.I9UlKm.m%n  n":/ACZ#Z[ [?	B,r#   