
    4Rj4                    8   U d dl mZ d dlZd dlmZmZmZmZmZm	Z	 d dl
mZ ddlmZ erddlmZmZ g dZeegd	f   Zd
ed<   	 eege	d   f   Zd
ed<   	  G d d      Zeeegd	f   Zd
ed<   eeege	d   f   Zd
ed<   eeeef   Zd
ed<   ddZddZddZddZy)    )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                       e Zd ZdZddZddZy)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                     ||      S N selfrequest	call_nexts      ]/var/www/html/meridian/meridian-ai/venv/lib/python3.12/site-packages/anthropic/_middleware.pyhandlezMiddleware.handle6   s    !!    c                .   K    ||       d {   S 7 wr   r   r   s      r   handle_asynczMiddleware.handle_async9   s     w''''s   N)r   r   r   r   returnr   )r   r   r   r   r$   r   )__name__
__module____qualname____doc__r    r#   r   r!   r   r   r   .   s    "(r!   r   r   r   r   c                    t        | t              rt        |       j                  S t	        | dd       }t        |t
              r|S t        |       S )Nr%   )
isinstancer   typer%   getattrstrrepr)
middlewarenames     r   _middleware_namer1   B   sD    *j)J(((:z40DdC(4>d:.>>r!   c                ~    t        j                  |       ryt        | dd      }|duxr t        j                  |      S )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iscoroutinefunctionr,   )objcalls     r   _is_async_callabler8   I   s>     ""3'3
D)DtA ; ;D AAr!   c                   | D ]  }t        |t              r~t        |      j                  t        j                  u rt	        dt        |       d      t        j                  t        |      j                        syt	        dt        |       d      t        |      st	        dt        |       d      t        |      st	        dt        |       d       y )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   r+   r    	TypeErrorr1   r4   r5   callabler8   r/   entrys     r   validate_sync_middlewarer@   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                   | D ]  }t        |t              r~t        |      j                  t        j                  u rt	        dt        |       d      t        j                  t        |      j                        ryt	        dt        |       d      t        |      st	        dt        |       d      t        |      rt	        dt        |       d       y )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   r+   r#   r<   r1   r4   r5   r=   r8   r>   s     r   validate_async_middlewarerB   k   s     eZ(E{'':+B+BB!"25"9!: ;P P  ..tE{/G/GH!"25"9!: ;` `  %k*:5*A)BBRSTT#E*.u56 7N N r!   )r/   objectr$   r-   )r6   rC   r$   bool)r/   zIterable[MiddlewareInput]r$   None)
__future__r   r4   typingr   r   r   r   r   r	   typing_extensionsr
   _requestr   	_responser   r   __all__r   __annotations__r   r   r   r   r   r1   r8   r@   rB   r   r!   r   <module>rM      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!   