o
    [ZhR                     @   s  d Z ddlmZmZ ddlmZ ejZddlmZ ej	Z	ej
Z
ddlZddlZddlmZ ddlmZ ddlZddlmZ dd	lmZ dd
lmZmZ ddlZddlmZmZ ddlmZ G dd dZzddlmZ ee_W n   Y ddlm Z m!Z! ej"d dkre e_ ne e_ G dd deZ#G dd dZ$dd Z%dd Z&dd Z'dd Z(ej)dkre*edsd d! Z+n	d"d! Z+nd#d! Z+d$d% Z,d&ej-v rej-d& d'kZ.nd(Z.z0zej/Z/W n e0y   dZ/Y nw e.rdd)l1m#Z# e/dure/e_/nze2ed* W n   Y W n   d(Z.Y d+d, Z3d-d. Z4d/d0 Z5d1d2 Z6d3d4 Z7d5d6 Z8d7d8 Z9G d9d: d:e
Z:d;d< Z;e<d=krwddl=Z=e=ej>e_>ej?d>d \Z@ZAdd?lmBZB eCe@dkrheCeAdkrheBD \ZEZFeFZAe=5eBG eCe@eCeA dS dS )@z6
Entry point module to start the interactive console.
    )thread_code)	IS_JYTHON)InteractiveConsoleN)	threading)INTERACTIVE_MODE_AVAILABLE)	pydev_log)pydevd_save_locals)Exec_queue)BaseInterpreterInterface	BaseStdIn)CodeFragmentc                   @   s,   e Zd Zdd Zdd ZeeZdd ZdS )Commandc                 C   s   || _ || _d| _dS )za
        :type code_fragment: CodeFragment
        :type interpreter: InteractiveConsole
        N)interpretercode_fragmentmore)selfr   r    r   \/var/www/html/lang_env/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevconsole.py__init__"   s   
zCommand.__init__c                 C   s"   | j rd}|S trd}|S d}|S )Nsingleexec)Zis_single_liner   )r   symbolr   r   r   symbol_for_fragment+   s   zCommand.symbol_for_fragmentc                 C   s*   | j j}| | j }| j|d|| _d S )Nz<input>)r   textr   r   Z	runsourcer   )r   r   r   r   r   r   run7   s   zCommand.runN)__name__
__module____qualname__r   r   staticmethodr   r   r   r   r   r   !   s
    	
r   )execfile)runfile_set_globals_function   c                   @   sB   e Zd ZdZdddZdd Zdd Zd	d
 Zdd Zdd Z	dS )InterpreterInterfacezO
    The methods in this class should be registered in the xml-rpc server.
    Nc                 C   s6   t | || || _|| _i | _t| j| _d| _d S )NF)r   r   client_porthost	namespacer   r   Z_input_error_printed)r   r'   r&   Z
mainThreadZconnect_status_queuer   r   r   r   V   s   
zInterpreterInterface.__init__c                 C   s   t | j|}|  |jS N)r   r   r   r   )r   ZcodeFragmentcommandr   r   r   do_add_exec^   s   z InterpreterInterface.do_add_execc                 C   s   | j S r)   )r(   r   r   r   r   get_namespacec   s   z"InterpreterInterface.get_namespacec                 C   s<   zddl m} || jd }||W S    t  g  Y S )Nr   )	Completer)Z_pydev_bundle._pydev_completerr.   r(   Zcompleter   	exception)r   r   Zact_tokr.   Z	completerr   r   r   getCompletionsf   s   z#InterpreterInterface.getCompletionsc                 C   s   t d d S )Nr   )sysexitr,   r   r   r   closep   s   zInterpreterInterface.closec                 C      dS )NzPyDev console: starting.
r   r,   r   r   r   get_greeting_msgs      z%InterpreterInterface.get_greeting_msgr)   )
r   r   r   __doc__r   r+   r-   r0   r3   r5   r   r   r   r   r%   Q   s    

r%   c                   @   s   e Zd ZdZdZdS )_ProcessExecQueueHelperNF)r   r   r   _debug_hook_return_control_oscr   r   r   r   r8   w   s    r8   c                 C   s
   | t _d S r)   )r8   r9   )Z
debug_hookr   r   r   set_debug_hook|   s   
r;   c                 C   s:   | j rt| j D ]}|tjv r| j |}|  qd S d S r)   )mpl_modules_for_patchinglistr1   modulespop)r   moduleZactivate_functionr   r   r    activate_mpl_if_already_imported   s   
rA   c                    s$   ddl m}  fdd}|| d S )Nr   )set_return_control_callbackc                      s,   t jrt j t _t jrdS  j sdS dS )zA function that the inputhooks can call (via inputhook.stdin_ready()) to find
        out if they should cede control and returnTF)r8   r9   r:   
exec_queueemptyr   r   r   r   return_control   s   

z4init_set_return_control_back.<locals>.return_control)pydev_ipython.inputhookrB   )r   rB   rF   r   rE   r   init_set_return_control_back   s   rH   c                 C   sL   t |  tsd S t|  ddlm} t| jD ]}||| j| qd S )Nr   )import_hook_manager)	rH   r   rA   Z_pydev_bundle.pydev_import_hookrI   r=   r<   Zadd_module_namer?   )r   rI   modr   r   r   init_mpl_in_console   s   rK   win32killc                 C   r4   )NTr   )pidr   r   r   
pid_exists   r6   rO   c              
   C   s   dd l }| dkr
dS z	t| d W dS  ty@ } z!|j |jkr(W Y d }~dS |j |jkr5W Y d }~dS W Y d }~dS d }~ww )Nr   TF)errnoosrM   OSErrorZESRCHEPERM)rN   rP   errr   r   r   rO      s   c              	   C   s   dd l }|jj}d}d}d}d}|||B d| }|s'| }||kr%dS dS z@|d}	||	}
|||
}|sBW || dS t	|
j
jrXt|
j
j|kr`W || dS W || dS W || dS || w )Nr   i   i   W   i  FT)ctypesZwindllkernel32ZOpenProcessZGetLastErrorc_intZpointerZGetExitCodeProcessZCloseHandleboolcontentsvalueint)rN   rV   rW   ZPROCESS_QUERY_INFORMATIONZ!PROCESS_QUERY_LIMITED_INFORMATIONZERROR_INVALID_PARAMETERZSTILL_ACTIVEprocessrT   zero	exit_codeZexit_code_suceededr   r   r   rO      s:   



c                 C   s  t |  ddlm} zttjdd}W n   d}Y 	 |dkr(t|s(t  | }t	j
r2t	
  |rBz|  W n   t  Y z%z
| jjddd	}W n tjyX   Y W qw t|ra|  n| |}W n tys   d | _Y q tyz       td
 t  Y q)Nr   )get_inputhookZPYDEV_ECLIPSE_PIDz-1   Tg?)blocktimeoutz'Error processing queue on pydevconsole.)rK   rG   r`   r\   rQ   environgetrO   r2   r8   r9   r   r/   rC   r   Emptycallableadd_execKeyboardInterruptbuffer
SystemExit)r   r`   Zkill_if_pid_not_aliveZ	inputhookr   r   r   r   r   process_exec_queue  sJ   



rm   ZIPYTHONENABLETrueF)r%   exitfuncc                  G   s\   zddl }|jjd W dS  ty-   t| dkr%t| d  Y dS td Y dS w )z
    We have to override the exit because calling sys.exit will only actually exit the main thread,
    and as we're in a Xml-rpc server, that won't work.
    r   Nrb   )Zjava.lang.SystemlangSystemr2   ImportErrorlenrQ   _exit)argsjavar   r   r   do_exitR  s   rw   c           	   	   C   s  z|dkrd} ddl m} z|| |fddd}W n   tjd| ||jf  tj   t|j |	|j
 |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |	|j |dkr|j \}}t| t|j 	 z|  W n   t d }d}z	|j d d	k}W n   Y |sт Y q   t!"  |# }|d ur|$d Y d S Y d S )
Nr    )SimpleXMLRPCServerFT)ZlogRequests
allow_nonezEError starting server with host: "%s", port: "%s", client_port: "%s"
rb      )%_pydev_bundle.pydev_importsry   r1   stderrwriter&   flushr#   r-   Zregister_functionZexecLineZexecMultipleLinesr0   ZgetFrameZgetVariableZchangeVariableZgetDescriptionr3   Z	interrupt	handshakeZconnectToDebuggerZhelloZgetArrayevaluateZShowConsoleZloadFullValueZ	enableGuisocketgetsocknameprintserve_foreverexc_inforu   r   r/   Zget_connect_status_queueput)	r'   portr   ZXMLRPCServerserverheretryZconnection_queuer   r   r   start_console_serverf  sl   


r   c                 C   s2   t t_t| |t }tt| ||f t| d S r)   )	rw   r1   r2   r%   r   current_threadstart_new_threadr   rm   )r'   r   r&   r   r   r   r   start_server  s   r   c                  C   s$   t rttdrt } |  S d S d S Nr   )IPYTHONhasattr__builtin__get_interpreterZget_ipython_hidden_vars_dictrE   r   r   r   get_ipython_hidden_vars  s   r   c                  C   sV   zt td} W | S  ty*   td d t } | t_tj	| 
  tj  Y | S w r   )getattrr   AttributeErrorr%   r   r   r   r1   r}   r~   r5   r   )interpreterInterfacer   r   r   r     s   r   c                 C   s    t  }|j|| || |S r)   )r   r   updater0   )r   tokenglobalslocalsr   r   r   r   get_completions  s   r   c                 C   s6   t  }|j|| || }|rdS || | dS )NTF)r   r   r   	need_moreri   )coder   r   Zdebuggerr   resr   r   r   	exec_code  s   
r   c                   @   s4   e Zd ZdZdddZdd ZdddZd	d
 ZdS )ConsoleWriterr   Nc                 C   s   t | | d S r)   )InteractiveInterpreterr   )r   r   r   r   r   r     s   zConsoleWriter.__init__c                 C   s:   | j dkr|  j d8  _ d S |dkrd| _ tj| d S )Nr   rb   #Traceback (most recent call last):
)skipr1   r}   r~   )r   datar   r   r   r~     s
   
zConsoleWriter.writec                 C   s   t  \}}}|t _|t _|t _|r7|tu r7z|j\}\}}}}	W n	 ty*   Y nw t|||||	f}|t _t	||}
t j
d|
 dS )z,Display the syntax error that just occurred.rx   N)r1   r   	last_type
last_valuelast_tracebackSyntaxErrorru   
ValueError	tracebackformat_exception_onlyr}   r~   join)r   filenametyper[   tbmsgZdummy_filenamelinenooffsetliner=   r   r   r   showsyntaxerror  s   zConsoleWriter.showsyntaxerrorc                 O   s   z6t  \}}}|t _|t _|t _t|}|dd= t|}|r(|dd |	t
|| W d }}nd }}w t jd| dS )z)Display the exception that just occurred.Nrb   r   r   rx   )r1   r   r   r   r   r   
extract_tbformat_listinsertextendr   r}   r~   r   )r   ru   kwargsr   r[   r   Ztblistlinesr   r   r   showtraceback  s   


zConsoleWriter.showtracebackr)   )r   r   r   r   r   r~   r   r   r   r   r   r   r     s    

	r   c           
   
   C   s   | | |}|ddk}t|dd}i }||j ||j tr8tt	|||j|}|s6t
| |S t }|s\zt|}	W n tttfyT   |  Y dS w |	du r[dS n|}	z	t|	||j W n tyo       |  Y dS t
| dS )z7returns 'False' in case expression is partially correctz@LINE@rb   
FNT)Z
find_framecountstrreplacer   	f_globalsf_localsr   r   r   r	   Zsave_localsr   compile_commandOverflowErrorr   r   r   r
   rl   r   )
	thread_idZframe_idZ
expressionZdbgframeZis_multilineZupdated_globalsr   r   r   r   r   r   console_exec  s@   


r   __main__rb   )pydev_localhost)Hr7   Z"_pydev_bundle._pydev_saved_modulesr   r   Z_pydevd_bundle.pydevd_constantsr   r   Z _pydevd_bundle.pydevconsole_coder   r   r   rQ   r1   r   r   r   Z_pydev_bundler   Z_pydevd_bundler	   r|   r
   r   builtinsr   Z!_pydev_bundle.pydev_console_utilsr   r   r   r   r!   Z_pydev_bundle.pydev_umdr"   r#   version_infor%   r8   r;   rA   rH   rK   platformr   rO   rm   re   r   ro   r   Z#_pydev_bundle.pydev_ipython_consoledelattrrw   r   r   r   r   r   r   r   r   r   Zpydevconsolestdinargvr   r&   r   r\   Zget_socket_namer   pZget_localhostr   r   r   r   <module>   s    
&



",
0
H7
4