
    tni"                        U d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZ d dlmZmZmZmZmZmZmZ d dlmZ er&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#  ej$                    dej%        dd         z  ej&        dZ'de(d<    G d de          Z)d%dZ*	 d&ddddde+de,dddd fd!Z-d%d"Z.d'd$Z/dS )(    N)HTTPConnection)OPSPANDATA)Integration)add_global_event_processor)EnvironHeadersshould_propagate_traceadd_http_request_source)SENSITIVE_DATA_SUBSTITUTEcapture_internal_exceptionsensure_integration_enabledis_sentry_urllogger	safe_repr	parse_url)TYPE_CHECKING)Any)Callable)Dict)Optional)List)EventHintz%s.%s.%s   )nameversionbuildzdict[str, object]_RUNTIME_CONTEXTc                   *    e Zd ZdZedd            ZdS )StdlibIntegrationstdlibreturnNc                  l    t                       t                       t          	 	 	 	 	 	 dd            } d S )	Neventr   hintr   r"   Optional[Event]c                     t          j                                        t                    9|                     di           }t          |t                    rd|vr
t          |d<   | S )Ncontextsruntime)
sentry_sdk
get_clientget_integrationr    
setdefault
isinstancedictr   )r$   r%   r(   s      [/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/integrations/stdlib.pyadd_python_runtime_contextz@StdlibIntegration.setup_once.<locals>.add_python_runtime_context5   sb     $&&667HIIU ++J;;h-- ;)82K2K*:HY'L    )r$   r   r%   r   r"   r&   )_install_httplib_install_subprocessr   )r1   s    r0   
setup_oncezStdlibIntegration.setup_once0   s[    	#		"(		 	 	 
$	#	 	 	r2   r"   N)__name__
__module____qualname__
identifierstaticmethodr5    r2   r0   r    r    -   s7        J   \  r2   r    r"   c                      t           j        t           j        dddt          dt          ddddddffd	} dfd
}| t           _        |t           _        d S )Nselfr   methodurlargsr   kwargsr"   c                 B   | j         }| j        }| j        }t          j                    }|                    t                    t          ||          r | ||g|R i |S |}	|	|	                    d          s|dk    rdpdd|||k    rd|z  pd|}	d }
t                      5  t          |	d	          }
d d d            n# 1 swxY w Y   t          j        t          j        |d
|
r|
j        nt          d          }|                    t"          j        |           |
e|                    d|
j                   |                    t"          j        |
j                   |                    t"          j        |
j                    | ||g|R i |}t/          ||	          rmt          j                                        |          D ]E\  }}t5          j        d                    |||	                     |                     ||           F|| _        |S )N)zhttp://zhttps://i  httpshttpz://z:%s F)sanitize zauto.http.stdlib.httplibopr   originr@   spanzJ[Tracing] Adding `{key}` header {value} to outgoing request to {real_url}.)keyvaluereal_url)hostportdefault_portr*   r+   r,   r    r   
startswithr   r   
start_spanr   HTTP_CLIENTr@   r   set_datar   HTTP_METHOD
HTTP_QUERYqueryHTTP_FRAGMENTfragmentr	   get_current_scopeiter_trace_propagation_headersr   debugformat	putheader_sentrysdk_span)r>   r?   r@   rA   rB   rQ   rR   rS   clientrP   
parsed_urlrM   rvrN   rO   real_putrequests                  r0   
putrequestz$_install_httplib.<locals>.putrequestE   s    yy(&((!!"344<DA
 A
< #?4FtFFFvFFF8#6#67N#O#O#/9699$5;;	H 
(** 	= 	="8e<<<J	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= $~vvRz~~9RRT-	
 
 
 	h*F333!MM%000MM(-z/?@@@MM(0*2EFFF_T63@@@@@@!&(33 	+ -//NN O  + +  `ggux h    
 sE****#	s   )CCCc                    t          | dd           }| | g|R i |S 	  | g|R i |}|                    t          |j                             |                    d|j                   |                                 t                      5  t          |           d d d            n# 1 swxY w Y   nN# |                                 t                      5  t          |           d d d            w # 1 swxY w Y   w xY w|S )Nrb   reason)	getattrset_http_statusintstatusrW   ri   finishr   r
   )r>   rA   rB   rM   re   real_getresponses        r0   getresponsez%_install_httplib.<locals>.getresponse   s   t.55<##D:4:::6:::		.!!$888888B  RY000MM(BI...KKMMM,.. . .'---. . . . . . . . . . . . . . . KKMMM,.. . .'---. . . . . . . . . . . . . . . . 	sB   AB: B..B25B2:#DC9-D9C==D C=D)r>   r   rA   r   rB   r   r"   r   )r   rg   rp   str)rg   rp   ro   rf   s     @@r0   r3   r3   A   s    $/O%188(+8258>C8OT8	8 8 8 8 8 8t     & !+N!,Nr2   rA   z	List[Any]rB   zDict[Any, Any]r   positionsetdefault_callbackzOptional[Callable[[Any], Any]]r   c                     ||v r||         }| ||          }||||<   nD|t          |           k     r| |         }| ||          }||| |<   n|o
 |d          }||||<   |S )a?  
    given (*args, **kwargs) of a function call, retrieve (and optionally set a
    default for) an argument by either name or position.

    This is useful for wrapping functions with complex type signatures and
    extracting a few arguments without needing to redefine that function's
    entire type signature.
    N)len)rA   rB   r   rr   rs   re   s         r0   _init_argumentrv      s      v~~D\*$$R((B>F4L	CII		(^*$$R((B>DN >%8%8%>%>>F4LIr2   c                     t           j        j        t          t                    	 	 	 	 	 	 	 	 d
fd            } | t           j        _        t           j        j        t          t                    	 	 	 	 	 	 	 	 dfd            }|t           j        _        t           j        j        t          t                    	 	 	 	 	 	 	 	 dfd	            }|t           j        _        d S )Nr>   subprocess.Popen[Any]ar   kwr"   c           	      l   t          |          }t          ||dd          pg }t          ||dd          }d }t          |t           t          f          rat	          |          dk     rNt                      5  d                    t          t          |                    }d d d            n# 1 swxY w Y   |t          |          }d }t          j        t          j        |d          5 }t          j                                        |	          D ]I\  }}	|t          ||d
dd           }|	|d|                                                    dd          z   <   J|r|                    d|            | g|R i |}
|                    d| j                   |
cd d d            S # 1 swxY w Y   d S )NrA   r   cwd	   d   rH   !auto.subprocess.stdlib.subprocessrI   rL   env
   c                 <    t          | | nt          j                  S N)r/   osenviron)xs    r0   <lambda>zH_install_subprocess.<locals>.sentry_patched_popen_init.<locals>.<lambda>   s    $AMqqrz"J"J r2   SUBPROCESS_-_zsubprocess.cwdsubprocess.pid)listrv   r.   tupleru   r   joinmaprq   r   r*   rU   r   
SUBPROCESSr]   r^   upperreplacerW   set_tagpid)r>   ry   rz   rA   r|   descriptionr   rM   kvre   old_popen_inits              r0   sentry_patched_popen_initz6_install_subprocess.<locals>.sentry_patched_popen_init   sb   
 GGaVQ//52QE1-- dT5M** 	7s4yy3,.. 7 7!hhs3~~667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 #D//K"}6
 
 
 	 "466UU V   E E1 ;(JJ C DEMAGGII$5$5c3$?$??@@ 5.444/q///B//BLL)484441	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s%   6)B++B/2B/*B2F))F-0F-c                     t          j        t          j        d          5 }|                    d| j                    | g|R i |cd d d            S # 1 swxY w Y   d S Nr   )rJ   rK   r   )r*   rU   r   SUBPROCESS_WAITr   r   )r>   ry   rz   rM   old_popen_waits       r0   sentry_patched_popen_waitz6_install_subprocess.<locals>.sentry_patched_popen_wait   s     "!6
 
 
 	2 LL)48444!>$1111b11	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2   'AAAc                     t          j        t          j        d          5 }|                    d| j                    | g|R i |cd d d            S # 1 swxY w Y   d S r   )r*   rU   r   SUBPROCESS_COMMUNICATEr   r   )r>   ry   rz   rM   old_popen_communicates       r0    sentry_patched_popen_communicatez=_install_subprocess.<locals>.sentry_patched_popen_communicate  s     "(6
 
 
 	9 LL)48444((8888R88	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9r   )r>   rx   ry   r   rz   r   r"   N)r>   rx   ry   r   rz   r   r"   r   )
subprocessPopen__init__r   r    waitcommunicate)r   r   r   r   r   r   s      @@@r0   r4   r4      sV   %.N 1>BB3%3+038=3	3 3 3 3 3 CB3j !:J%*N 1>BB2%2+028=2	2 2 2 2 2 CB2 6J&,8 13HII9%9+098=9	9 9 9 9 9 JI9 $DJ   r2   r   c                  8    t          t          j        d          S )Nr   )prefix)r   r   r   r<   r2   r0   "get_subprocess_traceparent_headersr     s    "*];;;;r2   r6   r   )r"   r   )0r   r   sysplatformhttp.clientr   r*   sentry_sdk.constsr   r   sentry_sdk.integrationsr   sentry_sdk.scoper   sentry_sdk.tracing_utilsr   r	   r
   sentry_sdk.utilsr   r   r   r   r   r   r   typingr   r   r   r   r   r   sentry_sdk._typesr   r   python_implementationversion_infor   r   __annotations__r    r3   rq   rl   rv   r4   r   r<   r2   r0   <module>r      s   					     



  & & & & & &     * * * * * * * * / / / / / / 7 7 7 7 7 7         
                  !           .-------- +H*,,S-bqb12[) ) %          (R- R- R- R-t =A! !
!! ! 	!
 :! ! ! ! !HWD WD WD WDt< < < < < <r2   