o
    Ù°“im  ã                   @   s~  d dl mZ d dlmZ d dlmZ d dlmZ ddlmZ ddl	m
Z
 d dlmZmZmZmZ z.d d	lZd d
lmZmZmZ d dlmZ d dlmZ ddlm
Z ddlmZ ddlmZ W n eyi   edƒ‚w erud dlmZm Z  nG dd„ dƒZG dd„ dƒZ!e!ƒ Z edƒZ"eej#ƒZ$ddde%fdd„Z&d,dd„Z'd,dd „Z(		!		!d-d"d#„Z)d.d%d&„Z*d/d(d)„Z+G d*d+„ d+eƒZ,d	S )0é    ©Úwraps)ÚIntegration)Úparse_version)ÚDidNotEnableé   )ÚClientInterceptor©ÚServerInterceptor)ÚTYPE_CHECKINGÚAnyÚOptionalÚSequenceN)ÚChannelÚServerÚintercept_channel)r   )r   )Ú!SentryUnaryUnaryClientInterceptor)Ú"SentryUnaryStreamClientInterceptorzgrpcio is not installed.)Ú	ParamSpecÚCallablec                   @   ó   e Zd Zdd„ ZdS )r   c                 C   s   d | _ d | _d S ©N)ÚargsÚkwargs©ÚselfÚ_© r   úY/home/ubuntu/.local/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/__init__.pyÚ__init__$   s   
zParamSpec.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   #   ó    r   c                   @   r   )Ú	_Callablec                 C   s   d S r   r   r   r   r   r   Ú__getitem__*   s   z_Callable.__getitem__N)r    r!   r"   r%   r   r   r   r   r$   )   r#   r$   ÚPÚchannelr   Úreturnc                 C   sV   t | dd ƒ}|d ur)t|tƒrdS t | dd ƒ}|d u rdS |} t | dd ƒ}|d us
dS )NÚ_interceptorTÚ_channelF)ÚgetattrÚ
isinstancer   )r'   ÚinterceptorÚinner_channelr   r   r   Ú_is_channel_intercepted5   s   
÷r/   ÚfuncúCallable[P, Channel]c                    s   t ˆ ƒd	‡ fdd„ƒ}|S )
z4Wrapper for synchronous secure and insecure channel.r   r   r   r(   r   c                     s&   ˆ | i |¤Ž}t |ƒst|tƒ ƒS |S r   )r/   r   r   )r   r   r'   ©r0   r   r   Úpatched_channelH   s   z+_wrap_channel_sync.<locals>.patched_channelN)r   r   r   r   r(   r   r   ©r0   r3   r   r2   r   Ú_wrap_channel_syncE   s   r5   c                 C   s"   t | ƒ						ddd„ƒ}|S )	Nr'   r   Úinterceptorsúgrpc.ServerInterceptorr(   c                 W   s0   t | ƒrtdd„ |D ƒƒ}n|}t| g|¢R Ž S )Nc                 S   ó   g | ]	}t |tƒs|‘qS r   )r,   r   ©Ú.0r-   r   r   r   Ú
<listcomp>Z   ó    ýÿzN_wrap_intercept_channel.<locals>.patched_intercept_channel.<locals>.<listcomp>)r/   Útupler   )r'   r6   r   r   r   Úpatched_intercept_channelT   s   þÿz:_wrap_intercept_channel.<locals>.patched_intercept_channel)r'   r   r6   r7   r(   r   r   )r0   r>   r   r   r   Ú_wrap_intercept_channelS   s   ÿÿþr?   úCallable[P, AsyncChannel]c                    ó.   t ˆ ƒddœ								
d‡ fdd„ƒ}|S )z5Wrapper for asynchronous secure and insecure channel.N©r6   r   úP.argsr6   ú.Optional[Sequence[grpc.aio.ClientInterceptor]]r   úP.kwargsr(   r   c                    s.   t ƒ tƒ g}g |¢| pg ¢} ˆ |d| i|¤ŽS )Nr6   )Ú AsyncUnaryUnaryClientInterceptorÚ AsyncUnaryStreamClientIntercetor)r6   r   r   Úsentry_interceptorsr2   r   r   r3   l   s
   þz,_wrap_channel_async.<locals>.patched_channel)r   rC   r6   rD   r   rE   r(   r   r   r4   r   r2   r   Ú_wrap_channel_asyncg   s   þÿþýürI   úCallable[P, Server]c                    rA   )zWrapper for synchronous server.NrB   r   rC   r6   ú*Optional[Sequence[grpc.ServerInterceptor]]r   rE   r(   r   c                    s8   dd„ | pg D ƒ} t ƒ }|g| pg ¢} ˆ |d| i|¤ŽS )Nc                 S   r8   r   )r,   r
   r9   r   r   r   r;   …   r<   z=_wrap_sync_server.<locals>.patched_server.<locals>.<listcomp>r6   r	   ©r6   r   r   Úserver_interceptorr2   r   r   Úpatched_server   s   þz)_wrap_sync_server.<locals>.patched_server©r   rC   r6   rK   r   rE   r(   r   r   )r0   rN   r   r2   r   Ú_wrap_sync_server|   s   þÿþýürP   úCallable[P, AsyncServer]c                    rA   )z Wrapper for asynchronous server.NrB   r   rC   r6   rK   r   rE   r(   r   c                    sV   t ƒ }|g| pg ¢} ztd urtdk rt| ƒ} W n	 ty!   Y nw ˆ |d| i|¤ŽS )N)r   é*   r   r6   )ÚAsyncServerInterceptorÚGRPC_VERSIONr=   Ú	ExceptionrL   r2   r   r   Úpatched_aio_server”   s   ÿþ€ÿz._wrap_async_server.<locals>.patched_aio_serverrO   r   )r0   rV   r   r2   r   Ú_wrap_async_server‘   s   þÿþýürW   c                   @   s   e Zd ZdZeddd„ƒZdS )ÚGRPCIntegrationÚgrpcr(   Nc                  C   sl   dd l } t| jƒ| _t| jƒ| _t| jƒ| _t| jjƒ| j_t| jjƒ| j_t| j	ƒ| _	t
| jj	ƒ| j_	d S )Nr   )rY   r5   Úinsecure_channelÚsecure_channelr?   r   rI   ÚaiorP   ÚserverrW   )rY   r   r   r   Ú
setup_once²   s   zGRPCIntegration.setup_once)r(   N)r    r!   r"   Ú
identifierÚstaticmethodr^   r   r   r   r   rX   ¯   s    rX   )r0   r1   r(   r1   )r0   r@   r(   r@   )r0   rJ   r(   rJ   )r0   rQ   r(   rQ   )-Ú	functoolsr   Úsentry_sdk.integrationsr   Úsentry_sdk.utilsr   r   Úclientr   r]   r
   Útypingr   r   r   r   rY   r   r   r   Úgrpc.aioÚAsyncChannelÚAsyncServerÚ
aio.serverrS   Ú
aio.clientr   rF   r   rG   ÚImportErrorr   r   r$   r&   Ú__version__rT   Úboolr/   r5   r?   rI   rP   rW   rX   r   r   r   r   Ú<module>   sH    ÿ


ÿ
þ

