o
    î6Wj4  ã                   @  s"  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r1d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„ 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d„Zd$dd„Zd%dd „Zd%d!d"„ZdS )&é    )Ú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                   @  s$   e Zd ZdZddd	„Zddd„ZdS )r   zìBase 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.
    Úrequestr   Ú	call_nextr   Úreturnr   c                 C  s   ||ƒS ©N© ©Úselfr   r   r   r   úd/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/anthropic/_middleware.pyÚhandle6   s   zMiddleware.handler   r   c                 Ã  s   �||ƒI d H S r   r   r   r   r   r   Úhandle_async9   s   €zMiddleware.handle_asyncN)r   r   r   r   r   r   )r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   .   s    
r   r   r   r   Ú
middlewareÚobjectr   Ústrc                 C  s6   t | tƒr
t| ƒjS t| dd ƒ}t |tƒr|S t| ƒS )Nr    )Ú
isinstancer   Útyper    Úgetattrr&   Úrepr)r$   Únamer   r   r   Ú_middleware_nameB   s   

r,   ÚobjÚboolc                 C  s,   t  | ¡rdS t| ddƒ}|duot  |¡S )z·Whether 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)   )r-   Úcallr   r   r   Ú_is_async_callableI   s   
r3   úIterable[MiddlewareInput]ÚNonec                 C  sš   | D ]H}t |tƒr.t|ƒjtju rtdt|ƒ› d�ƒ‚t t|ƒj¡r-tdt|ƒ› d�ƒ‚qt|ƒs<tdt|ƒ› d�ƒ‚t	|ƒrJtdt|ƒ› d�ƒ‚qd S )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   Ú	TypeErrorr,   r0   r1   Úcallabler3   ©r$   Úentryr   r   r   Úvalidate_sync_middlewareU   ó&   
ÿÿÿÿÿòr<   c                 C  sš   | D ]H}t |tƒr.t|ƒjtju rtdt|ƒ› d�ƒ‚t t|ƒj¡s-tdt|ƒ› d�ƒ‚qt|ƒs<tdt|ƒ› d�ƒ‚t	|ƒsJtdt|ƒ› d�ƒ‚qd S )Nr6   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 functionr7   zV is not an async function; the asynchronous client requires async middleware functions)
r'   r   r(   r   r8   r,   r0   r1   r9   r3   r:   r   r   r   Úvalidate_async_middlewarek   r=   r>   )r$   r%   r   r&   )r-   r%   r   r.   )r$   r4   r   r5   )Ú
__future__r   r0   Útypingr   r   r   r   r   r   Útyping_extensionsr	   Ú_requestr   Ú	_responser   r   Ú__all__r   Ú__annotations__r   r   r   r   r   r,   r3   r<   r>   r   r   r   r   Ú<module>   s(     	


