U
    Kyh[                 	   @   s  d Z ddlZddlmZ ddlZddlmZ ejdd dk rFedddl	Z	ddl
Z
ddlZddlZddlmZ dd	lmZ dd
lmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z* ddl)m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl1m3Z3 ddl1m4Z4 ddl5m6Z6m7Z7 ddl8Z8ddl5m9Z9 ddl5m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\ ddl]m^Z^m_Z_ ddl`maZambZb ddlcmdZd ddlemfZgmhZhmiZimjZj ddlkmlZlmmZmmnZn ddlompZp ddlqmrZr ddlsmtZtmuZumvZvmwZw dd lxmyZymzZz dd!l{m|Z|m}Z}m~Z~ ddlZdd"lmZ dd#l{mZmZ ejZd$Zg ZeD ]Zeee qd%eZdfd&d'Ze  e ZdZer,dd(lmZ e2jZe2jZejZzd)d* W n   Y nX d+ad+ad+ad+Zd+ae. ZG d,d- d-eNZG d.d/ d/eNZG d0d1 d1eZG d2d3 d3eZG d4d5 d5eZG d6d7 d7eZd8d9 Zd:d; Zdgd<d=Zdhd>d?ZG d@dA dAeZdidBdCZdjdDdEZdkdHdIZe4 ZdJdK ZdLdM ZG dNdO dOeZG dPdQ dQePZdRdS ZdTdU ZdVdW ZG dXdY dYZdZd[ Zd\d] Zd^d_ Zdd`lmZ ddal5mZ eeD ]Zejedb qdcdd Zedekre  dS )lzF
Entry point module (keep at root):

This module starts the debugger.
    N)contextmanager)collect_return_info   r      zThe PyDev.Debugger requires Python 2.6 onwards to be run. If you need to use an older Python version, use an older version of the debugger.)partial)defaultdict)IS_JYTH_LESS25
IS_PYCHARMget_thread_idget_current_thread_id	dict_keysdict_iter_itemsDebugInfoHolderPYTHON_SUSPENDSTATE_SUSPEND	STATE_RUN	get_framexrangeclear_cached_thread_idINTERACTIVE_MODE_AVAILABLESHOW_DEBUG_INFO_ENVIS_PY34_OR_GREATERIS_PY36_OR_GREATERIS_PY2NULL	NO_FTRACEdummy_excepthook
IS_CPYTHONGOTO_HAS_RESPONSE)fix_getpass)pydev_imports	pydev_log)getfilesystemencoding)is_thread_alive)	threading)time)thread)	pydevd_iopydevd_vm_type)pydevd_utils)pydevd_vars)	overrides)ExceptionBreakpointset_fallback_excepthookdisable_excepthook)CMD_SET_BREAKCMD_SET_NEXT_STATEMENTCMD_STEP_INTOCMD_STEP_OVERCMD_STEP_RETURNCMD_STEP_INTO_MY_CODECMD_THREAD_SUSPENDCMD_RUN_TO_LINECMD_ADD_EXCEPTION_BREAKCMD_SMART_STEP_INTOInternalConsoleExecNetCommandFactoryPyDBDaemonThread_queueReaderThreadGetGlobalDebuggerget_global_debuggerset_global_debuggerWriterThread
pydevd_logstart_clientstart_serverInternalGetBreakpointExceptionInternalSendCurrExceptionTrace'InternalSendCurrExceptionTraceProceededCommunicationRolerun_as_pydevd_daemon_thread)CustomFramesContainercustom_frames_container_init)add_exception_to_frameremove_exception_from_frame)kill_all_pydev_threads)trace_dispatchglobal_cache_skipsglobal_cache_frame_skipsshow_tracing_warning)frame_eval_funcdummy_trace_dispatchshow_frame_eval_warning)set_additional_thread_info)save_main_module)ThreadingLoggerAsyncioLoggersend_messagecur_time)wrap_threadswrap_asyncio)get_fullnamerPathget_package_dir)
DONT_TRACE)*get_abs_path_real_path_and_base_from_frameNORM_PATHS_AND_BASE_CONTAINER)      r   .c                 C   s,   | d krddl m} |} tjdkr(| t_d S )Nr   )breakpointhook)      )Z$_pydevd_bundle.pydevd_breakpointhookrh   sysversion_info)Zpydevd_breakpointhookrh    rm   0/usr/local/lib/python3.8/dist-packages/pydevd.pyinstall_breakpointhookJ   s
    
	ro   )PluginManagerdummyutf-8Fc                   @   s&   e Zd Zdd Zeejdd ZdS )PyDBCommandThreadc                 C   s&   t |  |j| _|| _| d d S )Nzpydevd.CommandThread)r<   __init___py_db_command_thread_eventpy_dbsetNameselfrv   rm   rm   rn   rt   {   s    
zPyDBCommandThread.__init__c                 C   s   t d | jrd S zH| jsZz| j  W n   tdd Y nX | j  | jd qW n   t	
t d  Y nX d S )N333333?r   z#Finishing debug communication...(2))r&   sleepkillReceivedrv   process_internal_commandsrC   ru   clearwaitr"   debugrk   exc_infory   rm   rm   rn   _on_run   s    

zPyDBCommandThread._on_runN)__name__
__module____qualname__rt   r,   r<   r   rm   rm   rm   rn   rs   y   s   rs   c                   @   s8   e Zd Zdd Zeejdd ZdddZdd	 Zd
S )CheckOutputThreadc                 C   s$   t |  || _| d d| _d S )Nzpydevd.CheckAliveThreadF)r<   rt   rv   rw   daemonrx   rm   rm   rn   rt      s    

zCheckOutputThread.__init__c                 C   sx   | j sttd | j sh| jj rhztd | j	  t
  W n   t  Y nX |   d| _ | j  q d S )Nrz   z)No threads alive, finishing debug sessionT)r|   r&   r{   rv   has_threads_alivewriteremptyr"   r   finish_debugging_sessionrO   	traceback	print_excwait_pydb_threads_to_finishcheck_output_redirectr   rm   rm   rn   r      s    



zCheckOutputThread._on_run      ?c                    sv   t d  j}t }t || k rPt|dkrD| d rDd S td qt dd fdd|D   d S )Nz)Waiting for pydb daemon threads to finishre   {Gz?z9The following pydb threads may not finished correctly: %sz, c                    s   g | ]}| k	r|  qS rm   )getName.0tr   rm   rn   
<listcomp>   s      zACheckOutputThread.wait_pydb_threads_to_finish.<locals>.<listcomp>)r"   r   created_pydb_daemon_threadsr&   lengetr{   join)ry   timeoutZpydb_daemon_threadsZ
started_atrm   r   rn   r      s    
z-CheckOutputThread.wait_pydb_threads_to_finishc                 C   s
   d| _ d S NT)r|   r   rm   rm   rn   do_kill_pydev_thread   s    z&CheckOutputThread.do_kill_pydev_threadN)r   )	r   r   r   rt   r,   r<   r   r   r   rm   rm   rm   rn   r      s
   

r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TrackedLockzGThe lock that tracks if it has been acquired by the current thread
    c                 C   s    t  | _t | _d| j_d S NF)r'   allocate_lock_lockr%   local_tlsis_lock_acquiredr   rm   rm   rn   rt      s    

zTrackedLock.__init__c                 C   s   | j   d| j_d S r   )r   acquirer   r   r   rm   rm   rn   r      s    
zTrackedLock.acquirec                 C   s   | j   d| j_d S r   )r   releaser   r   r   rm   rm   rn   r      s    
zTrackedLock.releasec                 C   s   |    d S N)r   r   rm   rm   rn   	__enter__   s    zTrackedLock.__enter__c                 C   s   |    d S r   )r   )ry   exc_typeexc_valexc_tbrm   rm   rn   __exit__   s    zTrackedLock.__exit__c                 C   s   | j jS r   )r   r   r   rm   rm   rn   is_acquired_by_current_thread   s    z)TrackedLock.is_acquired_by_current_threadN)
r   r   r   __doc__rt   r   r   r   r   r   rm   rm   rm   rn   r      s   r   c                   @   sb   e Zd ZdZdddddddgZd	Zd
d Zdd Zdd Zdd Z	dd Z
dd Zedd ZdS )"AbstractSingleNotificationBehaviora  
    The basic usage should be:

    # Increment the request time for the suspend.
    single_notification_behavior.increment_suspend_time()

    # Notify that this is a pause request (when a pause, not a breakpoint).
    single_notification_behavior.on_pause()

    # Mark threads to be suspended.
    set_suspend(...)

    # On do_wait_suspend, use notify_thread_suspended:
    def do_wait_suspend(...):
        with single_notification_behavior.notify_thread_suspended(thread_id):
            ...
    _last_resume_notification_time_last_suspend_notification_timer   _next_request_time_suspend_time_request_suspended_thread_ids_pause_requestedr   c                 C   sB   t tt | _d| _d| _|  | _t	 | _
t | _d| _d S )NF)r   next	itertoolscountr   r   r   r   r'   r   r   setr   r   r   rm   rm   rn   rt      s    

z+AbstractSingleNotificationBehavior.__init__c                 C   s   t dd S Nz#abstract: subclasses must override.AssertionErrorry   	thread_idstop_reasonrm   rm   rn   send_suspend_notification  s    z<AbstractSingleNotificationBehavior.send_suspend_notificationc                 C   s   t dd S r   r   ry   r   rm   rm   rn   send_resume_notification	  s    z;AbstractSingleNotificationBehavior.send_resume_notificationc              	   C   s    | j  |  | _W 5 Q R X d S r   )r   r   r   r   rm   rm   rn   increment_suspend_time  s    z9AbstractSingleNotificationBehavior.increment_suspend_timec              	   C   s.   | j  d| _| j}W 5 Q R X t| j| d S r   )r   r   r   rJ   _notify_after_timeoutry   Zglobal_suspend_timerm   rm   rn   on_pause  s    z+AbstractSingleNotificationBehavior.on_pausec              	   C   sN   t | j | j2 | jr@|| jkr@|| _| tt| jt	 W 5 Q R X d S r   )
r&   r{   NOTIFY_OF_PAUSE_TIMEOUTr   r   r   r   r   iterr6   r   rm   rm   rn   r     s    
z8AbstractSingleNotificationBehavior._notify_after_timeoutc                 c   s   | j N | j}|rd| _| j| |tks0|rP| j| jkrP| j| _| || W 5 Q R X z
d V  W 5 | j 0 | j| | j	| jk r| j| _	| 
| W 5 Q R X X d S r   )r   r   r   addr6   r   r   r   remover   r   )ry   r   r   Zpause_requestedrm   rm   rn   notify_thread_suspended!  s     
z:AbstractSingleNotificationBehavior.notify_thread_suspendedN)r   r   r   r   	__slots__r   rt   r   r   r   r   r   r   r   rm   rm   rm   rn   r      s$   
		r   c                   @   s\   e Zd Zejddg Zdd Zeejdd Zeejdd Zeej	e
d	d
 Z	dS )"ThreadsSuspendedSingleNotification!multi_threads_single_notification_py_dbc                 C   s    t |  d| _t|| _d S r   )r   rt   r   weakrefrefr   rx   rm   rm   rn   rt   A  s    
z+ThreadsSuspendedSingleNotification.__init__c                 C   s(   |   }|d k	r$|j|j| d S r   )r   r   add_commandcmd_factoryZ&make_thread_resume_single_notification)ry   r   rv   rm   rm   rn   r   G  s    z;ThreadsSuspendedSingleNotification.send_resume_notificationc                 C   s*   |   }|d k	r&|j|j|| d S r   )r   r   r   r   Z'make_thread_suspend_single_notification)ry   r   r   rv   rm   rm   rn   r   M  s    z<ThreadsSuspendedSingleNotification.send_suspend_notificationc              	   c   s2   | j r(t| || d V  W 5 Q R X nd V  d S r   )r   r   r   r   rm   rm   rn   r   S  s    z:ThreadsSuspendedSingleNotification.notify_thread_suspendedN)r   r   r   r   r   rt   r,   r   r   r   r   rm   rm   rm   rn   r   <  s    

r   c                   @   s  e Zd ZdZdrddZdd Zdsd	d
Zdd ZdtddZduddZ	e
dd Zejdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zdvd:d;Z dwd<d=Z!d>d? Z"d@dA Z#dBdC Z$dxdDdEZ%dFdG Z&dydHdIZ'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dzdXdYZ/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5d{dfdgZ6dhdi Z7d|djdkZ8dldm Z9dndo Z:dpdq Z;e<Z=e>Z>e?Z?dS )}PyDBa8   Main debugging class
    Lots of stuff going on here:

    PyDB starts two threads on startup that connect to remote debugger (RDB)
    The threads continuously read & write commands to RDB.
    PyDB communicates with these threads through command queues.
       Every RDB command is processed by calling process_net_command.
       Every PyDB net command is sent to the net by posting NetCommand to WriterThread queue

       Some commands need to be executed on the right thread (suspend/resume & friends)
       These are placed on the internal command queue.
    Tc                 C   s  |rt |  t  d | _d | _d | _d | _d | _t | _	t
tj| _i | _d| _i | _i | _i | _i | _d| _t | _t | _t | _|r| jt_d| _d| _d | _ tj!| _!d| _"d| _#d| _$d| _%d| _&d| _'d| _(d| _)i | _*d| _+i | _,d | _-d| _.d| _/d | _0d | _1d| _2d| _3i | _4i | _5d| _6t78 | _8t79 | _9d| _:d| _;d| _<d| _=d| _>t?| | _@tA | _BtC | _Dd | _EtF| _Fd| _Gd S )Nr   FTrm   )HrA   pydevd_tracingZreplace_sys_set_trace_funcreaderr   output_checker_threadpy_db_command_threadZquittingr;   r   r   r=   Queue
_cmd_queuebreakpointsmtimeZfile_to_id_to_line_breakpointZfile_to_id_to_plugin_breakpointbreak_on_uncaught_exceptionsbreak_on_caught_exceptionsready_to_runr   
_main_lockr'   r   _lock_running_thread_idsr%   Eventru   rK   _finish_debugging_sessionZ_termination_event_setsignature_factorySetTraceZ)skip_on_exceptions_thrown_in_same_contextZ7ignore_exceptions_thrown_in_lines_with_ignore_exceptionZ$skip_suspend_on_breakpoint_exceptionZskip_print_breakpoint_exceptionZdisable_property_traceZdisable_property_getter_traceZdisable_property_setter_traceZdisable_property_deleter_trace_running_thread_idsZ_set_breakpoints_with_idZ.filename_to_lines_where_exceptions_are_ignoredpluginhas_plugin_line_breakshas_plugin_exception_breaksthread_analyserasyncio_analyser
mpl_in_usempl_hooks_in_debug_consolempl_modules_for_patchingZ_filename_to_not_in_scopeZfirst_breakpoint_reachedr*   Zis_filter_enabledZis_filter_librariesZshow_return_valuesZremove_return_values_flagredirect_outputZuse_frame_evalstop_on_startr   &_threads_suspended_single_notificationr   _local_thread_trace_funcdict#process_created_msg_received_eventscommunication_roler   stop_on_failed_tests)ry   Zset_as_globalrm   rm   rn   rt   o  sx    





zPyDB.__init__c                 C   s,   z| j j}W n tk
r&   | j}Y nX |S r   )r   thread_trace_funcAttributeErrorrP   )ry   r   rm   rm   rn   get_thread_local_trace_func  s
    z PyDB.get_thread_local_trace_funcNFc                 C   sv   t   | jdk	r<|   t| j tr8|r8t| j dS |dkrN|  }n|| j_	t| trr|rrt| dS )aT  
        Enables tracing.

        If in regular mode (tracing), will set the tracing function to the tracing
        function for this thread -- by default it's `PyDB.trace_dispatch`, but after
        `PyDB.enable_tracing` is called with a `thread_trace_func`, the given function will
        be the default for the given thread.
        N)
r.   rT   r   r   rU   r   Zset_trace_to_threadsr   r   r   )ry   r   apply_to_all_threadsrm   rm   rn   enable_tracing  s    	


zPyDB.enable_tracingc                 C   s   t d  d S r   )r   r   r   rm   rm   rn   disable_tracing  s    zPyDB.disable_tracingc                 C   s(   | j s
dS |  jd7  _|s$|   dS )zh
        When breakpoints change, we have to re-evaluate all the assumptions we've made so far.
        Nre   )r   r   !set_tracing_for_untraced_contexts)ry   Zremovedrm   rm   rn   on_breakpoints_changed  s
    zPyDB.on_breakpoints_changedc           
      C   s   d }|rt  }tdd t D }trVt }| D ]\}}||kr8| | q8nlt }zR|D ]H}|j	|ksb||krzqbt
|}	|	|}z|d k	r| | W 5 d }X qbW 5 d }d }d }d }	X d S )Nc                 s   s,   | ]$}t |d dst |ddr|jV  qdS )is_pydev_daemon_threadFpydev_do_not_traceN)getattridentr   rm   rm   rn   	<genexpr>  s    z9PyDB.set_tracing_for_untraced_contexts.<locals>.<genexpr>)r%   current_threadr   threadingEnumerater   rk   _current_framesitemsset_trace_for_frame_and_parentsr  rW   get_topmost_frame)
ry   ignore_current_threadZignore_threadZignore_thread_idsZtid_to_framer   framethreadsr   additional_inform   rm   rn   r     s4    
z&PyDB.set_tracing_for_untraced_contextsc                 C   s   | j jS r   r   r   r   rm   rm   rn   r   .  s    z&PyDB.multi_threads_single_notificationc                 C   s   || j _d S r   r  )ry   notifyrm   rm   rn   r   2  s    c                 C   s   | j d krtrt| | _ | j S r   )r   SUPPORT_PLUGINSrp   r   rm   rm   rn   get_plugin_lazy_init6  s    
zPyDB.get_plugin_lazy_initc                 C   s
   t |S r   )r*   Zin_project_rootsry   filenamerm   rm   rn   in_project_scope;  s    zPyDB.in_project_scopec                 C   s
   t |S r   )r*   Zis_ignored_by_filterr  rm   rm   rn   is_ignored_by_filters>  s    zPyDB.is_ignored_by_filtersc                 C   s
   t |S r   )r*   #is_exception_trace_in_project_scopery   tracerm   rm   rn   r  A  s    z(PyDB.is_exception_trace_in_project_scopec                 C   s
   t |S r   )r*   #is_top_level_trace_in_project_scoper  rm   rm   rn   r  D  s    z(PyDB.is_top_level_trace_in_project_scopec                 C   s
   t |S r   )r*   is_test_item_or_set_up_caller)ry   r  rm   rm   rn   r  G  s    z"PyDB.is_test_item_or_set_up_callerc                 C   s
   d| _ d S r   )r   r   rm   rm   rn   set_unit_tests_debugging_modeJ  s    z"PyDB.set_unit_tests_debugging_modec                 C   sF   t  D ]8}t|tr td t|r| r:t|dr dS qdS )NWError in debugger: Found PyDBDaemonThread not marked with is_pydev_daemon_thread=True.
Z__pydevd_main_threadTF)	r*   get_non_pydevd_threads
isinstancer<   r"   
error_oncer$   isDaemonhasattr)ry   r   rm   rm   rn   r   M  s    
zPyDB.has_threads_alivec                 C   s
   d| _ d S r   )r   r   rm   rm   rn   r   Y  s    zPyDB.finish_debugging_sessionc                 C   sR   z| d  W n   Y nX t|| _t|| _| j  | j  td d S )N皙?)
settimeoutrB   r   r>   r   startr&   r{   )ry   sockrm   rm   rn   initialize_network]  s    



zPyDB.initialize_networkc                 C   s6   |rt j| _t||}nt j| _t|}| | d S r   )rI   ZCLIENTr   rD   SERVERrE   r(  )ry   hostportsrm   rm   rn   connecti  s    zPyDB.connectc                 C   s*   | dr ||dd d }| j| S )zm returns internal command queue for a given thread.
        if new queue is created, notify the RDB about it Z	__frame__|re   N)
startswithrfindr   r   rm   rm   rn   get_internal_queuet  s    
zPyDB.get_internal_queuec                 C   s   |  |}|| dS )z) if thread_id is *, post to the '*' queueN)r1  put)ry   int_cmdr   queuerm   rm   rn   post_internal_command{  s    
zPyDB.post_internal_commandc                 C   s*   |a |a|p|| _t rt  tr&t  d S r   )bufferStdOutToServerbufferStdErrToServerr   init_stdout_redirectinit_stderr_redirect)ry   redirect_stdoutredirect_stderrrm   rm   rn   enable_output_redirection  s    
zPyDB.enable_output_redirectionc                 C   s   t r
t  trt  d S r   )r6  r8  r7  r9  r   rm   rm   rn   r     s    zPyDB.check_output_redirectc                 C   s4   ddl m} t| jD ]}||| j| qd S )Nr   )import_hook_manager)Z_pydev_bundle.pydev_import_hookr=  r   r   Zadd_module_namepop)ry   r=  modulerm   rm   rn    init_matplotlib_in_debug_console  s    z%PyDB.init_matplotlib_in_debug_consolec                    sb   ddl mm}m}m G dd d  fdd}ddlm} || fdd	||d
| _d S )Nr   )activate_matplotlibactivate_pylabactivate_pyplotdo_enable_guic                   @   s   e Zd ZdZdS )z7PyDB.init_matplotlib_support.<locals>._MatplotlibHelperFN)r   r   r   _return_control_oscrm   rm   rm   rn   _MatplotlibHelper  s   rF  c                      s    j   _  j S r   )rE  rm   )rF  rm   rn   return_control  s    
z4PyDB.init_matplotlib_support.<locals>.return_control)set_return_control_callbackc                      s    S r   rm   rm   )rA  rD  rm   rn   <lambda>      z.PyDB.init_matplotlib_support.<locals>.<lambda>)Z
matplotlibzmatplotlib.pyplotZpylab)Zpydev_ipython.matplotlibtoolsrA  rB  rC  rD  pydev_ipython.inputhookrH  r   )ry   rB  rC  rG  rH  rm   )rF  rA  rD  rn   init_matplotlib_support  s    zPyDB.init_matplotlib_supportc                 C   sD   t | jdkr@t| jD ]&}|tjkr| j|}|  d| _qd S )Nr   T)r   r   r   rk   modulesr>  r   )ry   r?  Zactivate_functionrm   rm   rn   _activate_mpl_if_needed  s    
zPyDB._activate_mpl_if_neededc                 C   s2   z ddl m} | }|r|  W n   Y nX d S )Nr   )get_inputhook)rK  rO  )ry   rO  Z	inputhookrm   rm   rn   _call_mpl_hook  s    
zPyDB._call_mpl_hookc              	   C   s~   | j d krd S |r| jntD || jkr6W 5 Q R  d S t|}|jrRW 5 Q R  d S || j|< W 5 Q R X | j | j| d S r   )	r   r   r   r   rW   pydev_notify_killr   r   Zmake_thread_created_message)ry   r   r'   use_lockr  rm   rm   rn   notify_thread_created  s    

zPyDB.notify_thread_createdc              	   C   sx   | j dkrdS |r| jnt> | j|d}|dkrBW 5 Q R  dS |jj}|sVd|j_W 5 Q R X | j | j	| dS )z: if thread is not alive, cancel trace_dispatch processing NT)
r   r   r   r   r>  r  rQ  r   r   make_thread_killed_message)ry   r   rR  r'   Zwas_notifiedrm   rm   rn   notify_thread_not_alive  s    
zPyDB.notify_thread_not_alivec              
   C   sV  | j D |   i }t }g }| j |D ]}t|ddr>q,t|trTtd q,t	|r,| j
s|D ]D}t|}t| t|}||krft|rft|}t|| qft|}|||< | j||dd q,t| j
 }	|	D ]}||kr|| q|D ]}| j|dd qW 5 Q R X t|dkrR|   |D ]}t|dr4|  q4ntt }
|
dfD ]}| |}g }z|d}| jst|trz|    d| _!W n   t"d	d
t#$  Y nX d| _|%|
rt"d	dt&| |'|  nt"d	dt&| || qxW n. t(j)k
rB   |D ]}|*| q,Y nX qdW 5 Q R X dS )z2This function processes internal commands
        r  Fr  )rR  r   r   *Tr   z*Matplotlib support in debug console failedzprocessing internal command z NOT processing internal command N)+r   r   r  r   r  r   r<   r"   r!  r$   r   r   r   r+   Zhas_additional_frames_by_idZget_additional_frames_by_idadd_additional_frame_by_idrS  listkeysappendrU  r   r   r#  r   r   threadingCurrentThreadr1  r   r   r:   r@  r   rC   r   
format_excZcan_be_executed_bystrdo_itr=   Emptyr2  )ry   Zprogram_threads_aliveall_threadsZprogram_threads_deadr   Zexisting_threadZold_thread_idr   Zframes_by_idZ
thread_idsZcurr_thread_idr4  Zcmds_to_add_backr3  rm   rm   rn   r}     sp    







zPyDB.process_internal_commandsc                 C   s4   i }t |D ]\}}|||j< q|||< |   d S r   )r   lineclear_skip_caches)ry   fileZid_to_breakpointr   Z
break_dictZbreakpoint_idZpybreakpointrm   rm   rn   consolidate_breakpointsI  s
    zPyDB.consolidate_breakpointsc                 C   s   t   t  d S r   )rQ   r~   rR   r   rm   rm   rn   rb  Q  s    zPyDB.clear_skip_cachesc           
      C   s   zt |||||||}W n& tk
r>   td|f  Y d S X |jrx| j }	||	|< tjdkrrtd|	f  |	| _|j	r| j
 }	||	|< tjdkrtd|	f  |	| _
|S )NzQError unable to add break on exception for: %s (exception could not be imported)
r   z$Exceptions to hook on terminate: %s
zExceptions to hook always: %s
)r-   ImportErrorr"   errornotify_on_unhandled_exceptionsr   copyr   DEBUG_TRACE_BREAKPOINTSnotify_on_handled_exceptionsr   )
ry   	exception	condition
expressionrj  rg  Znotify_on_first_raise_onlyZignore_librariesZebcprm   rm   rn   add_break_on_exceptionU  s4    
	



zPyDB.add_break_on_exceptionc                 C   s.   t |}t|_||_|jdkr$t|_t|_|S )Nr   )rW   r   suspend_typer   pydev_step_cmdr2   r   pydev_state)ry   r'   r   inform   rm   rn   _mark_suspend}  s    
zPyDB._mark_suspendc           
      C   s   | j   |r| j   | ||}|rP||}|dk	rPz| | W 5 d}X |tkrz|jdk	rz|j}d|_| || |s| j	rd}|rt
 }|D ]P}	t|	ddrq|	|krq| |	t}||	}|dk	rz| | W 5 d}X qdS )a  
        :param thread:
            The thread which should be suspended.

        :param stop_reason:
            Reason why the thread was suspended.

        :param suspend_other_threads:
            Whether to force other threads to be suspended (i.e.: when hitting a breakpoint
            with a suspend all threads policy).

        :param is_pause:
            If this is a pause to suspend all threads, any thread can be considered as the 'main'
            thread paused.
        NTr  )r   r   r   rt  r  r
  r0   Z conditional_breakpoint_exception$_send_breakpoint_condition_exceptionr   r*   r  r  r6   )
ry   r'   r   Zsuspend_other_threadsZis_pausers  r  &conditional_breakpoint_exception_tupler`  r   rm   rm   rn   set_suspend  s:    




zPyDB.set_suspendc                 C   s<   t |}|r8t|dkr8|\}}t|||}| || dS )zoIf conditional breakpoint raises an exception during evaluation
        send exception details to java
        r   N)r   r   rF   r5  )ry   r'   rv  r   r   Z
stacktracer3  rm   rm   rn   ru    s
    z)PyDB._send_breakpoint_condition_exceptionc                 C   s$   t |}t|||}| || dS )zSends details on the exception which was caught (and where we stopped) to the java side.

        arg is: exception type, description, traceback object
        N)r   rG   r5  )ry   r'   argZcurr_frame_idr   r3  rm   rm   rn   send_caught_exception_stack  s    z PyDB.send_caught_exception_stackc                 C   s(   t |}t|}| || |   dS )zXSends that some thread was resumed and is no longer showing an exception trace.
        N)r   rH   r5  r}   )ry   r'   r   r3  rm   rm   rn   %send_caught_exception_stack_proceeded  s    z*PyDB.send_caught_exception_stack_proceededc                 C   s   | j  }| j| dS )z=Sends a message that a new process has been created.
        N)r   make_process_created_messager   r   ry   cmdrm   rm   rn   send_process_created_message  s    
z!PyDB.send_process_created_messagec                 C   sZ   | j tjkrV| j r$td dS | j }t	
 }|| j|j< | j| |  dS )aF  When `PyDB` works in server mode this method sends a message that a
        new process is going to be created. After that it waits for the
        response from the IDE to be sure that the IDE received this message.
        Waiting for the response is required because the current process might
        become substituted before it actually sends the message and the IDE
        will not try to connect to `PyDB` in this case.

        When `PyDB` works in client mode this method does nothing because the
        substituted process will try to connect to the IDE itself.
        z/Skip sending process substitution notification
N)r   rI   r)  r   r   r"   r   r   r{  r%   r   r   seqr   r   r   )ry   r}  eventrm   rm   rn    send_process_will_be_substituted  s    


z%PyDB.send_process_will_be_substitutedc           
      C   sh   d}d}|j }|dks|dkr^|jj}|dkr2d}|dksB||krZ|}	| j|_|	|_ d}nd}|||fS )	NF ra  rk  )?z<module>rV  Tz.jump is available only within the bottom frame)f_linenof_codeco_namerP   f_trace)
ry   r  r  	func_name	next_linestopresponse_msgold_lineZcurr_func_namera  rm   rm   rn   set_next_statement  s    zPyDB.set_next_statementc                 C   s   | j   zlzRt }|D ]B}t|ddrt|drt|dr|j|kr|j|kr|j	  qW n   t
  Y nX W 5 | j   X d S )Nr  Fcancel_eventr   )r   r   r   r  r  r#  r   frame_idr  r   r   r   )ry   r   r  r`  r   rm   rm   rn   cancel_async_evaluation  s    
 zPyDB.cancel_async_evaluationc                 C   s<  |    d}t|}|j}	|jj}
|r|jj}d|j_i }|rb|d }|dk	rb|j||j< |j}qF| j	j
|||	||
|d}|  |j}| j| tjj g }ttjD ]T\}}|j|jkr| j| j	||j | j| j	
||jtd|
 || qW 5 Q R X | j||	 | |||||
| W 5 Q R X dS )a   busy waits until the thread state changes to RUN
        it expects thread's state as attributes of the thread.
        Upon running, processes any outstanding Stepping commands.

        :param is_unhandled_exception:
            If True we should use the line of the exception instead of the current line in the frame
            as the paused location on the top-level frame (exception info must be passed on 'arg').
        r  r  r   N)frame_to_lineno)r}   r   r   r  Ztrace_suspend_typepydev_message	tb_linenotb_frametb_nextr   Zmake_thread_suspend_messager~   thread_stack_strr   r   rK   custom_frames_lockr   custom_framesr   r  Z!make_custom_frame_created_messagenamer  r6   rZ  r   r   _do_wait_suspend)ry   r'   r  r  rx  send_suspend_messageis_unhandled_exceptionr  r   r   rp  messager  tbr}  from_this_threadr  custom_framerm   rm   rn   do_wait_suspend+  s6    	zPyDB.do_wait_suspendc                 C   s  |j }|jtkrP| jsP|   |jtkrP| jsP| jr<|   |   t	d q| 
t|tt| |jtks||jtkrd |_d |j_n |jtkr||_d |j_| | n|jtkr| | d |_||j_n|jtks|jtkrN| | d}d}	|j}
tsZ| |||j|j\}}}	|rLd|_t|_t|_|  |||||| d S nzPz| |||j|j\}}
}	W n, t'k
r } zd| }	W 5 d }~X Y nX W 5 t!r|j"}| j#$|||	}| j%&| d|_"X |r"| j#(t||j}| j%&| t|_t|_| )|||| d S d|_t|_t|_| j)||||dd d S n@|jt*kr|j+}|d k	r|||_| | nd |_d|_t,|_~| j#(t||j}| j%&| t-j.& |D ]}| j%&| j#/| qW 5 Q R X d S )Nr   Fr  r   z%s)r  )0r  rr  r   r   rN  r   rP  r}   r&   r{   r  r   r]  idrq  r2   r5   pydev_step_stopZpydev_smart_step_contextZsmart_step_stopr3   r
  r9   r7   r1   r  r
   r  Zpydev_func_nameZpydev_next_liner6   r   r  r   r  r   Z"make_set_next_stmnt_status_messager   r   
ValueErrorZmake_thread_run_messager  r4   f_backr   rK   r  rT  )ry   r'   r  r  rx  rp  r  rs  r  r  r  _r  r}  eZ
back_framer  rm   rm   rn   r  Z  s    




zPyDB._do_wait_suspendc           
   
   C   s   t d t|}t|| |\}}}t|}tjt	krHt
||| t  zxz.t|| | |t | j||d|dd W nD tk
r }	 z|	W 5 d }	~	X Y n    t d|d f  Y nX W 5 t| t| d }X d S )NzWe are stopping in post-mortem
rk  T)r  z5We've got an error while stopping in post-mortem: %s
r   )r"   r   r   r+   rW  r*   Z$get_top_level_trace_in_project_scoperk   
excepthookr   original_excepthookr/   rN   Zremove_additional_frame_by_idrM   rw  r8   r  KeyboardInterruptrf  )
ry   r'   r  Zframes_byidrx  r   exctypevaluer  r  rm   rm   rn   stop_on_unhandled_exception  s(    





z PyDB.stop_on_unhandled_exceptionc                 K   s   | dd}|rt|d k	rzt|jj }W n   t|}Y nX t|d }|d kr|rv|jd k	r|jtk	rt|_n|j| j	k	r| j	|_|j
}q~d S )NdisableFr   )r>  r   rd   r  co_filenamerc   get_file_typer  r   rP   r  )ry   r  kwargsr  Zabs_path_real_path_and_base	file_typerm   rm   rn   r
    s     z$PyDB.set_trace_for_frame_and_parentsc                 C   s0   | j }|d k	r|  t|  }| _ |  d S r   )r   r   rs   r&  )ry   Zcurr_pydb_command_threadZnew_pydb_command_threadrm   rm   rn   _create_pydb_command_thread  s
    z PyDB._create_pydb_command_threadc                 C   s0   | j }|d k	r|  t|  }| _ |  d S r   )r   r   r   r&  )ry   Zcurr_output_checker_threadr   rm   rm   rn   _create_check_output_thread  s
    z PyDB._create_check_output_threadc                 C   s   |    |   d S r   )r  r  r   rm   rm   rn   start_auxiliary_daemon_threads  s    z#PyDB.start_auxiliary_daemon_threadsc                 C   sl   |    | js"| jdk	s"| jdk	r0|   d| _|   |rHt| j	 t
sPtrh| jd}| j| dS )zO Shared code to prepare debugging by installing traces and registering threads Ncython)r  r   r   r   r  rT   patch_threadsr   r   rP   rS   rV   r   Zmake_show_warning_messager   r   )ry   Zenable_tracing_from_startr}  rm   rm   rn   prepare_to_run  s    zPyDB.prepare_to_runc                 C   s4   zt | j W n   Y nX ddlm} |  d S )Nr   )patch_thread_modules)r%   settracerP   _pydev_bundle.pydev_monkeyr  )ry   r  rm   rm   rn   r    s    zPyDB.patch_threadsc                 C   sv  d }d}|r@dt jkr&t jdd |d\}}}|}t|}	|	d krt|}
|
d krnt jd|  d S td| }	|	d krt jd|  d S |	}n|	}tj	|	}
tj
|
d}tj
|
d}|	drtj|r|}	ntj|r|}	n@|	d	r6tj|r$tj|s$|}	ntj|r6|}	|	t jd< tj|rntj
|d}tj|rn|}d }|d krt|d
}|j}zt|d< W n tk
r   Y nX |d kr|}t jd dkr|d k	r|jt jd rt jd= |st jdtjt|d  |rb| js4td q| jsT| jsT| jsT| jrZd | _|    t! }t"|}| j#d k	rt$  | j#%t&  t'dd|( |dd|dd t)|d
 | j*d k	rt+rt,  t'dddddd|dd d d
 zt-r| .  W n    t jd t/0  Y nX t1t dr0t 2  | 3|| | j4rTt5|}t6|j7_8|rb| 9  | :||||||S )Nr  r   :zNo module named %s
z%s.__main__z__main__.pyz__main__.pycz__init__.pycz__init__.pypydevd__builtins__r$  Zthreading_eventr'   r&  re   )parentZasyncio_eventTaskr  )r  r  z&Matplotlib support in debugger failed
	exc_clear);rk   pathinsert	partitionr_   ra   stderrwriteosdirnamer   endswithexistsargvisdirisfilerX   __dict__r  	NameError__file__r/  splitr`   r   r&   r{   r   r   r   r   rT   r  r[  r   r   r]   Zset_start_timer\   r[   r   r   r   r   r^   r   rL  r   r   r#  r  rS  r   rW   r5   r  rq  r   _exec)ry   rc  globalslocals	is_module	set_tracemodule_nameentry_point_fnr  r  Zmod_dirZmain_pyZmain_pyc
new_targetmr   r   rs  rm   rm   rn   run  s    





.$zPyDB.runc           
      C   s   |st ||| nx|r>t|d|g||d}t||}|  nNddl}	t|	drtjdd dkrr|	j|dd q|	j|dd	 n
|		| |S )
zs
        This function should have frames tracked by unhandled exceptions (the `_exec` name is important).
        r   )levelfromlistr  r  N_run_module_as_mainr   r   F)Z	set_argv0)
alter_argv)
r!   Zexecfile
__import__r  runpyr#  rk   rl   r  
run_module)
ry   r  r  r  rc  r  r  modfuncr  rm   rm   rn   r    s    


z
PyDB._execc                 C   s6   t j  t j  |   | j }| j| d S r   )	rk   stdoutflushr  r   r   Zmake_exit_messager   r   r|  rm   rm   rn   exiting  s
    


zPyDB.exitingc                 C   s   |    t }ddlm} |d d|dtj	tj
t||}t|}t|t||i | j||}| j| | jr|   |   td q|d S )Nr   )pydevd_frame_utilsr   Consoler   )rN  r%   currentThread_pydevd_bundler  FrameZFCoder  r  abspathr  r  r   r+   rW  r  r   Zmake_show_console_messager   r   r   rP  r}   r&   r{   )ry   r  r'   r  r  r   r}  rm   rm   rn   wait_for_commands  s"     zPyDB.wait_for_commands)T)NF)F)F)T)T)F)FF)TF)T)NNFT)@r   r   r   r   rt   r   r   r   r   r   propertyr   setterr  r  r  r  r  r  r  r   r   r(  r-  r1  r5  r<  r   r@  rL  rN  rP  rS  rU  r}   rd  rb  ro  rt  rw  ru  ry  rz  r~  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r  _trace_dispatchrP   rT   rU   rm   rm   rm   rn   r   `  s~   
d


(




] 
(
>

/c


 r   c                 C   s   d| d< d| d< d| d< d S )NTDEBUG_RECORD_SOCKET_READSre   ri  ri   DEBUG_TRACE_LEVELrm   setuprm   rm   rn   	set_debug  s    r  c                 C   s   ddl m} ||  d S )Nr   )pydev_monkey_qt)_pydev_bundler  Zpatch_qt)Zqt_support_moder  rm   rm   rn   enable_qt_support  s    r  c                 C   s   t |  dS )zE
    Helper to dump thread info (default is printing to stderr).
    N)r*   dump_threads)streamrm   rm   rn   r    s    r  c                 C   s*   t jd t jd | r&t d d S )NzUsage:
zUpydevd.py --port N [(--client hostname) | --server] --file executable [file_options]
r   )rk   r  r  exit)ZdoExitrm   rm   rn   usage  s    r  c                   @   s&   e Zd ZdddZdd Zdd ZdS )	_CustomWriterNc                 C   s>   t |dtjdd| _|| _|r4t||d|d| _|| _dS )a  
        :param out_ctx:
            1=stdout and 2=stderr

        :param wrap_stream:
            Either sys.stdout or sys.stderr.

        :param bool wrap_buffer:
            If True the buffer attribute (which wraps writing bytes) should be
            wrapped.

        :param callable(str) on_write:
            May be a custom callable to be called when to write something.
            If not passed the default implementation will create an io message
            and send it through the debugger.
        encodingPYTHONIOENCODINGrr   F)wrap_bufferon_writeN)	r  r  environr   r  _out_ctxr  buffer	_on_write)ry   Zout_ctxZwrap_streamr  r  rm   rm   rn   rt     s
    z_CustomWriter.__init__c                 C   s   d S r   rm   r   rm   rm   rn   r    s    z_CustomWriter.flushc                 C   s   | j d k	r|  | d S |r|tr8t|trR|dd}nt|trR|j| jdd}t }|d k	r||j	
|| j}|j| d S )Nrr   replace)errors)r  r   r   unicodeencodebytesdecoder  r@   r   Zmake_io_messager  r   r   )ry   r,  rv   r}  rm   rm   rn   r    s    



z_CustomWriter.write)N)r   r   r   rt   r  r  rm   rm   rm   rn   r    s   
r  c                 C   sH   t tdsDtsdnd}tj}td||| t_|t_t|tj|t_d S )N_pydevd_out_buffer_TFre   )	r#  rk   r   r  r  r  Zstdout_originalr(   IORedirectorr  r  originalrm   rm   rn   r8  *  s    
r8  c                 C   sH   t tdsDtsdnd}tj}td||| t_|t_t|tj|t_d S )N_pydevd_err_buffer_TFr   )	r#  rk   r   r  r  r  Zstderr_originalr(   r  r  rm   rm   rn   r9  2  s    
r9  .  Tc	           	   	   C   s2   t   zt| ||||||| W 5 t   X dS )a  Sets the tracing function with the pydev debug function and initializes needed facilities.

    @param host: the user may specify another host, if the debug server is not in the same machine (default is the local
        host)

    @param stdoutToServer: when this is true, the stdout is passed to the debug server

    @param stderrToServer: when this is true, the stderr is passed to the debug server
        so that they are printed in its console and not in this process console.

    @param port: specifies which port to use for communicating with the server (note that the server must be started
        in the same port). @note: currently it's hard-coded at 5678 in the client

    @param suspend: whether a breakpoint should be emulated as soon as this function is called.

    @param trace_only_current_thread: determines if only the current thread will be traced or all current and future
        threads will also have the tracing enabled.

    @param overwrite_prev_trace: deprecated

    @param patch_multiprocessing: if True we'll patch the functions which create new processes so that launched
        processes are debugged.

    @param stop_at_frame: if passed it'll stop at the given frame, otherwise it'll stop in the function which
        called this method.
    N)_set_trace_lockr   r   _locked_settrace)	r*  stdoutToServerstderrToServerr+  suspendtrace_only_current_threadoverwrite_prev_tracepatch_multiprocessingstop_at_framerm   rm   rn   r  >  s    %r  c                 C   s  |r*zddl m} W n   Y n
X |  i t_ts>t  tj	d kr`| dt
||d}	|	t_	t }
|
| | da|a|atrt  trt  t|
 t }t|}|
jstd q|
t j tj  z$ttjD ]\}}|
|j  qW 5 tj  X |
!  |
j"dd |s2|
#  |
j$dd t%&t' n8t( }
|
t j t }t|}|
"  |sv|
#  |r|d k	rt)|_*t+|_,||_-t.|_/n|
0|t1 d S )	Nr   pydev_monkeyF)clientserverr+  multiprocessTr$  )r   )r  )2r  r  patch_new_process_functionsr<   r   	connectedr)   
setup_typeSetupHolderr  intr   r-  r6  r7  r8  r9  patch_stdinr[  rW   r   r&   r{   r
  r   r  rK   r  r   r   r   r  r  r  r   r  r   atexitregister	stoptracer@   r   rr  r3   rq  r  r   rp  rw  r0   )r*  r  r  r+  r  r  r  r  r  r  debuggerr   r  Z_frameIdr  rm   rm   rn   r  v  sp    



r  c                  C   st   t rpt  td  ztd  W n   Y nX ddlm}  |   t }|rl|j	t
 dd |  t  da d S )Nr   )undo_patch_thread_modulesT)r  F)r"  r   restore_sys_set_trace_funcrk   r  r%   r  r+  r@   r
  r   r  rO   )r+  r*  rm   rm   rn   r)    s    
r)  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )
Dispatcherc                 C   s
   d | _ d S r   )r+  r   rm   rm   rn   rt      s    zDispatcher.__init__c                 C   s<   || _ || _t| j | j| _t| | _d| j_| j  d S r   )r*  r+  rD   r  DispatchReaderr   r  r  )ry   r*  r+  rm   rm   rn   r-    s    
zDispatcher.connectc                 C   s    z| j   W n   Y nX d S r   )r   r   r   rm   rm   rn   close  s    zDispatcher.closeN)r   r   r   rt   r-  r/  rm   rm   rm   rn   r-    s   r-  c                   @   s6   e Zd Zdd Zeejdd Zdd Zdd Zd	S )
r.  c                 C   s   || _ t| | j j d S r   )
dispatcherr>   rt   r  )ry   r0  rm   rm   rn   rt     s    zDispatchReader.__init__c                 C   s   t  }d|_t| S r   )r%   r  r  r>   r   )ry   dummy_threadrm   rm   rn   r     s    zDispatchReader._on_runc                 C   s   t |  d S r   )r>   handle_exceptr   rm   rm   rn   r2    s    zDispatchReader.handle_exceptc                 C   s   |dkrt || j_d| _d S )Nc   T)r%  r0  r+  r|   )ry   Zcmd_idr  textrm   rm   rn   process_command  s    zDispatchReader.process_commandN)	r   r   r   rt   r,   r>   r   r2  r5  rm   rm   rm   rn   r.    s
   
r.  c                 C   s   |  ddS )z
    The new connection dispatch approach is used by PyDev when the `multiprocess` option is set,
    the existing connection approach is used by PyCharm when the `multiproc` option is set.
    	multiprocF)r   r  rm   rm   rn   _should_use_existing_connection%  s    r7  c                  C   sN   t j} | d }| d }t| rFt }z||| |j}W 5 |  X ||fS )Nr  r+  )r$  r  r7  r-  r/  r-  r+  )r  r*  r+  r0  rm   rm   rn   dispatch-  s    

r8  c                  C   st   ddl m}  d| _ddlm} t \}}ddl}|  |dk	rpdada	t
  |dk	r\|  t||ddddd dS )zo
    When creating a fork from a process in the debugger, we need to reset the whole debugger environment!
    r   )GlobalDebuggerHolderN)clear_thread_local_infoFT)r+  r  r  r  r  )_pydevd_bundle.pydevd_constantsr9  Z
global_dbg)_pydevd_frame_eval.pydevd_frame_eval_mainr:  r8  r   r,  r"  forkedrL   r  )r9  r:  r*  r+  r   rm   rm   rn   settrace_forked;  s(    
r>  c                   @   s   e Zd ZdZdS )r$  N)r   r   r   r  rm   rm   rm   rn   r$  _  s   r$  c                 C   sp   ddd}| |  |} t }| d rXt tjjkrDtjd nddl	m
} | |_| d rlt| d  d	S )
z/

    :type setup_options: dict[str, bool]
    Fr  )save-signatures
qt-supportr?  zACollecting run-time type information is not supported for Jython
r   )SignatureFactoryr@  N)updater?   r)   Zget_vm_typeZPydevdVmTypeZJYTHONrk   r  r  Z_pydevd_bundle.pydevd_signaturerA  r   r  )Zsetup_optionsZdefault_optionsr*  rA  rm   rm   rn   apply_debugger_optionsd  s    

rC  c                 C   s"   ddl m} tj}|| |t_d S )Nr   )DebugConsoleStdIn)Z_pydev_bundle.pydev_stdinrD  rk   stdin)r*  rD  Z
orig_stdinrm   rm   rn   r&  z  s    r&  c                  C   s  t  } | sd S |   t \}}}|rN|jjj}| |rFd|krFqN|j}q$|rd}|j}|rr|j|jkrrd }|r|jjj}t	t
j|sd|krq|d7 }|jr|jj|jk	r|j}qrqqrz||}W n tk
r   ||_Y nX d |_tjt||||d t  d S )NZ_pydevdre   )limit)r@   r   rk   r   r  r  r  r  r  r  r  r  basenamewith_tracebackr   __traceback__	__cause__r   print_exceptiontyper/   )r*  r  r  r  r  rF  r  rm   rm   rn   handle_keyboard_interrupt  s<    

rM  )DebuggerEventHandler)pydevd_extension_utils)Zdebugger_versionc               
   C   s  z ddl m}  | tj}|t_W n$ tk
rD   t  t	d Y nX |d rzdt
  }W n   d}Y nX tjd|  t  td|d	   td
ttj  t|dd  trt| |dtjt_|dtjt_|dtjt_|d }|d }|d	 }d}t }zddlm} W n   Y nX |d rT|  n|d rtd t }	zz|	!|| |	j"d k	r|	j"}td|  t#dt
   z|  W n   t$d t  Y nX n
t$d W 5 |	   X n@z|%  W n   t$d t  Y nX |&ddkr8t
j'(|)dr8t
j'*|}
t
j'+|
d}t
j',|r8zt-|d}z|. / D ]}|0 }|)dr|dd  0 }|1d d}|2d!}t3|d dkrd"}n(t3|d dkrt3|d d#krd"} qqW 5 |   X W n   t  Y nX zdd$l4m5} |6  W n&   zt7  W n   Y nX Y nX |d% }t8| |r$tjd& t
j'*t9}t
j'+|d'}tj:dd(|  dd l;}t9|d)< tj:d*d+|<|  tj:d,d- tj:d.d/ |j=|d	 d d |dd0 n|d1 r6t> |_?|d2 rNt@rNtA |_BtC| z|!|| W n2   tjd3||f  t  tDd Y nX d"aEz|=|d	 d d |}W n, tFk
r } ztG   W 5 d }~X Y nX |d4 r|H| d S )5Nr   )process_command_linere   zprint-in-debugger-startupz
 (pid: %s)r  zpydev debugger: starting%s
zExecuting file %src  zarguments: %sZvm_typer  ri  r  r+  r  Fr  r   r6  zStarted in multiproc mode
zReceived port %d
z)pydev debugger: process %d is connecting
z!Error patching process functions
z8pydev debugger: couldn't get port for new debug process
zdev_appserver.pyr   VERSIONrzrelease:   "rg   Trj   )pydevd_stacklessr?  z6pydev debugger: google app engine integration enabled
z!pydev_app_engine_debug_startup.pyz--python_startup_script=r  r   z--python_startup_args=%sri   z--automatic_restart=norf   z--max_module_instances=1)r  zsave-threadingzsave-asynciozCould not connect to %s: %s
zcmd-line)IZ+_pydevd_bundle.pydevd_command_line_handlingrP  rk   r  r$  r  r  r   r   r  r  getpidr  r  r    r"   r   r]  r)   r#  r   r   r  r   r  ri  r  r   r  r  r!  r-  r/  r-  r+  rs  rf  Z(patch_new_process_functions_with_warningfindr  rG  r/  r  r   r  openread
splitlinesstripr  r  r%  r  rU  Zpatch_stacklessr  r&  r  r  jsondumpsr  rY   r   r   rZ   r   rC  r  r"  r  rM  r  )rP  r  pidr+  r*  fZfix_app_engine_debugr*  r  r0  Zappserver_dirZversion_filer  ra  versionrU  r  Zcurr_dirZapp_engine_startup_filer\  r  r  rm   rm   rn   main  s    












ra  __main__)N)N)r   )N)N)	NFFr  TFFFN)r   rk   
contextlibr   r   Z-_pydevd_bundle.pydevd_collect_try_except_infor   rl   RuntimeErrorr   r'  r  r   	functoolsr   collectionsr   r;  r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r    r!   r"   Z(_pydev_bundle._pydev_filesystem_encodingr#   Z#_pydev_bundle.pydev_is_thread_aliver$   Z _pydev_imps._pydev_saved_modulesr%   r&   r'   r  r(   r)   r   r*   r+   Z_pydev_bundle.pydev_overrider,   Z!_pydevd_bundle.pydevd_breakpointsr-   r.   r/   Z_pydevd_bundle.pydevd_commr0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   Z#_pydevd_bundle.pydevd_custom_framesrK   rL   Z!_pydevd_bundle.pydevd_frame_utilsrM   rN   Z-_pydevd_bundle.pydevd_kill_all_pydevd_threadsrO   Z$_pydevd_bundle.pydevd_trace_dispatchrP   r  rQ   rR   rS   r<  rT   rU   rV   Z,_pydevd_bundle.pydevd_additional_thread_inforW   Z_pydevd_bundle.pydevd_utilsrX   Z5pydevd_concurrency_analyser.pydevd_concurrency_loggerrY   rZ   r[   r\   Z2pydevd_concurrency_analyser.pydevd_thread_wrappersr]   r^   Zpydevd_file_utilsr_   r`   ra   Zpydev_ipythonZ&_pydevd_bundle.pydevd_dont_trace_filesrb   rc   rd   r   r  __version_info__Z__version_info_str__vrZ  r]  r   __version__ro   r  rp   Z"_pydevd_bundle.pydevd_plugin_utils	enumerater  r  r[  __excepthook__r  r
  r"  r6  r7  remoter=  Zfile_system_encodingrs   r   objectr   r   r   r   r  r  r  r  r  r8  r9  r  r   r  r  r)  r-  r.  r7  r8  r>  r$  rC  r&  rM  Z#_pydevd_bundle.pydevd_extension_apirN  rO  Zextensions_of_typehandlerZon_debugger_modules_loadedra  r   rm   rm   rm   rn   <module>   s   dt

")^$         

4

         
6p$* +
