o
    ai_                  	   @   s  d dl mZmZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZmZmZ d dlmZ d dlmZ zd dlZW n eyO   dZY nw zd dlZW n eya   dZY nw z
d dlZeduZW n eyw   dZY nw z
d dlZeduZW n ey   dZY nw d dlZd dlZd dlZd dlmZ d dlmZm Z m!Z!m"Z" d d	l#m$Z$m%Z%m&Z& d d
l'm(Z(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/ e,rd dl+m0Z0 d dl+m1Z1 d dl+m2Z2 d dl+m3Z3 d dl+m4Z4 d dl+m5Z5 d dl+m6Z6 d dl+m7Z7 d dl+m8Z8 d dl+m9Z9 d dl:m;Z; d dl:m<Z< d dl=m>Z>m?Z? g Z@ejAdd dfejBdd dfejBdd dfejBd d d!ffD ]ZCze@DeCd  eCd  eCd" f W q? eEy^   Y q?w d#d$d%eFd&d'fd(d)ZGG d*d+ d+eZH	dCd%eFd,d-d&d.fd/d0ZIG d1d2 d2eHZJG d3d4 d4eJZKG d5d6 d6eKZLG d7d8 d8eJZMesG d9d: d:eLZNnG d;d: d:eKZNG d<d= d=eHZOdDdAdBZPdS )E    )ABCabstractmethodN)datetime	timedeltatimezone)defaultdict)
getproxiesF)EndpointType)Dsnloggercapture_internal_exceptionsmark_sentry_task_internal)BackgroundWorkerWorkerAsyncWorker)EnvelopeItem
PayloadRef)TYPE_CHECKINGcastListDict)Any)Callable)DefaultDict)Iterable)Mapping)Optional)Self)Tuple)Type)Union)PoolManager)ProxyManager)EventEventDataCategoryc                   C   
   t tdS )NSO_KEEPALIVEgetattrsocket r+   r+   R/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/sentry_sdk/transport.py<lambda>I      
 r-      c                   C   r&   )NTCP_KEEPIDLEr(   r+   r+   r+   r,   r-   J   r.   -   c                   C   r&   )NTCP_KEEPINTVLr(   r+   r+   r+   r,   r-   K   r.   
   c                   C   r&   )NTCP_KEEPCNTr(   r+   r+   r+   r,   r-   L   r.         responser   headerreturnOptional[str]c                    s"   |   t fdd| jD dS )z<Case-insensitive header lookup for httpcore-style responses.c                 3   s0    | ]\}}| d   kr| d V  qdS )asciiN)decodelower).0keyvalheader_lowerr+   r,   	<genexpr>Z   s    z-_get_httpcore_header_value.<locals>.<genexpr>N)r=   nextheaders)r7   r8   r+   rA   r,   _get_httpcore_header_valueV   s   
rF   c                   @   s   e Zd ZU dZdZded< d'd(d
dZd)ddZed*ddZ		d'ddde
ddd	dfddZd+ddZ		d,dddeddd d!d"ed	df
d#d$Zddd	efd%d&ZdS )-	TransportzWBaseclass for all transports.

    A transport is used to send an event to sentry.
    NzOptional[Dsn]
parsed_dsnselfr   optionsOptional[Dict[str, Any]]r9   c                 C   sB   || _ |r|d d ur|d rt|d |d| _d S d | _d S )Ndsnorg_id)rJ   r
   getrH   rI   rJ   r+   r+   r,   __init__k   s   
zTransport.__init__eventr$   c                 C   s.   t jdtdd t }|| | | dS )z
        DEPRECATED: Please use capture_envelope instead.

        This gets invoked with the event dictionary when an event should
        be sent to sentry.
        zAcapture_event is deprecated, please use capture_envelope instead!r6   
stacklevelN)warningswarnDeprecationWarningr   	add_eventcapture_envelope)rI   rQ   enveloper+   r+   r,   capture_eventr   s   
zTransport.capture_eventrY   r   c                 C      dS )a  
        Send an envelope to Sentry.

        Envelopes are a data container format that can hold any type of data
        submitted to Sentry. We use it to send all event data (including errors,
        transactions, crons check-ins, etc.) to Sentry.
        Nr+   )rI   rY   r+   r+   r,   rX      s   	zTransport.capture_envelopetimeoutcallbackzOptional[Any]c                 C   r[   )z
        Wait `timeout` seconds for the current events to be sent out.

        The default implementation is a no-op, since this method may only be relevant to some transports.
        Subclasses should override this method if necessary.
        Nr+   rI   r\   r]   r+   r+   r,   flush   s   zTransport.flushc                 C   r[   )z
        Forcefully kills the transport.

        The default implementation is a no-op, since this method may only be relevant to some transports.
        Subclasses should override this method if necessary.
        Nr+   rI   r+   r+   r,   kill   s   zTransport.killr/   quantityreasondata_categoryOptional[EventDataCategory]itemOptional[Item]rc   c                C   r[   )a  This increments a counter for event loss by reason and
        data category by the given positive-int quantity (default 1).

        If an item is provided, the data category and quantity are
        extracted from the item, and the values passed for
        data_category and quantity are ignored.

        When recording a lost transaction via data_category="transaction",
        the calling code should also record the lost spans via this method.
        When recording lost spans, `quantity` should be set to the number
        of contained spans, plus one for the transaction itself. When
        passing an Item containing a transaction via the `item` parameter,
        this method automatically records the lost spans.
        Nr+   )rI   rd   re   rg   rc   r+   r+   r,   record_lost_event   s   zTransport.record_lost_eventc                 C   r[   )NTr+   r`   r+   r+   r,   
is_healthy      zTransport.is_healthyN)rI   r   rJ   rK   r9   N)rI   r   rQ   r$   r9   NrI   r   rY   r   r9   NrI   r   r9   NNN)__name__
__module____qualname____doc__rH   __annotations__rP   rZ   r   rX   floatr_   ra   strintri   boolrj   r+   r+   r+   r,   rG   c   sD   
 



rG   nowzOptional[datetime]z6Iterable[Tuple[Optional[EventDataCategory], datetime]]c              
   c   s    |d u rt tj}| dD ]8}z+| d}|d d \}}|tt|d }|r2|dp3dD ]}||fV  q4W q tt	fyH   Y qw d S )N,:r6   seconds;rl   )
r   ry   r   utcsplitstripr   rw   LookupError
ValueError)r8   ry   limit
parametersretry_after_val
categoriesretry_aftercategoryr+   r+   r,   _parse_rate_limits   s   r   c                   @   s  e Zd ZdZdZdad	d
ZdbddZ		dcdddedddddeddf
ddZ	dddddeddfddZ
						dddd Z	!	"deddd#d$d%ed&eddf
d'd(Z					#	$		dfd)d*Z			+	,		dgd-d.Zddd/eddfd0d1Z	3dhddd4ed5eddfd6d7Zd8edefd9d:Zdddefd;d<Zdddefd=d>Zdddefd?d@Z			#	A		BdidCdDZ			#	A		EdjdFdGZ	2dkdddHeddfdIdJZdldKdLZedmdMdNZdmdOdPZdddQdRdefdSdTZ				UdndVdWZdddXedYdZd[dd+d\ddfd]d^Zdod_d`Z dS )pHttpTransportCorez0Shared base class for sync and async transports.   rI   r   rJ   Dict[str, Any]r9   Nc                 C   sH  ddl m} t| | | jd usJ || _| || _| jd| | _	i | _
tj | _tt| _t | _|  | _tj| _|di }|d|d}|d|d us[td u r]dnd	}|d	krqtd u rqtd
 d}d }|dvrtd| d| _d | _n|| _|d ur|| _d S | jdkrd| _d S | jd	krd| _d S d S )Nr   )VERSIONzsentry.python/%s_experimentstransport_compression_level transport_zlib_compression_leveltransport_compression_algogzipbrzSYou asked for brotli compression without the Brotli module, falling back to gzip -9)r   r   z2Unknown compression algo %s, disabling compression	      )sentry_sdk.constsr   rG   rP   rH   rJ   _create_worker_workerto_auth_auth_disabled_untilurllib3utilRetry_retryr   rw   _discarded_eventstime_last_client_report_sent
_make_pool_pool
sentry_sdkHub_hub_clsrN   brotlir   warning_compression_level_compression_algo)rI   rJ   r   experimentscompression_levelcompression_algor+   r+   r,   rP      sX   






zHttpTransportCore.__init__r   c                 C      t  rl   NotImplementedErrorrO   r+   r+   r,   r        z HttpTransportCore._create_workerr/   rb   rd   re   rf   rg   rh   rc   c                C   s   | j d sd S |d urY|j}d}|dkr7| pi }ttttttf  |	dp)g d }| j
|d|d n*|dkrL|rLt| }| j
|d|d n|d	krXt| pWd}n|d u ratd
| j||f  |7  < d S )Nsend_client_reportsr/   transactionspansspanrb   log_itemlog_byte
attachmentzdata category not provided)rJ   re   get_transaction_eventlenr   r   r   rv   objectrN   ri   	get_bytes	TypeErrorr   )rI   rd   re   rg   rc   rQ   
span_count
bytes_sizer+   r+   r,   ri     s&   
&z#HttpTransportCore.record_lost_eventr7   r   r8   r:   c                 C   s   |j |S rl   )rE   rN   rI   r7   r8   r+   r+   r,   _get_header_value?  s   z#HttpTransportCore._get_header_value2Union[urllib3.BaseHTTPResponse, httpcore.Response]c                 C   s   |  |d}|rtd | jt| d S |jdkrEtd |  |d}|d ur1| j|nd p4d}t	
tjt|d | jd < d S d S )Nzx-sentry-rate-limitsz%Rate-limited via x-sentry-rate-limits  zRate-limited via 429zRetry-After<   r|   )r   r   r   r   updater   statusr   parse_retry_afterr   ry   r   r   r   )rI   r7   r8   retry_after_valuer   r+   r+   r,   _update_rate_limitsD  s"   


z%HttpTransportCore._update_rate_limitsnetworknetwork_errorrY   Optional[Envelope]loss_reasonrecord_reasonc                    s.   dt dd f fdd}| || d S )Nrd   r9   c                    s8    d u rj | dd d S  jD ]	}j | |d qd S )Nerror)re   rg   )ri   items)rd   rg   rY   rI   r+   r,   record_lossc  s
   
z<HttpTransportCore._handle_request_error.<locals>.record_loss)rv   on_dropped_event)rI   rY   r   r   r   r+   r   r,   _handle_request_error]  s   
z'HttpTransportCore._handle_request_errorc                 C   s   |  | |jdkr1d}t|dt|dd }|d ur"|d| d7 }t| | j|ddd	 d S |jd
kr=| d d S |jdksG|jdk rdtd|jt|dt|dd  | j|d|jd d S d S )Ni  z;HTTP 413: Event dropped due to exceeded envelope size limitdatacontentz (body: )
status_413
send_error)rY   r   r   r   
status_429i,     z%Unexpected status code: %s (body: %s)z	status_{}rY   r   )r   r   r)   r   r   r   r   format)rI   r7   rY   size_exceeded_messageresponse_messager+   r+   r,   _handle_responsem  s4   






z"HttpTransportCore._handle_responserE   Dict[str, str]c                 C   s&   | t| jjt| j d d S )N)z
User-AgentzX-Sentry-Auth)r   rv   r   client	to_header)rI   rE   r+   r+   r,   _update_headers  s
   
z!HttpTransportCore._update_headers_reasonc                 C   s   d S rl   r+   )rI   r   r+   r+   r,   r     rk   z"HttpTransportCore.on_dropped_eventFr   forceintervalc                 C   st   | j d sd S |s| jt | k sd S | j}tt| _t | _|s%d S ttt dd | D ddddS )Nr   c                 S   s    g | ]\\}}}|||d qS ))rd   r   rc   r+   )r>   r   rd   rc   r+   r+   r,   
<listcomp>  s    
zBHttpTransportCore._fetch_pending_client_report.<locals>.<listcomp>)	timestampdiscarded_events)jsonclient_report)type)	rJ   r   r   r   r   rw   r   r   r   )rI   r   r   r   r+   r+   r,   _fetch_pending_client_report  s&   


z.HttpTransportCore._fetch_pending_client_reportr   c                    s&   dddt f fdd}||p|d S )Nbucketr   r9   c                    s$    j | }|d uo|ttjkS rl   )r   rN   r   ry   r   r   )r   tsr`   r+   r,   	_disabled  s   z4HttpTransportCore._check_disabled.<locals>._disabled)rx   )rI   r   r   r+   r`   r,   _check_disabled  s   z!HttpTransportCore._check_disabledc                 C   s   t dd | j D S )Nc                 s   s     | ]}|t tjkV  qd S rl   )r   ry   r   r   )r>   r   r+   r+   r,   rC     s    
z5HttpTransportCore._is_rate_limited.<locals>.<genexpr>)anyr   valuesr`   r+   r+   r,   _is_rate_limited  s   z"HttpTransportCore._is_rate_limitedc                 C   s
   | j  S rl   )r   fullr`   r+   r+   r,   _is_worker_full  s   
z!HttpTransportCore._is_worker_fullc                 C   s   |   p|   S rl   )r   r   r`   r+   r+   r,   rj     s   zHttpTransportCore.is_healthyr   5Optional[Tuple[Envelope, io.BytesIO, Dict[str, str]]]c                 C   s   g }|j D ]}| |jr|jdv r| d | jd|d q|| qt|j|d}|j s1d S | jdd}|d urA|j | | 	|\}}| j
d usOJ td|j| j
j| j
j d	d
i}|rf||d< |||fS )N)r   r   defaultstatsdself_rate_limitsratelimit_backoffr   )rE   r   r   )r   z(Sending envelope [%s] project:%s host:%szContent-Typezapplication/x-sentry-envelopezContent-Encoding)r   r   re   r   ri   appendr   rE   r   _serialize_enveloperH   r   debugdescription
project_idhost)rI   rY   	new_itemsrg   client_report_itemcontent_encodingbodyrE   r+   r+   r,   _prepare_envelope  s4   



z#HttpTransportCore._prepare_envelope tuple[Optional[str], io.BytesIO]c                 C   s   d }t  }| jdks| jd u r|| ||fS | j}| jdkr6td ur6|tj| | jd ||fS t	j
|d| jd}|| W d    ||fS 1 sRw   Y  ||fS )Nr   r   )qualityw)fileobjmodecompresslevel)ioBytesIOr   r   serialize_intor   writecompress	serializer   GzipFile)rI   rY   r  r	  fr+   r+   r,   r    s,   


z%HttpTransportCore._serialize_envelopehttp2c           	      C   s   |dd}d}| j d dur| j d }|du rg }dd |D }tD ]}|d |d f|vr3|| q"|dur<||d< t }|| j d	 pVtjd
pVtjdpVt	
  | j d pbtjd}| j d pmtjd}|durx||| ||d< |S )zDShared pool options for httpcore-based transports (Http2 and Async).   )r  retriesNsocket_optionsc                 S      h | ]
}|d  |d fqS r   r/   r+   r>   or+   r+   r,   	<setcomp>,      z?HttpTransportCore._get_httpcore_pool_options.<locals>.<setcomp>r   r/   ca_certsSSL_CERT_FILEREQUESTS_CA_BUNDLE	cert_fileCLIENT_CERT_FILEkey_fileCLIENT_KEY_FILEssl_context)rJ   KEEP_ALIVE_SOCKET_OPTIONSr   sslcreate_default_contextload_verify_locationsosenvironrN   certifiwhereload_cert_chain)	rI   r  rJ   r  used_optionsdefault_optionr*  r&  r(  r+   r+   r,   _get_httpcore_pool_options  s<   




z,HttpTransportCore._get_httpcore_pool_optionsc                 C   s   | j du rdS | | j }d}| jd }| j jdkr)|dkr)|p(| o(t d}| jd }|s?|dkr?|p>| o>t d}|pBdS )zJResolve proxy URL from options and environment. Returns proxy URL or None.Nhttps_proxyhttps 
http_proxyhttp)rH   _in_no_proxyrJ   schemer   rN   )rI   no_proxyproxyr7  r:  r+   r+   r,   _resolve_proxyC  s   


z HttpTransportCore._resolve_proxyc                 C   s   d| j | j | j | j diS )Nr\   )poolconnectr  read)TIMEOUTr`   r+   r+   r,   _timeout_extensionsW  s   z%HttpTransportCore._timeout_extensionsc                 C   r   rl   r   r`   r+   r+   r,   _get_pool_optionsb  r   z#HttpTransportCore._get_pool_optionsrH   r
   c                 C   sN   t  d}|s
dS |dD ]}| }|j|s!|j|r$ dS qdS )NnoFrz   T)r   rN   r   r   r  endswithnetloc)rI   rH   r>  r  r+   r+   r,   r<  e  s   zHttpTransportCore._in_no_proxyUnion[PoolManager, ProxyManager, httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool, httpcore.AsyncSOCKSProxy, httpcore.AsyncHTTPProxy, httpcore.AsyncConnectionPool]c                 C   r   rl   r   r`   r+   r+   r,   r   o  s   zHttpTransportCore._make_poolmethodendpoint_typer	   r	  Mapping[str, str]c                 C   r   rl   r   rI   rK  rL  r	  rE   r+   r+   r,   _requestt  s   zHttpTransportCore._requestc                 C   s   t d | j  d S )NKilling HTTP transport)r   r  r   ra   r`   r+   r+   r,   ra   }  s   
zHttpTransportCore.killrI   r   rJ   r   r9   NrI   r   rJ   r   r9   r   ro   )rI   r   r7   r   r9   N)r   r   )rI   r   r7   r   rY   r   r9   N)rI   r   rE   r   r9   N)Fr   )rI   r   rY   r   r9   r   )rI   r   rY   r   r9   r  F)rI   r   r9   r:   rI   r   r9   r   )rI   r   r9   rJ  rn   )!rp   rq   rr   rs   rD  rP   r   rv   rw   ri   r   r   r   r   r   r   rx   r   r   r   r   rj   r
  r  r6  r@  propertyrE  rF  r<  r   rO  ra   r+   r+   r+   r,   r      s    

<
(



(

 
/


(




	r   c                   @   s   e Zd ZdZd)dd	Z	d*ddd
eddddddddfddZd+ddZd,dddeddfddZ					d-ddZ
	d*dddeddddfd d!Zed.d"d#Zed/d%d&Zejd0d(d&ZdS )1BaseHttpTransportz&The base HTTP transport (synchronous).rI   r   rY   r   r9   Nc                 C   s8   |  |}|d ur|\}}}| j| |tj|d d S N)rE   rL  rY   r
  _send_requestgetvaluer	   ENVELOPErI   rY   _prepared_enveloper	  rE   r+   r+   r,   _send_envelope  s   

z BaseHttpTransport._send_enveloper	  rE   r   rL  r	   r   c                 C   sf   |  | z
| d|||}W n ty   | j|dd  w z| j||d W |  d S |  w NPOSTr   r   )r7   rY   )r   rO  	Exceptionr   r   closerI   r	  rE   rL  rY   r7   r+   r+   r,   rY    s   
zBaseHttpTransport._send_requestrJ   r   r   c                 C      t |d dS Ntransport_queue_size)
queue_size)r   rO   r+   r+   r,   r        z BaseHttpTransport._create_workerFr   c                 C   s0   | j |dd}|d ur| t|gd d S d S Nr   )r   r   )r   r   rX   r   rI   r   r   r+   r+   r,   _flush_client_reports  s   z'BaseHttpTransport._flush_client_reportsc                    H   d fdd}j |s d  jD ]}jd|d qd S d S )Nr9   c                      s>   t       W d    d S 1 sw   Y  d S rl   r   r^  rl  r+   r   r+   r,   send_envelope_wrapper  s   

"zABaseHttpTransport.capture_envelope.<locals>.send_envelope_wrapper
full_queuequeue_overflowr   r9   Nr   submitr   r   ri   rI   rY   ro  rg   r+   r   r,   rX     s   

z"BaseHttpTransport.capture_enveloper\   r]   &Optional[Callable[[int, float], None]]c                    s<   t d |dkr j fdd  j|| d S d S )NFlushing HTTP transportr   c                          j ddS NT)r   rl  r+   r`   r+   r,   r-         z)BaseHttpTransport.flush.<locals>.<lambda>r   r  r   rt  r_   r^   r+   r`   r,   r_     s
   
zBaseHttpTransport.flushc                   C   s   t jdtdd dS )zRConvenience method to warn users about the deprecation of the `hub_cls` attribute.zNThe `hub_cls` attribute is deprecated and will be removed in a future release.r  rR   N)rT   rU   rV   r+   r+   r+   r,   _warn_hub_cls  s
   
zBaseHttpTransport._warn_hub_clstype[sentry_sdk.Hub]c                 C   s   t   | jS )QDEPRECATED: This attribute is deprecated and will be removed in a future release.HttpTransportr}  r   r`   r+   r+   r,   hub_cls  s   zBaseHttpTransport.hub_clsvaluec                 C   s   t   || _dS )r  Nr  )rI   r  r+   r+   r,   r    s   
rm   rl   rR  rS  rY   r   r9   Nrr  )rI   r   r9   r~  )rI   r   r  r~  r9   N)rp   rq   rr   rs   r^  bytesrY  r   rx   rl  rX   ru   r_   staticmethodr}  rU  r  setterr+   r+   r+   r,   rV    sP    




rV  c                   @   sP   e Zd ZU erded< dddZdd	d
ZdddeddddddddfddZdS )r   Union[PoolManager, ProxyManager]r   rI   r   r9   r   c                 C   s  | j di d}|d u rdnt|dtj| jdd}d }| j d d ur+| j d }| j d rQ|d u r6g }d	d
 |D }tD ]}|d |d f|vrP|| q?|d urY||d< | j d pmtj	dpmtj	dpmt
 |d< | j d pztj	d|d< | j d ptj	d|d< |S )Nr   transport_num_poolsr6   CERT_REQUIRED)total)	num_pools	cert_reqsr\   r  
keep_alivec                 S   r  r  r+   r  r+   r+   r,   r!    r"  z2HttpTransport._get_pool_options.<locals>.<setcomp>r   r/   r#  r$  r%  r&  r'  r(  r)  )rJ   rN   rw   r   TimeoutrD  r+  r   r/  r0  r1  r2  )rI   r  rJ   r  r4  r5  r+   r+   r,   rF    s@   





zHttpTransport._get_pool_optionsc           	      C   s,  | j d u r	tdd }| | j }| jd }| j jdkr+|dkr+|p*| o*t d}| jd }|sA|dkrA|p@| o@t d}|  }|r| jd }|rR||d< |drd	}zd
dl	m
} W n tyr   d}td| Y nw |r}||fi |S tjdi |S tj|fi |S tjdi |S )N4Cannot create HTTP-based transport without valid DSNr7  r8  r9  r:  r;  proxy_headerssocksTr   )SOCKSProxyManagerFzYou have configured a SOCKS proxy (%s) but support for SOCKS proxies is not installed. Disabling proxy support. Please add `PySocks` (or `urllib3` with the `[socks]` extra) to your dependencies.r+   )rH   r   r<  rJ   r=  r   rN   rF  
startswithurllib3.contrib.socksr  ImportErrorr   r   r   r"   r#   )	rI   r?  r>  r7  r:  optsr  use_socks_proxyr  r+   r+   r,   r     s>   




zHttpTransport._make_poolrK  rL  r	   r	  r   rE   rM  zurllib3.BaseHTTPResponsec                 C   s   | j j|| j|||dS )N)r	  rE   )r   requestr   get_api_urlrN  r+   r+   r,   rO  ;  s   
zHttpTransport._requestNrT  )rI   r   r9   r  )	rp   rq   rr   r   rt   rF  r   rv   rO  r+   r+   r+   r,   r    s$   
 

)-r  c                       s  e Zd Zd8 fddZd9d
dZdddddeddfddZd:ddZ	d;dddeddddddddfddZ	dddedddddddd fd!d"Z
d<ddd$eddfd%d&Zd:d'd(Zd:d)d*Z	d;ddd+ed,d-dd.fd/d0Zd=d1d2Z				3d>d4d5Zd?d6d7Z  ZS )@AsyncHttpTransportrI   r   rJ   r   r9   Nc                    s&   t stdt | t | _d S )Nz_AsyncHttpTransport requires httpcore[asyncio]. Install it with: pip install sentry-sdk[asyncio])ASYNC_TRANSPORT_AVAILABLERuntimeErrorsuperrP   asyncioget_running_looplooprO   	__class__r+   r,   rP   K  s   zAsyncHttpTransport.__init__r   c                 C   rd  re  )r   rO   r+   r+   r,   r   U  rh  z!AsyncHttpTransport._create_workerr7   r   r8   r:   c                 C   
   t ||S rl   rF   r   r+   r+   r,   r   X     
z$AsyncHttpTransport._get_header_valuerY   r   c                    s@   |  |}|d ur|\}}}| j| |tj|dI d H  d S rW  rX  r\  r+   r+   r,   r^  ]  s   

z!AsyncHttpTransport._send_enveloper	  rE   r   rL  r	   r   c                    sz   |  | z| d|||I d H }W n ty"   | j|dd  w z| j||d W | I d H  d S | I d H  w r_  )r   rO  ra  r   r   acloserc  r+   r+   r,   rY  i  s    
"z AsyncHttpTransport._send_requestrK  rM  httpcore.Responsec                    s(   | j j|| j|||| jdI d H S N)r   rE   
extensionsr   r  r   r  rE  rN  r+   r+   r,   rO    s   
zAsyncHttpTransport._requestFr   c                    s2   | j |dd}|d ur| t|gd d S d S ri  rj  rk  r+   r+   r,   rl    s
   z(AsyncHttpTransport._flush_client_reportsc                    rm  )Nr9   c                      sL   t    I d H   I d H  W d    d S 1 sw   Y  d S rl   rn  r+   r   r+   r,   ro    s
   "zCAsyncHttpTransport._capture_envelope.<locals>.send_envelope_wrapperrp  rq  r   rr  rs  ru  r+   r   r,   _capture_envelope  s   

z$AsyncHttpTransport._capture_envelopec                 C   sV   | j r| j  r| j | j| d S td | d |jD ]	}| jd|d qd S )Nz0Async Transport is not running in an event loop.internal_sdk_errorr   )	r  
is_runningcall_soon_threadsafer  r   r   r   r   ri   )rI   rY   rg   r+   r+   r,   rX     s   


z#AsyncHttpTransport.capture_enveloper\   r]   rv  Optional[asyncio.Task[None]]c                    s8   t d |dkr j fdd  j||S d S )Nrw  r   c                      rx  ry  rz  r+   r`   r+   r,   r-     r{  z*AsyncHttpTransport.flush.<locals>.<lambda>r|  r^   r+   r`   r,   r_     s
   
zAsyncHttpTransport.flushc                 C   s"   | j to| jd uo| jjdkdS Nr8  )r  )r6  HTTP2_ENABLEDrH   r=  r`   r+   r+   r,   rF    s   
z$AsyncHttpTransport._get_pool_optionsVUnion[httpcore.AsyncSOCKSProxy, httpcore.AsyncHTTPProxy, httpcore.AsyncConnectionPool]c                 C   s   | j d u r	td|  }|  }|r\| jd }|r||d< |drRz| }d|v r8|d}|r8t	d t
jdd|i|W S  tyQ   t	d| Y nw t
jdd|i|S t
jdi |S 	Nr  r  r  r  zqYou have defined socket_options but using a SOCKS proxy which doesn't support these. We'll ignore socket_options.	proxy_urlzoYou have configured a SOCKS proxy (%s) but support for SOCKS proxies is not installed. Disabling proxy support.r+   )rH   r   r@  rF  rJ   r  copypopr   r   httpcoreAsyncSOCKSProxyr  AsyncHTTPProxyAsyncConnectionPool)rI   r?  r  r  
socks_optsr  r+   r+   r,   r     s4   



zAsyncHttpTransport._make_poolc                 C   st   t d | j  z t  | j| j W  d    W S 1 s#w   Y  W d S  t	y9   t 
d Y d S w )NrP  z&Event loop not running, aborting kill.)r   r  r   ra   r   r  create_taskr   r  r  r   r`   r+   r+   r,   ra     s   

(
zAsyncHttpTransport.killrQ  rR  rm   rl   rS  rT  )rI   r   r9   r  )rI   r   r9   r  )rp   rq   rr   rP   r   rv   r   r^  r  rY  rO  rx   rl  r  rX   ru   r_   rF  r   ra   __classcell__r+   r+   r  r,   r  J  sx    










"r  c                       s   e Zd Zd	 fddZ  ZS )
Http2TransportrI   r   rJ   r   r9   Nc                    s   t  | td d S )NzhYou tried to use HTTP2Transport but don't have httpcore[http2] installed. Falling back to HTTPTransport.)r  rP   r   r   rO   r  r+   r,   rP     s   zHttp2Transport.__init__rQ  )rp   rq   rr   rP   r  r+   r+   r  r,   r    s    r  c                   @   sz   e Zd ZU dZdZerded< ddddd	ed
dfddZdddeddddddd
dfddZ	dddZ
			
	dddZdS ) r  z&The HTTP2 transport based on httpcore.   zeUnion[
                httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool
            ]r   rI   r   r7   r  r8   r9   r:   c                 C   r  rl   r  r   r+   r+   r,   r      r  z Http2Transport._get_header_valuerK  rL  r	   r	  r   rE   rM  c                 C   s$   | j j|| j|||| jd}|S r  r  )rI   rK  rL  r	  rE   r7   r+   r+   r,   rO    s   
zHttp2Transport._requestr   c                 C   s   | j | jd uo| jjdkdS r  )r6  rH   r=  r`   r+   r+   r,   rF    s   z Http2Transport._get_pool_optionsGUnion[httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]c                 C   s   | j d u r	td|  }|  }|rX| jd }|r||d< |drNzd|v r4|d}|r4td t	j
dd|i|W S  tyM   td| Y nw t	jdd|i|S t	jdi |S r  )rH   r   r@  rF  rJ   r  r  r   r   r  
SOCKSProxyr  	HTTPProxyConnectionPool)rI   r?  r  r  r  r+   r+   r,   r     s2   



zHttp2Transport._make_poolNrT  )rI   r   r9   r  )rp   rq   rr   rs   rD  r   rt   rv   r   rO  rF  r   r+   r+   r+   r,   r    sB   
 


c                   @   s>   e Zd ZdZ				dddZ					dd
dZdddZdS )_FunctionTransportz
    DEPRECATED: Users wishing to provide a custom transport should subclass
    the Transport class, rather than providing a function.
    funcCallable[[Event], None]r9   Nc                 C   s   t |  || _d S rl   )rG   rP   _func)rI   r  r+   r+   r,   rP   B  s   

z_FunctionTransport.__init__rQ   r$   c                 C   s   |  | d S rl   )r  )rI   rQ   r+   r+   r,   rZ   I  s   
z _FunctionTransport.capture_eventrY   r   c                 C   s"   |  }|d ur| | d S d S rl   )	get_eventrZ   )rI   rY   rQ   r+   r+   r,   rX   P  s   z#_FunctionTransport.capture_envelope)r  r  r9   N)rQ   r$   r9   Nr  )rp   rq   rr   rs   rP   rZ   rX   r+   r+   r+   r,   r  <  s    

r  rJ   r   Optional[Transport]c                 C   s  | d }|  di  dd}|  di  dd}tdd |  dp"g D }|r*tnt}|rVtrVzt  |rA|r>td	 t	}ntd
 W n t
yU   td Y nw |r]td t|trd|S t|trqt|trq|}nt|rtjdtdd t|S | d r|| S d S )N	transportr   transport_http2Ftransport_asyncc                 s   s    | ]	}|j jd kV  qdS )AsyncioIntegrationN)r  rp   )r>   integrationr+   r+   r,   rC   ^  s
    

z!make_transport.<locals>.<genexpr>integrationsz\HTTP/2 transport is not supported with async transport. Ignoring transport_http2 experiment.znYou tried to use AsyncHttpTransport but the AsyncioIntegration is not enabled. Falling back to sync transport.z6No event loop running, falling back to sync transport.zoYou tried to use AsyncHttpTransport but don't have httpcore[asyncio] installed. Falling back to sync transport.zFunction transports are deprecated and will be removed in a future release.Please provide a Transport instance or subclass, instead.r6   rR   rL   )rN   r   r  r  r  r  r  r   r   r  r  
isinstancerG   r   
issubclasscallablerT   rU   rV   r  )rJ   ref_transportuse_http2_transportuse_async_transportasync_integrationtransport_clsr+   r+   r,   make_transportY  sT   

r  rl   )rJ   r   r9   r  )Qabcr   r   r  r  r/  r   r*   r,  r   rT   r   r   r   collectionsr   urllib.requestr   r   r  r  h2r  anyior  r   r1  r   r   r	   sentry_sdk.utilsr
   r   r   r   sentry_sdk.workerr   r   r   sentry_sdk.enveloper   r   r   typingr   r   r   r   r   r   r   r   r   r   r   r   r    r!   urllib3.poolmanagerr"   r#   sentry_sdk._typesr$   r%   r+  
SOL_SOCKETSOL_TCPoptionr   AttributeErrorrv   rF   rG   r   r   rV  r  r  r  r  r  r+   r+   r+   r,   <module>   s    $_
   4]i "	F