o
    [Zhmz                     @  s   d dl m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
mZmZmZ d dlmZmZmZmZmZ G dd dejZdd	 Zd
d ZdS )    )annotationsN)adaptercommonlauncher)jsonlog	messagingsockets)clients
components	launchersserverssessionsc                      s  e Zd ZU dZejjZded< 	 G dd dejZG dd dejZ	 fdd	Z
d
d Zdd Zedd Zedd Zedd Zdd Zedd Zedd Zedd Zedd Zedd Zed d! Zed"d# Zed$d% Zed&d' Z fd(d)Zd*d+ Zd,d- Z  ZS ).Clientz+Handles the client side of a debug session.zset[servers.Connection]known_subprocessesc                   @  s   e Zd ZdddddddZdS )zClient.CapabilitiesF)ZsupportsVariableTypeZsupportsVariablePagingZsupportsRunInTerminalRequestZsupportsMemoryReferences#supportsArgsCanBeInterpretedByShellsupportsStartDebuggingRequestN)__name__
__module____qualname__
PROPERTIES r   r   N/var/www/html/lang_env/lib/python3.10/site-packages/debugpy/adapter/clients.pyCapabilities   s    
r   c                   @  s$   e Zd ZdddejddddZdS )zClient.Expectationszen-USTpathoptional)localeZlinesStartAt1ZcolumnsStartAt1Z
pathFormatN)r   r   r   r   enumr   r   r   r   r   Expectations$   s    
r   c                   s:  |dkr1t d|  d| _tj }ttjd t	_
}t|j ttjd t	_}t|j n	d| _tj|}t 5}t || d | _	 d| _	 d | _	 d| _	 d | _	 g | _	 d| _t | _| |_|  W d    n1 svw   Y  | jddd	d
t j!id | jdddd
t j!id t"  d S )NZstdioz"Connecting to client over stdio...TrwFoutputZ	telemetryZptvsdZpackageVersion)categoryr"   datadebugpy)#r   infousing_stdior   ZJsonIOStreamZ
from_stdioopenosdevnullsysstdinatexitregisterclosestdoutZfrom_socketr   Sessionsuper__init__	client_idhas_startedstart_requestrestart_requested_initialize_request_deferred_events_forward_terminate_requestsetr   clientchannel
send_eventr%   __version__report_sockets)selfsockstreamr,   r0   session	__class__r   r   r3   ,   sX   


&zClient.__init__c                 C  s6   | j d ur| j | td d S | jj| d S )NzPropagation deferred.)r9   appendr   debugr<   r=   	propagaterA   eventr   r   r   propagate_after_starts   s   
zClient.propagate_after_startc                 C  sP   t d| j | jD ]}t d|  | jj| q
t d| j d | _d S )Nz%Propagating deferred events to {0}...zPropagating deferred {0}z&All deferred events propagated to {0}.)r   rH   r<   r9   Zdescriber=   rI   r&   rJ   r   r   r   _propagate_deferred_events~   s   

z!Client._propagate_deferred_eventsc                 C  s   | j r| j j| d S d S N)serverr=   rI   rJ   r   r   r   rK      s   zClient.eventc                 C  s   | j j|S rN   )rO   r=   delegaterA   requestr   r   r   rR      s   zClient.requestc                 C  s   | j d ur
|d|dd| _| | || _| | || _|| _ dddddd	d
ddddddddg}i ddddddddddddddddddddddddddddddddd dd|dd!S )"NzSession is already initializedZclientID raisedzRaised ExceptionsFz'Break whenever any exception is raised.)filterlabeldefaultdescriptionZuncaughtzUncaught ExceptionsTz=Break when the process is exiting due to unhandled exception.ZuserUnhandledzUser Uncaught Exceptionsz/Break when exception escapes into library code.ZsupportsCompletionsRequestZsupportsConditionalBreakpointsZ supportsConfigurationDoneRequestZsupportsDebuggerPropertiesZ supportsDelayedStackTraceLoadingZsupportsEvaluateForHoversZsupportsExceptionInfoRequestZsupportsExceptionOptionsZsupportsFunctionBreakpointsZ!supportsHitConditionalBreakpointsZsupportsLogPointsZsupportsModulesRequestZsupportsSetExpressionZsupportsSetVariableZsupportsValueFormattingOptionsZsupportsTerminateRequestZsupportsGotoTargetsRequest)ZsupportsClipboardContextZexceptionBreakpointFiltersZsupportsStepInTargetsRequest)r8   
isnt_validr4   r   capabilitiesr   Zexpectations)rA   rR   Zexception_breakpoint_filtersr   r   r   initialize_request   sz   

	
zClient.initialize_requestc                   s   t jj fdd}|S )Nc                   s  | ddsJ | jd u r|d| js| jr|d|dtd| j_| jjr/t	
  t|dtt | j_} | | |jd urId S | jr| j| j d | _|j}| jr|dd	k}d
|v rvt|}t|d
h |d< d}|drt|}|d= d}||d< z| jj|j| W n6 tjy   |i  | jd| jt|j Y d S  tjy } z|| W Y d }~nd }~ww | jjr|| _ d| _!|i  | "  d S | j#d || _ tj$S )NZlaunchattachzSession is not initialized yetzSession is already startedZnoDebugFdebugOptionsconsoleinternalConsoleZRedirectOutputTZredirectOutputZisOutputRedirected){0} disconnected before responding to {1}Zinitialized)%Z
is_requestr8   rY   r   rO   r   rW   rD   no_debugr   Zdont_wait_for_first_connectionr;   arraystrdebug_optionsresponseZ
initialize	argumentsgetdictlistr=   rR   commandr   NoMoreMessagesrespondfinalizeformatreprMessageHandlingErrorrI   r6   r5   rM   r>   NO_RESPONSE)rA   rR   rd   rf   Zredirectingexcfr   r   handle   sn   








z-Client._start_message_handler.<locals>.handle)r   	Componentmessage_handler)rt   ru   r   rs   r   _start_message_handler   s   LzClient._start_message_handlerc                   sH  ddl m} | jjdkstt rdtdt	
t  fdd}d}|v r8d	v r7d
nd	v r>d	}|t	j
tddd}t|sQtjg}|dt	j
tdd7 }|dd  jd< |jd< dtdd}|dkrz|d }d } }}	dv rdt}|g}
|jd< dv rdt}d|g}
|jd< dv rdt	j
tddd}	dd|	g}
djd< tdd |||	fD }|dkrӈd|dkr܈ddt	jd d!d"dd}d#t	d$}d%t	j
tdd&}|
|7 }
t|dkotjd% t}|r%| jd' sd(|d kr%d)d*tdd}|dkrA|dkr8d ntj|p@d }t|d+d,}|rVtjd-krVd.d/tdd}|re|d0k| _d1tjtj}d2d3}zt| W n ty } zd4| j|d }~ww || j|g|||
||||| d S )5Nr   )r      z"attach" expectedr]   c                   sh   | d   r|d  sJ | tdd}|dkrd }| v r2|du r0dt| t|d}|S )Nr   Tr   r   Fz9{0}:false and "debugOptions":[{1}] are mutually exclusive)islowerisupperboolrY   r   ro   )Z	prop_nameZ	flag_namevaluerd   rR   r   r   property_or_debug_option)  s   z7Client.launch_request.<locals>.property_or_debug_optionpythonZ
pythonPathz2"pythonPath" is not valid if "python" is specifiedT)r   )	vectorizesize
pythonArgs)r   ZdebugLauncherPythonr   r   programprocessNamemodulez-mcode)ry   z-c
c                 S  s   g | ]}|d kr|qS )r   r   ).0xr   r   r   
<listcomp>_  s    z)Client.launch_request.<locals>.<listcomp>z7either "program", "module", or "code" must be specifiedz6"program", "module", and "code" are mutually exclusiver^   r_   ZintegratedTerminalZexternalTerminalZconsoleTitlezPython Debug Consoleargs)r   r   z8Shell expansion in "args" is not supported by the clientzJShell expansion in "args" is not available for "console":"internalConsole"cwdsudoZSudowin32z("sudo":true is not supported on Windows.onTerminateKeyboardInterruptZdebugLauncherPathZdebugAdapterHost	127.0.0.1z4{0} couldn't create listener socket for servers: {1}) debugpy.adapterr   rD   idlenr   connectionscant_handler;   r   rb   rc   rY   r+   
executablerf   joinr   rW   
isinstancerZ   r)   r   dirnamer|   platformr:   r   __file__serve	ExceptionZspawn_debuggee)rA   rR   r   r   Z
python_keyr   Zlauncher_pythonr   r   r   r   Znum_targetsr^   Zconsole_titleZtarget_argsZshell_expand_argsr   r   on_terminateZlauncher_pathZadapter_hostrr   r   r~   r   launch_request  s   






	


 


zClient.launch_requestc              
     s&  j jr	|d|dtdd}|dtdd}|dtdd}|dtdd}|dttfdd |d	tdd|d
tdd}|rC|dk_|dksK|dkr]|dkrT|d|dkr]|d|dkr||dkrj|d dkrs|ddkr||d dkrdkr|d|dkrt	 r|d|dd}|dt}d t
_|dd_t||\}}nt	 st  tj \}} dkr#t tszt  W n ty   |dw |dtt}fdd}z	t || W n# ty }	 zt  j dt|	f  W Y d }	~	d S d }	~	ww tj}
 fdd}ndkr7dd }|dkr4tjnd }
nfdd}d }
jd!||d" tj ||
}|d u rxdkrk|i  j d# d S ||
rtd$d%z	| j  W d S  t!y   |d&| Y d S w )'Nz'"noDebug" is not supported for "attach"hostTr   portlistenconnect	processIdsubProcessIdr   r   r   z1"listen" and "host"/"port" are mutually exclusivez2"connect" and "host"/"port" are mutually exclusivez-"listen" and "connect" are mutually exclusivez/"listen" and "processId" are mutually exclusivez2"listen" and "subProcessId" are mutually exclusivez5"processId" and "subProcessId" are mutually exclusivez7Multiple concurrent "listen" sessions are not supportedr   restartFz$"processId" must be parseable as intZdebugpyArgsc                   s    j d| |d d S )Nr"   r#   r"   )r=   r>   r   rA   r   r   	on_output
  s   z(Client.attach_request.<locals>.on_outputz&Error when trying to attach to PID:
%sc                   
   | j  kS rN   pidconnr   r   r   <lambda>     
 z'Client.attach_request.<locals>.<lambda>c                 S  s   dS )NTr   r   r   r   r   r      s    c                   r   rN   r   r   )sub_pidr   r   r   #  r   r   ZdebugpyWaitingForServerr   r   z+No known subprocess with "subProcessId":{0}z.Timed out waiting for debug server to connect.z3There is no debug server connected to this adapter.z{0} is already being debugged.)"rD   ra   rY   rc   intrh   r|   r:   r   
is_servingr   Zaccess_tokenr7   r   listenergetsocknamer   r   r   rb   Zinjectr   swallow_exceptionrm   r   ZPROCESS_SPAWN_TIMEOUTr=   r>   Zwait_for_connectionrl   rn   r   Zattach_to_session
ValueError)rA   rR   r   r   r   r   r   Zdebugpy_argsr   etimeoutpredr   r   )r   rA   r   r   attach_request  s   






	



	zClient.attach_requestc                 C  sj  | j d u s| jr|d z{zMd| _z	| jj|}W n9 tjyT   |i  | j i  | j	
d| jt|j Y W W | j jd u rR| j i  |   d S d S w || W n tjyv } z| j t| W Y d }~nd }~ww W | j jd u r| j i  |   n| j jd u r| j i  |   w w t D ]}|jd u r|j| j	jkr| | qd S )NzX"configurationDone" is only allowed during handling of a "launch" or an "attach" requestTr`   )r6   r5   r   rO   r=   rP   r   rk   rl   rD   rm   rn   r   ro   rj   re   rM   rp   rc   r   r   Zppidr   notify_of_subprocess)rA   rR   resultrr   r   r   r   r   configurationDone_requestB  sT   



z Client.configurationDone_requestc                   s*   | j j } fdd}|| tjS )Nc                   s     | j d S rN   )rl   body)re   rR   r   r   handle_responseo  s   z0Client.evaluate_request.<locals>.handle_response)rO   r=   rI   Zon_responser   rq   )rA   rR   Zpropagated_requestr   r   r   r   evaluate_requestk  s   
zClient.evaluate_requestc                 C  s   d|j d< | jj|S )N*threadId)rf   rO   r=   rP   rQ   r   r   r   pause_requestv  s   
zClient.pause_requestc                 C  s8   d|j d< z| jj|W S  tjy   ddi Y S w )Nr   r   ZallThreadsContinuedT)rf   rO   r=   rP   r   rk   rQ   r   r   r   continue_request{  s   
zClient.continue_requestc                 C  sJ   ddt jii}| jr#z	| jjd}W n
 ty   Y |S w || |S )Nr%   versionZpydevdSystemInfo)r%   r?   rO   r=   rR   r   update)rA   rR   r   Zpydevd_infor   r   r   debugpySystemInfo_request  s   
z Client.debugpySystemInfo_requestc                 C  s.   d| _ | jr| jj|S | jjddd i S )NFzclient requested "terminate"T)terminate_debuggee)r7   r:   rO   r=   rP   rD   rm   rQ   r   r   r   terminate_request  s
   zClient.terminate_requestc              	   C  s   d| _ |dtdd}|dkrd }| jd| |i  | jrDt  t	d|  t
 D ]}z|j  W q- tyC   t  Y q-w d S d S )NFZterminateDebuggeeTr   r   zclient requested "disconnect"zB{0} disconnected from stdio; closing remaining server connections.)r7   r|   rD   rm   rl   r'   r   stop_servingr   r&   r   r=   r/   r   r   )rA   rR   r   r   r   r   r   disconnect_request  s"   
zClient.disconnect_requestc                   s   t    d S rN   )r2   
disconnectr   rE   r   r   r     s   zClient.disconnectc                 C  s0   dd t jtjtjfD }| jdd|i d S )Nc                 S  s2   g | ]}|d ur|  \}}|||tjudqS )N)r   r   Zinternal)r   r
   r   )r   r   r   r   r   r   r   r     s    z)Client.report_sockets.<locals>.<listcomp>ZdebugpySocketsr	   )r
   r   r   r   r=   r>   )rA   r	   r   r   r   r@     s   
zClient.report_socketsc                 C  s  t d| | | jI | jd u s|| jv r	 W d    d S d| jjv r4t d| j 	 W d    d S t d| | t| jj}| j| | j	  W d    n1 sVw   Y  dD ]}|
|d  q]d|j|d< |j|d< d	D ]}|
|d  qu|
d
d }|
dd }d|vri |d< d
|d vr|d ur|nd|d d
< d|d vr|d u rt \}}||d d< | jd r| jdd|d d S d|d< | jd| d S )Nz{1} is a subprocess of {0}.r   zrNot reporting subprocess for {0}, because the parent process was attached to using "processId" rather than "port".zNotifying {0} about {1}.)r   r   ZpreLaunchTaskZpostDebugTaskrR   r   zSubprocess {0}namer   )r   r   r   r   r   r   r   r   ZstartDebuggingr\   )rR   configurationrR   ZdebugpyAttach)r   r&   rD   r6   r   rf   warningrh   addZnotify_changedpoprn   r   r   r   rZ   r=   rR   r>   )rA   r   r   keyr   r   _r   r   r   r     sP   

zClient.notify_of_subprocess)r   r   r   __doc__r   rv   rw   __annotations__r   r   r3   rL   rM   rK   rR   r[   rx   r   r   r   r   r   r   r   r   r   r   r@   r   __classcell__r   r   rE   r   r      sP   
 
G


9P
 
 
(






r   c                 C  s    t dt| |at  t S )Nr   )r	   r   r   r   r   r@   r   r   r   r   r   r     s   r   c                   C  sD   t d urzt   W n ty   tjdd Y nw d a t  d S )Nr   )level)r   r/   r   r   r   r   r@   r   r   r   r   r   
  s   r   )
__future__r   r-   r)   r+   r%   r   r   r   Zdebugpy.commonr   r   r   r	   r   r
   r   r   r   r   rv   r   r   r   r   r   r   r   <module>   s         w