
    lh"                     ~   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 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jF                         dejH                  dd z  ejJ                  dZ& G d de      Z'd Z(ddZ)d Z*d Z+y)    N)HTTPConnection)OPSPANDATA)Integration)add_global_event_processor)EnvironHeadersshould_propagate_trace)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buildc                        e Zd ZdZed        Zy)StdlibIntegrationstdlibc                  D    t                t                t        d        } y )Nc                     t        j                         j                  t              /| j	                  di       }t        |t              rd|vr	t        |d<   | S )Ncontextsruntime)
sentry_sdk
get_clientget_integrationr   
setdefault
isinstancedict_RUNTIME_CONTEXT)eventhintr"   s      p/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/stdlib.pyadd_python_runtime_contextz@StdlibIntegration.setup_once.<locals>.add_python_runtime_context2   sQ     $$&667HIU ++J;h-)82K*:HY'L    )_install_httplib_install_subprocessr   )r.   s    r-   
setup_oncezStdlibIntegration.setup_once,   s"     		#	 
$	r/   N)__name__
__module____qualname__
identifierstaticmethodr2    r/   r-   r   r   )   s    J r/   r   c                      t         j                  t         j                  fd} fd}| t         _        |t         _        y )Nc                 P   | j                   }| j                  }| j                  }t        j                         }|j                  t              t        ||      r | ||g|i |S |}	|	|	j                  d      s$|dk(  xr dxs dd|||k7  xr d|z  xs d|}	d }
t               5  t        |	d	      }
d d d        t        j                  t        j                  |d
|
r|
j                  nt        d      }|j!                  t"        j$                  |       |
p|j!                  d|
j                         |j!                  t"        j&                  |
j(                         |j!                  t"        j*                  |
j,                          | ||g|i |}t/        ||	      ret        j0                         j3                  |      D ]>  \  }}t5        j6                  dj9                  |||	             | j;                  ||       @ || _        |S # 1 sw Y   axY w)N)zhttp://zhttps://i  httpshttpz://z:%s F)sanitize zauto.http.stdlib.httplibopr   originurl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_CLIENTrC   r
   set_datar   HTTP_METHOD
HTTP_QUERYqueryHTTP_FRAGMENTfragmentr	   get_current_scopeiter_trace_propagation_headersr   debugformat	putheader_sentrysdk_span)selfmethodrC   argskwargsrI   rJ   rK   clientrH   
parsed_urlrE   rvrF   rG   real_putrequests                  r-   
putrequestz$_install_httplib.<locals>.putrequestB   s!   yyyy((&&(!!"34<DA
 #4FtFvFF8#6#67N#O#/969$5;;	H 
(* 	="8e<J	= $$~~z~~9RRT-	
 	h**F3!MM%0MM(--z/?/?@MM(00*2E2EFT63@@@!&(3 --/NN O +  `ggux h 
 sE*+  $	C	= 	=s   .HH%c                 "   t        | dd       }| | g|i |S 	  | g|i |}|j                  t        |j                               |j	                  d|j
                         |j                          |S # |j                          w xY w)NrZ   reason)getattrset_http_statusintstatusrO   re   finish)r[   r]   r^   rE   ra   real_getresponses        r-   getresponsez%_install_httplib.<locals>.getresponse{   s    t.5<#D:4:6::	!$888B  RYY0MM(BII.KKM	 KKMs   AA< <B)r   rc   rl   )rc   rl   rk   rb   s     @@r-   r0   r0   =   s7    $//O%117r" !+N!,Nr/   c                     ||v r||   }| ||      }||||<   |S |t        |       k  r| |   }| ||      }||| |<   |S |xr  |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)r]   r^   r   positionsetdefault_callbackra   s         r-   _init_argumentrq      s     v~D\*$R(B>F4L I 
CI	(^*$R(B>DN I	 !>%8%>>F4LIr/   c                     t         j                  j                  t        t              fd       } | t         j                  _        t         j                  j
                  t        t              fd       }|t         j                  _        t         j                  j                  t        t              fd       }|t         j                  _        y )Nc           	         t        |      }t        ||dd      xs g }t        ||dd      }d }t        |t         t        f      r@t	        |      dk  r2t               5  dj                  t        t        |            }d d d        |t        |      }d }t        j                  t        j                  |d      5 }t        j                         j                  |	      D ]=  \  }}	|t        ||d
dd       }|	|d|j!                         j#                  dd      z   <   ? |r|j%                  d|        | g|i |}
|j'                  d| j(                         |
cd d d        S # 1 sw Y   xY w# 1 sw Y   y xY w)Nr]   r   cwd	   d   r?   !auto.subprocess.stdlib.subprocessr@   rD   env
   c                 D    t        | |       S t        j                        S N)r)   osenviron)xs    r-   <lambda>zH_install_subprocess.<locals>.sentry_patched_popen_init.<locals>.<lambda>   s    $AMq"J rzz"J r/   SUBPROCESS_-_zsubprocess.cwdsubprocess.pid)listrq   r(   tuplern   r   joinmapstrr   r$   rM   r   
SUBPROCESSrU   rV   upperreplacerO   set_tagpid)r[   akwr]   rt   descriptionrx   rE   kvra   old_popen_inits              r-   sentry_patched_popen_initz6_install_subprocess.<locals>.sentry_patched_popen_init   s    GaVQ/52QE1- dT5M*s4y3,. 7!hhs3~67 #D/K""}}6
 	 "446UU V  E1 ;(JC DEMAGGI$5$5c3$??@E .4/q/B/BLL)48841	 	7 7	 	s    E&:B"E2&E/2E;c                     t        j                  t        j                  d      5 }|j	                  d| j
                          | g|i |cd d d        S # 1 sw Y   y xY wNrw   )rA   rB   r   )r$   rM   r   SUBPROCESS_WAITr   r   )r[   r   r   rE   old_popen_waits       r-   sentry_patched_popen_waitz6_install_subprocess.<locals>.sentry_patched_popen_wait   s^     ""!!6
 	2 LL)4884!$11b1	2 	2 	2   (AA"c                     t        j                  t        j                  d      5 }|j	                  d| j
                          | g|i |cd d d        S # 1 sw Y   y xY wr   )r$   rM   r   SUBPROCESS_COMMUNICATEr   r   )r[   r   r   rE   old_popen_communicates       r-    sentry_patched_popen_communicatez=_install_subprocess.<locals>.sentry_patched_popen_communicate   s^     ""((6
 	9 LL)4884(88R8	9 	9 	9r   )
subprocessPopen__init__r   r   waitcommunicate)r   r   r   r   r   r   s      @@@r-   r1   r1      s    %%..N 1>B2 C2h !:J%%**N 1>B2 C2 6J&,,88 13HI9 J9 $DJ r/   c                  8    t        t        j                  d      S )Nr   )prefix)r   r|   r}   r8   r/   r-   "get_subprocess_traceparent_headersr     s    "**];;r/   r{   ),r|   r   sysplatformhttp.clientr   r$   sentry_sdk.constsr   r   sentry_sdk.integrationsr   sentry_sdk.scoper   sentry_sdk.tracing_utilsr   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*   r   r0   rq   r1   r   r8   r/   r-   <module>r      s    	  
  &  * / 7 K   !- +H**,S--bq12[[  (P-f>UDp<r/   