o
    ifR                     @   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/edux/Edux_v2/venv/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)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   	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 )InterpreterInterfacezS
        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   _input_error_printed)r   r)   r(   
mainThreadconnect_status_queuer   r   r   r   U   s   
zInterpreterInterface.__init__c                 C   s   t | j|}|  |jS N)r   r   r   r   )r   codeFragmentcommandr   r   r   do_add_exec]   s   z InterpreterInterface.do_add_execc                 C   s   | j S r.   )r*   r   r   r   r   get_namespaceb   s   z"InterpreterInterface.get_namespacec                 C   s<   zddl m} || jd }||W S    t  g  Y S )Nr   )	Completer)_pydev_bundle._pydev_completerr4   r*   completer   	exception)r   r   act_tokr4   	completerr   r   r   getCompletionse   s   z#InterpreterInterface.getCompletionsc                 C   s   t d d S )Nr   )sysexitr2   r   r   r   closeo   s   zInterpreterInterface.closec                 C      dS )NzPyDev console: starting.
r   r2   r   r   r   get_greeting_msgr      z%InterpreterInterface.get_greeting_msgr.   )
r   r    r!   __doc__r   r1   r3   r:   r=   r?   r   r   r   r   r'   P   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   rB   v   s    rB   c                 C   s
   | t _d S r.   )rB   rC   )
debug_hookr   r   r   set_debug_hook{   s   
rF   c                 C   s:   | j rt| j D ]}|tjv r| j |}|  qd S d S r.   )mpl_modules_for_patchinglistr;   modulespop)r   moduleactivate_functionr   r   r    activate_mpl_if_already_imported   s   
rM   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 )z A function that the inputhooks can call (via inputhook.stdin_ready()) to find
            out if they should cede control and return TF)rB   rC   rD   
exec_queueemptyr   r   r   r   return_control   s   

z4init_set_return_control_back.<locals>.return_control)pydev_ipython.inputhookrN   )r   rN   rR   r   rQ   r   init_set_return_control_back   s   rT   c                 C   sL   t |  tsd S t|  ddlm} t| jD ]}||| j| qd S )Nr   )import_hook_manager)	rT   r   rM   _pydev_bundle.pydev_import_hookrU   rH   rG   add_module_namerJ   )r   rU   modr   r   r   init_mpl_in_console   s   rY   win32killc                 C   r>   )NTr   )pidr   r   r   
pid_exists   r@   r]   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osr[   OSErrorESRCHEPERM)r\   r^   errr   r   r   r]      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)ctypeswindllkernel32OpenProcessGetLastErrorc_intpointerGetExitCodeProcessCloseHandleboolcontentsvalueint)r\   re   rg   PROCESS_QUERY_INFORMATION!PROCESS_QUERY_LIMITED_INFORMATIONERROR_INVALID_PARAMETERSTILL_ACTIVEprocessrc   zero	exit_codeexit_code_suceededr   r   r   r]      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_inputhookPYDEV_ECLIPSE_PIDz-1   Tg?)blocktimeoutz'Error processing queue on pydevconsole.)rY   rS   rz   rq   r_   environgetr]   r<   rB   rC   r   r7   rO   r   Emptycallableadd_execKeyboardInterruptbuffer
SystemExit)r   rz   kill_if_pid_not_alive	inputhookr   r   r   r   r   process_exec_queue   sJ   



r   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   Nr}   )java.lang.SystemlangSystemr<   ImportErrorlenr_   _exit)argsjavar   r   r   do_exitM  s   r   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)logRequests
allow_nonezEError starting server with host: "%s", port: "%s", client_port: "%s"
r}      )%_pydev_bundle.pydev_importsr   r;   stderrwriter(   flushr%   r3   register_functionexecLineexecMultipleLinesr:   getFramegetVariablechangeVariablegetDescriptionr=   	interrupt	handshakeconnectToDebuggerhellogetArrayevaluateShowConsoleloadFullValue	enableGuisocketgetsocknameprintserve_foreverexc_infor   r   r7   get_connect_status_queueput)	r)   portr   XMLRPCServerserverheretryconnection_queuer   r   r   start_console_servera  sh   


r   c                 C   s2   t t_t| |t }tt| ||f t| d S r.   )	r   r;   r<   r'   r   current_threadstart_new_threadr   r   )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_interpreterget_ipython_hidden_vars_dictrQ   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   r;   r   r   r?   r   )interpreterInterfacer   r   r   r     s   r   c                 C   s    t  }|j|| || |S r.   )r   r   updater:   )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_morer   )coder   r   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   r}   #Traceback (most recent call last):
)skipr;   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.r   N)r;   r   	last_type
last_valuelast_tracebackSyntaxErrorr   
ValueError	tracebackformat_exception_onlyr   r   join)r   filenametyperp   tbmsgdummy_filenamelinenooffsetlinerH   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.Nr}   r   r   r   )r;   r   r   r   r   r   
extract_tbformat_listinsertextendr   r   r   r   )r   r   kwargsr   rp   r   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 )z<returns 'False' in case expression is partially correct
    z@LINE@r}   
FNT)
find_framecountstrreplacer   	f_globalsf_localsr   r   r   r	   save_localsr   compile_commandOverflowErrorr   r   r   r
   r   r   )
	thread_idframe_id
expressiondbgframeis_multilineupdated_globalsr   r   r   r   r   r   console_exec  s@   


r  __main__r}   )pydev_localhost)HrA   "_pydev_bundle._pydev_saved_modulesr   r   _pydevd_bundle.pydevd_constantsr   r    _pydevd_bundle.pydevconsole_coder   r   r   r_   r;   r   r   r   _pydev_bundler   _pydevd_bundler	   r   r
   r   builtinsr   !_pydev_bundle.pydev_console_utilsr   r   r   r   r#   _pydev_bundle.pydev_umdr$   r%   version_infor'   rB   rF   rM   rT   rY   platformr   r]   r   r   r   r   r   #_pydev_bundle.pydev_ipython_consoledelattrr   r   r   r   r   r   r   r   r  r   pydevconsolestdinargvr   r(   r  rq   get_socket_namer   pget_localhostr   r   r   r   <module>   s    
&



!+
/
F7
5