o
    Zh                     @   s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 er8d dlmZmZ d dlmZmZmZmZ d	gZG d
d	 d	e
Zdd Zdd Zdd ZdS )    )absolute_importN)Hub)MYPY)OP)Integration)AddressFamily
SocketKind)TupleOptionalUnionListSocketIntegrationc                   @   s   e Zd ZdZedd ZdS )r   socketc                   C   s   t   t  dS )zs
        patches two of the most used functions of socket: create_connection and getaddrinfo(dns resolver)
        N)_patch_create_connection_patch_getaddrinfo r   r   U/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/socket.py
setup_once   s   
zSocketIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r      s    c              	   C   s4   z|   } W n ttfy   Y nw d| |f }|S )Nz%s:%s)decodeUnicodeDecodeErrorAttributeError)hostportdescriptionr   r   r   _get_span_description   s   r   c                     s$   t j t jd f fdd	} | t _d S )Nc                    s   t j}|td u r | ||dS |jtjt| d | d d!}|d|  |d| |d|  | ||dW  d    S 1 sDw   Y  d S )N)addresstimeoutsource_addressr      opr   r    r!   r"   )	r   currentget_integrationr   
start_spanr   ZSOCKET_CONNECTIONr   set_data)r    r!   r"   hubspanZreal_create_connectionr   r   create_connection.   s"   $z3_patch_create_connection.<locals>.create_connection)r   r-   _GLOBAL_DEFAULT_TIMEOUT)r-   r   r,   r   r   *   s
   
r   c                     s   t j d fdd	} | t _d S )Nr   c                    s   t j}|td u r | |||||S |jtjt| |d}|d|  |d|  | |||||W  d    S 1 s>w   Y  d S )Nr$   r   r   )	r   r&   r'   r   r(   r   Z
SOCKET_DNSr   r)   )r   r   familytypeprotoflagsr*   r+   Zreal_getaddrinfor   r   getaddrinfoM   s   $z'_patch_getaddrinfo.<locals>.getaddrinfo)r   r   r   r   )r   r4   )r4   r   r3   r   r   I   s   
r   )
__future__r   r   Z
sentry_sdkr   Zsentry_sdk._typesr   Zsentry_sdk.constsr   Zsentry_sdk.integrationsr   r   r   typingr	   r
   r   r   __all__r   r   r   r   r   r   r   r   <module>   s    