
    "e                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dl	m
Z
 d dlmZ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%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 d d	l7m8Z8 d d
l9m:Z:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dlAmBZBmCZCmDZDmEZEmFZF d dlGmHZH d dlImJZJ d dlKmLZL d dlMmNZN d dlOmPZP d ZQ G d deR      ZS G d deR      ZTy)    N)partial)	pydev_log)pydevd_base_schemapydevd_schema)CompletionsResponseBodyEvaluateResponseBodyExceptionOptionsGotoTargetsResponseBodyModulesResponseBodyProcessEventBodyProcessEventScopeScopesResponseBodySetExpressionResponseBodySetVariableResponseBodySourceBreakpointSourceResponseBodyVariablesResponseBodySetBreakpointsResponseBodyResponseCapabilitiesPydevdAuthorizeRequestRequestStepInTargetsResponseBody"SetFunctionBreakpointsResponseBodyBreakpointEventBreakpointEventBodyInitializedEvent)	PyDevdAPI)get_exception_classFunctionBreakpoint)
CMD_PROCESS_EVENT
CMD_RETURNCMD_SET_NEXT_STATEMENTCMD_STEP_INTOCMD_STEP_INTO_MY_CODECMD_STEP_OVERCMD_STEP_OVER_MY_CODEfile_system_encodingCMD_STEP_RETURN_MY_CODECMD_STEP_RETURN)ExcludeFilter)_extract_debug_optionsDebugOptions)
NetCommand)%convert_dap_log_message_to_expressionScopeRequest)PY_IMPL_NAMEDebugInfoHolderPY_VERSION_STRPY_IMPL_VERSION_STRIS_64BIT_PROCESS)USING_CYTHON)USING_FRAME_EVAL)!internal_get_step_in_targets_json)set_additional_thread_info)pydevd_find_thread_by_idc                    g }t        | t              s |d|        |S g }g }g }| D ]-  }t        |t              s |d|         |j                  d      }| |d|       ?|j                  d      }|j                  d      }	||	 |d|       q||}
d|vrmd|vrit        j
                  j                  |
      r,|
j                  d	      s|
j                  d
      s|
d	z  }
|
dz  }
|j                  t        |
| d             |j                  t        |
| d             |	|j                  t        |	| d             & |d       0 t        |d       }t        |d       }||z   |z   }|S )Nz1Invalid "rules" (expected list of dicts). Found: includez6Invalid "rule" (expected dict with "include"). Found: pathmodulez?Invalid "rule" (expected dict with "path" or "module"). Found: *?/\z**TFz8Internal error: expected path or module to be specified.c                 .    t        | j                         S Nlennameexclude_filters    P/usr/lib/python3/dist-packages/_pydevd_bundle/pydevd_process_net_command_json.py<lambda>z3_convert_rules_to_exclude_filters.<locals>.<lambda>[   s    adesexexay`y     )keyc                 .    t        | j                         S rE   rF   rI   s    rK   rL   z3_convert_rules_to_exclude_filters.<locals>.<lambda>\   s    [^_m_r_r[sZs rM   )
isinstancelistdictgetosr>   isdirendswithappendr,   sorted)ruleson_errorexclude_filtersdirectory_exclude_filtersmodule_exclude_filtersglob_exclude_filtersruler=   r>   r?   glob_patterns              rK   !_convert_rules_to_exclude_filtersra   (   s   OeT"%QRh c %'!!#! "	UDdD)RWYZhhy)GW[]^88F#DXXh'F|`dfg#d?s$ww}}\2  ,44S9,BWBWX\B](C/L$,-44]<U\Q\^b5cd(//lPWKY]0^_#&--mFKQV.WX STE"	UR %++DJy$z!!'(>Ds!t36JJMccrM   c                       e Zd Zd Zd Zd Zy)IDMapc                 p    i | _         i | _        t        t        t	        j
                  d            | _        y )Nr   )_value_to_key_key_to_valuer   next	itertoolscount_next_id)selfs    rK   __init__zIDMap.__init__d   s)    iooa&89rM   c                      | j                   |   S rE   )rf   )rk   rN   s     rK   obtain_valuezIDMap.obtain_valuei   s    !!#&&rM   c                     	 | j                   |   }|S # t        $ r2 | j                         }|| j                  |<   || j                   |<   Y |S w xY wrE   )re   KeyErrorrj   rf   )rk   valuerN   s      rK   
obtain_keyzIDMap.obtain_keyl   s_    	,$$U+C
 
	  	,--/C&+Ds#(+Du%
		,s    7AAN)__name__
__module____qualname__rl   rn   rr    rM   rK   rc   rc   b   s    :
'rM   rc   c                      e Zd Zd Zd-dZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-y,).PyDevJsonCommandProcessorc                     || _         t               | _        t               | _        t        t        t        j                  d            | _	        t               | _        d| _        y )Nr   F)	from_jsonr   apir.   _optionsr   rg   rh   ri   _next_breakpoint_idrc   _goto_targets_map_launch_or_attach_request_done)rk   rz   s     rK   rl   z"PyDevJsonCommandProcessor.__init__x   sE    ";$#*41C#D !&.3+rM   c           
      Z   d}	 t        |t              r|j                  d      }| j                  |d      }t        j
                  dk\  rVt        j                  d|j                  j                  dt        j                  |j                  d      d	d
      d       |j                  dk(  sJ d|j                  j                         d}t!        | |d      }|t#        d|d       y|rt#        d|d       	 |j4                  5  |j                  t6        k(  r3|}
|
j8                  j:                  }|j<                  j?                  |       |j<                  jA                         s\tC        |jD                  d|j                  di       }tG        tH        d|d      }|jJ                  jM                  |       	 ddd       y |||      }||r|jJ                  jM                  |       ddd       y# t$        $ r}	 t        j&                  |      }	t)        |	j+                  dd      |	d         }n!#  t        j,                  d|       Y Y d}~yxY wt/        |      j1                  d      rj3                  d      rdd fd}Y d}~d}~ww xY w# 1 sw Y   yxY w)zB
        Processes a debug adapter protocol json command.
        Futf-8T)update_ids_from_dap   zProcess z: )update_ids_to_dap   )indent	sort_keys
requeston__requestNzUnhandled: z- not available in PyDevJsonCommandProcessor.
zHandled in pydevd: z! (in PyDevJsonCommandProcessor).
commandz	<unknown>seqzError loading json: %s'c                 b    d|j                   d|j                  d}t        t        d|d      S )NresponseF)typerequest_seqsuccessr   messager   Tis_json)r   r   r/   r#   )py_dbr   error_response	error_msgs      rK   
on_requestzFPyDevJsonCommandProcessor.process_net_command_json.<locals>.on_request   s4    &#*;;$&(" "*aNNrM   zClient not authenticated.)r   r   r   bodyr   r   )'rP   bytesdecoderz   r3   DEBUG_TRACE_LEVELr   info	__class__rs   jsondumpsto_dictr   r   lowergetattrprint	Exceptionloadsr   rS   	exceptionstr
startswithrV   
_main_lockr   	argumentsdebugServerAccessTokenauthenticationloginis_authenticatedr   r   r/   r#   writeradd_command)rk   r   json_contentssend_responseDEBUGr   method_namer   eloaded_jsonauthorize_requestaccess_tokenr   cmdr   s                 @rK   process_net_command_jsonz2PyDevJsonCommandProcessor.process_net_command_json   sg   
 +	b-/ - 4 4W =nn]nMG6 00A5%%..

7??]a?;bklx|0} @ A <<9,,,-4__-B-B-DFK {D9J!WbdeS^`a 	.  $::$+!0::QQ$$**<8''88:#KKQlsuw Q$G((-	. 	. UG,C=((-	. 	.Q  	O"jj7!+//)["I;W\K]^##$<mLAI##C(Y-?-?-D%aO	O O	OP	. 	.sB   4G< B4J!(J!<	J4H;:J;IJ:JJ!J*c                     |j                   j                  }dd i}|r||d<   t        j                  |d|i      }t	        t
        d|d      S )NclientAccessTokenr   kwargsr   Tr   )r   client_access_tokenr   build_responser/   r#   )rk   r   r   r   r   r   s         rK   on_pydevdauthorize_requestz4PyDevJsonCommandProcessor.on_pydevdauthorize_request   sS    #22FF#T*(;D$%%44Wfd^T*a4@@rM   c                    t        d0i 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ddddddddddddgddddddd dd!dd"dd#dd$dd%dd&g d'g d(g j                         }d|d)<   i x|d*<   }t        j                         |d+<   | j                  j                  |       t        j                  |d,|i-      }t        t        d.|d/      S )1N supportsConfigurationDoneRequestTsupportsConditionalBreakpoints!supportsHitConditionalBreakpointssupportsEvaluateForHoverssupportsSetVariablesupportsGotoTargetsRequestsupportsCompletionsRequestsupportsModulesRequestsupportsExceptionOptionssupportsValueFormattingOptionssupportsExceptionInfoRequestsupportTerminateDebuggee supportsDelayedStackTraceLoadingsupportsLogPointssupportsSetExpressionsupportsTerminateRequestsupportsClipboardContextsupportsFunctionBreakpointsexceptionBreakpointFiltersraisedzRaised ExceptionsF)filterlabeldefaultuncaughtzUncaught ExceptionsuserUnhandledzUser Uncaught ExceptionssupportsStepBacksupportsRestartFramesupportsStepInTargetsRequestsupportsRestartRequestsupportsLoadedSourcesRequestsupportsTerminateThreadsRequestsupportsDataBreakpointssupportsReadMemoryRequestsupportsDisassembleRequestadditionalModuleColumnscompletionTriggerCharacterssupportedChecksumAlgorithmssupportsDebuggerPropertiespydevd	processIdr   r   r   r   rv   )
r   r   rT   getpidr{   notify_initializer   r   r/   r#   )rk   r   r   r   pydevd_infor   s         rK   on_initialize_requestz/PyDevJsonCommandProcessor.on_initialize_request   s    (
-1(
 ,0(
 /3	(

 '+(
 !%(
 (,(
 (,(
 $((
 &*(
 ,0(
 *.(
 &*(
 .2(
 #(
  #'!(
" &*#(
$ &*%(
& )-'(
, $.AeT%0ERVW*5O\ab(+(
8 #9(
: "';(
< *.=(
> $)?(
@ */A(
B -2C(
D %*E(
F ',G(
H (-I(
J %'K(
L )+M(
N )+O(
P ')Q 	V .2)*'))X#%99;K ""5)%44Wfd^T*a4@@rM   c                     | j                   st        j                  d       | j                  j	                  |       | j                  j                  |       t        j                  |      }t        t        d|d      S )z:
        :param ConfigurationDoneRequest request:
        zKMissing launch request or attach request before configuration done request.r   Tr   )
r   r   criticalr{   runnotify_configuration_doner   r   r/   r#   )rk   r   r   configuration_done_responses       rK   on_configurationdone_requestz6PyDevJsonCommandProcessor.on_configurationdone_request  sa     22lmU**51&8&G&G&P#*a)DdSSrM   c                 N    | j                   j                  ||j                        S )z0
        :param ThreadsRequest request:
        )r{   list_threadsr   rk   r   r   s      rK   on_threads_requestz,PyDevJsonCommandProcessor.on_threads_request  s     xx$$UGKK88rM   c                 t    | j                  |       t        j                  |      }t        t        d|d      S )z2
        :param TerminateRequest request:
        r   Tr   )_request_terminate_processr   r   r/   r#   rk   r   r   r   s       rK   on_terminate_requestz.PyDevJsonCommandProcessor.on_terminate_request  s3     	''.%44W=*a4@@rM   c                 :    | j                   j                  |       y rE   )r{   request_terminate_process)rk   r   s     rK   r   z4PyDevJsonCommandProcessor._request_terminate_process  s    **51rM   c           	         |j                   }|j                  }|j                  }|j                  }|j                  j                  |      }|9t        g       }t        j                  ||ddd      }	t        t        d|	d      S |j                  d	z
  }
|j                  d
}n|j                  d	z
  }| j                  j                  |||||||
       y)z4
        :param CompletionsRequest request:
        NFz8Thread to get completions seems to have resumed already.r   r   r   r   r   Tr   r   r   )linecolumn)r   r   textframeIdsuspended_frames_manager$get_thread_id_for_variable_referencer   r   r   r/   r#   r  r  r{   request_completions)rk   r   r   r   r   r  frame_id	thread_idr   variables_responser  r  s               rK   on_completions_requestz0PyDevJsonCommandProcessor.on_completions_request   s     %%	kk~~$$22WW	 *2.D!3!B!B $Y" j!-?NN !!A%>>!D>>A%D$$UCHdQU^d$erM   c                     |dk(  r[t        j                         }|j                  d      xs |j                  d      }||rt         j                  j                  z   S dz   S |S )N.rC   rB    )rT   getcwdrV   r>   sep)rk   
local_rootremote_rootcwdappend_pathseps        rK   _resolve_remote_rootz.PyDevJsonCommandProcessor._resolve_remote_rootA  sX    #))+C'006R*:M:Mc:RN"''++@@R@@rM   c           	      >   " |j                  d      }|j                  dd      } j                  j                  |       |j                  dd      } j                  j                  |       |j                  dd      dk(  } j                  j	                  |       |j                  dd       "t        "t              rj"fd	} |d
d      }	 |d|	      }
 |d|	      } |d|	      } |d|	      } j                  j                   j                  j                  |
|||             g }|t        | fd      } j                  j                  |       t        |j                  d      |j                  d            } j                  j                  |        j                  j                  |        j                  j                   j                  j                           j                  j"                  r/ j                  j%                   j                  j"                         g }|j                  dg       D ]W  }|j                  dd      }|j                  dd      } j'                  ||      }|dk7  s?|dk7  sE|j)                  ||f       Y t+        |      rt-        j.                  |       |j                  dd       }|t-        j0                  |       |j                  d      } j                  j2                  rj5                  dd       d}nj5                  dd       |_         j                  j9                   j                  j:                          j                  j<                  sRdd g} j                  j>                  s j                  j@                  r|dgz  } j                  jC                  |       |j                  di       }t        |t              stE        jF                  d|       i }|j                  dd      }|j                  d      }|sg }|j                  d       }|r_tH        jJ                  jM                  |      r|j)                  |       n.|j)                  tH        jJ                  jO                  |             |j)                  tH        jJ                  jQ                  d!             tS        tT        d"g       }|rf|d   }|r_tH        jJ                  jM                  |      r|j)                  |       n.|j)                  tH        jJ                  jO                  |             t        |tV        tX        tZ        f      s|f}tY               }|D ]:  }	 |j]                  t-        j^                  t-        j`                  |                   < |}|j                  d$d%      }|j                  d&d'      } |j                  d(d)      }! j                  jg                  |||| |!        j                  jh                  r|d*k(  r j                  ji                           j                  jk                   j                  jl                         y # tb        $ r tE        jd                  d#|       Y w xY w)+NrY   steppingResumesAllThreadsTterminateChildProcessesonTerminatekillKeyboardInterruptvariablePresentationc                 p    j                  | |      }|dvrt        j                  d| d|d       |}|S )N)groupinlinehidezThe value set for "z" (zW) in the variablePresentation is not valid. Valid values are: "group", "inline", "hide")rS   r   r   )settingr   rq   variable_presentations      rK   get_variable_presentationzOPyDevJsonCommandProcessor._set_debug_options.<locals>.get_variable_presentationV  s@    -11'7C ;;NN#U-. $ErM   allr"  specialfunctionclass	protectedc                 <    j                   j                  |       S rE   )r{   send_error_message)msgr   rk   s    rK   rL   z>PyDevJsonCommandProcessor._set_debug_options.<locals>.<lambda>r  s    488#>#>uc#J rM   optionsdebugOptionspathMappings	localRootr  
remoteRootresolveSymlinksisOutputRedirectedFr      
autoReloadz,Expected autoReload to be a dict. Received: enablewatchDirectoriesprogramr  argvzError adding watch dir: %spollingIntervalr   exclude)z
**/.git/**z**/__pycache__/**z**/node_modules/**z**/.metadata/**z**/site-packages/**r=   )z**/*.pyz**/*.pywlaunch)7rS   r{    set_stepping_resumes_all_threadsset_terminate_child_processes set_terminate_keyboard_interruptrP   rR   set_variable_presentationVariablePresentationra   set_exclude_filtersr-   r|   update_fom_debug_optionsupdate_from_argsset_use_libraries_filterjust_my_code	client_os
set_ide_osr  rW   boolpydevd_file_utilssetup_client_server_pathsset_resolve_symlinksredirect_outputenable_output_redirectionis_output_redirectedset_show_return_valuesshow_return_valuebreak_system_exit_zerodjango_debugflask_debugset_ignore_system_exit_codesr   r   rT   r>   rU   dirnameabspathr   sysrQ   settupleaddget_path_with_real_caseabsolute_pathr   r   setup_auto_reload_watcherstop_on_entryset_gui_event_loopgui_event_loop)#rk   r   argsstart_reasonrY   stepping_resumes_all_threadsterminate_child_processesterminate_keyboard_interruptr'  r   special_presentationfunction_presentationclass_presentationprotected_presentationr[   debug_optionspath_mappingspathMappingr3  r4  resolve_symlinksredirectingignore_system_exit_codesauto_reloadenable_auto_reload
watch_dirsr;  r<  fnew_watch_dirswpoll_target_timeexclude_patternsinclude_patternsr&  s#   ``                                @rK   _set_debug_optionsz,PyDevJsonCommandProcessor._set_debug_optionsH  s   !'+xx0KT'R$11%9UV$(HH-F$M!..u6OP'+xxv'FJ]']$11%9UV $)? F+T2 0w?G#<Y#P $=j'$R!!:7G!L%>{G%T"HH..udhh6S6S$%"&	7  ?JLO 	$$UO<.HHYHH^$
 	..}=&&t,))%1K1KL==""HH 7 7888NB7 	>K#R8I$r:J229jIJRjB&6$$i%<=	> 77F88$5t<'223CDhh34==((++D$7K++E59%0"''t}}/N/NO}}33()4y$}}))T]]-F-F(QC/(HH11%9QRhh|R0+t,NN{\]K(__Xu= __%78
J hhy)G77==)%%g.%%bggoog&>?bggooc233+DGww}}Q'"))!,"))"''//!*<=*tS%&89$J 	EAE""#4#L#LM^MlMlmnMo#pq	E
 $
&??+<a@&??9  7Z  [&??96MN**%z3CEUWg	i ==&&<8+CHH""$##E4==+G+GH  E##$@!DEs   7Y99ZZc                 p   t        t        dg       }t        |      dkD  r|d   }nd}t        |t              r'|j                  t        d      }|j                  d      }t        |t        j                         d|      }t        |      }|j                  j                  t        t        d|d             y )	Nr<  r   r  replacer   T)rH   systemProcessIdisLocalProcessstartMethodr   )r   r[  rG   rP   r   r   r)   encoder   rT   r   r   r   r   r/   r"   )rk   r   start_methodr<  rH   r   events          rK   _send_process_eventz-PyDevJsonCommandProcessor._send_process_event  s    sFB't9q=7DDdE";;3Y?D;;w'DIIK$	
 T"  ,=q%QU!VWrM   c                 x   | j                  ||       d| _        | j                  j                  |d       | j	                  ||j
                  j                  |       t        j                  |      }t               }|j                  j                  t        t        d|d             t        t        d|d      S )NTrf  r   r   )r  r   r{   set_enable_thread_notificationsr}  r   r   r   r   r   r   r   r/   r#   )rk   r   r   rf  r   initialized_events         rK    _handle_launch_or_attach_requestz:PyDevJsonCommandProcessor._handle_launch_or_attach_request  s      5.2+00=w'8'8'?'?l[%44W=,.  J;LVZ![\*a4@@rM   c                 *    | j                  ||d      S )z/
        :param LaunchRequest request:
        r?  r  r  r   s      rK   on_launch_requestz+PyDevJsonCommandProcessor.on_launch_request       44UGRZ4[[rM   c                 *    | j                  ||d      S )z/
        :param AttachRequest request:
        attachr  r  r   s      rK   on_attach_requestz+PyDevJsonCommandProcessor.on_attach_request  r  rM   c                     |j                   }|j                  }| j                  j                  ||       t	        j
                  |      }t        t        d|d      S )z.
        :param PauseRequest request:
        r  r   Tr   )r   threadIdr{   request_suspend_threadr   r   r/   r#   )rk   r   r   r   r  r   s         rK   on_pause_requestz*PyDevJsonCommandProcessor.on_pause_request  sR     %%	&&	'''C%44W=*a4@@rM   c                     j                   }|j                  fd}j                  j                  |       | j                  j                         y)z1
        :param ContinueRequest request:
        c                      ddk(  i} t        j                  d| i      }t        t        d|d      }j                  j                  |       y )NallThreadsContinuedr@   r   r   r   Tr   )r   r   r/   r#   r   r   )r   r   r   r   r   r  s      rK   
on_resumedzAPyDevJsonCommandProcessor.on_continue_request.<locals>.on_resumed  sK    )9+;<D)88&RVXHZHdCCLL$$S)rM   N)r   r  %threads_suspended_single_notificationadd_on_resumed_callbackr{   request_resume_thread)rk   r   r   r   r  r  s    ``  @rK   on_continue_requestz-PyDevJsonCommandProcessor.on_continue_request  sH     %%	&&		* 	33KKJW&&y1rM   c                     |j                   }|j                  }|j                         rt        }nt        }| j
                  j                  |||       t        j                  |      }t        t        d|d      S )z-
        :param NextRequest request:
        r   Tr   )r   r  get_use_libraries_filterr(   r'   r{   request_stepr   r   r/   r#   rk   r   r   r   r  step_cmd_idr   s          rK   on_next_requestz)PyDevJsonCommandProcessor.on_next_request'  sg     %%	&&	))+/K'KeY<%44W=*a4@@rM   c                    |j                   }|j                  }|j                  }|St        |      }|:t	        |j
                  d|j                  d|i       }t        t        d|d      S t        |      }|j                  }	|	s-t        j                  |ddd	      }
t        t        d|
d      S |	j                  |      }||j                  }|>| j                  j!                  ||j
                  ||j"                  |j"                         n| j                  j!                  ||j
                  ||j"                  d
       nmt        j                  |dd|d|	d	      }
t        t        d|
d      S |j%                         rt&        }nt(        }| j                  j+                  |||       t        j                  |      }t        t        d|d      S )z/
        :param StepInRequest request:
        F&Unable to find thread from thread_id: r   r   r   r   r   r   Tr   zEUnable to step into target (no targets are saved in the thread info).r   r   r   r   z Unable to find step into target z. Available targets: )r   r  targetIdr;   r   r   r   r/   r#   r:   $target_id_to_smart_step_into_variantr   r   rS   parentr{   request_smart_step_intooffsetr  r&   r%   r  )rk   r   r   r   r  	target_idthreadr   r   r  r  variantr  r  s                 rK   on_stepin_requestz+PyDevJsonCommandProcessor.on_stepin_request8  s    %%	&&	&&	 -i8F~# '!#OOJSU "*a4HH-f5D373\3\07%7%F%F#(#j&" "*a1CTRR:>>yIG" %HH44UGKKTZTaTacjcqcqrHH44UGKKT[TbTbdfg%7%F%F#(%'K$M&" "*a1CTRR --/3+HH!!%K@%44W=*a4@@rM   c           	      .   |j                   j                  }|j                  j                  |      }|9t	        g       }t        j                  ||ddd      }t        t        d|d      S |j                  |t        |j                  |||t               y)	z6
        :param StepInTargetsRequest request:
        NFzdUnable to get thread_id from frame_id (thread to get step in targets seems to have resumed already).r  r   r   Tr   )r   r  r	  r
  r   r   r   r/   r#   post_method_as_internal_commandr9   r   r:   )rk   r   r   r  r  r   r  s          rK   on_stepintargets_requestz2PyDevJsonCommandProcessor.on_stepintargets_requests  s     $$,,22WW	 ,R0D!3!B!B $  F" j!-?NN--8'++yRZ\ce	ArM   c                     |j                   }|j                  }|j                         rt        }nt        }| j
                  j                  |||       t        j                  |      }t        t        d|d      S )z0
        :param StepOutRequest request:
        r   Tr   )r   r  r  r*   r+   r{   r  r   r   r/   r#   r  s          rK   on_stepout_requestz,PyDevJsonCommandProcessor.on_stepout_request  sg     %%	&&	))+1K)KeY<%44W=*a4@@rM   c                 P   |sy|j                         }	 t        |       dj                  |      S # t        $ r Y nw xY w|j	                  d      rdj                  |      S |j	                  d      s"|j	                  d      s|j	                  d      rdj                  |      S |S )	a3  Following hit condition values are supported

        * x or == x when breakpoint is hit x times
        * >= x when breakpoint is hit more than or equal to x times
        * % x when breakpoint is hit multiple of x times

        Returns '@HIT@ == x' where @HIT@ will be replaced by number of hits
        Nz@HIT@ == {}%z@HIT@ {} == 0z==><z@HIT@ {})stripintformat
ValueErrorr   )rk   hit_conditionexprs      rK   _get_hit_condition_expressionz7PyDevJsonCommandProcessor._get_hit_condition_expression  s     ""$	I ''-- 		 ??3"))$//??4 OOC OOC $$T**s   1 	==c                 \   |j                   j                  r9| j                  |       t        j                  |      }t        t        d|d      S d| _        |j                  dd       | j                  j                  |d       t        j                  |      }t        t        d|d      S )z3
        :param DisconnectRequest request:
        r   Tr   F)resume_threads)r   terminateDebuggeer   r   r   r/   r#   r   rQ  r{   request_disconnectr   s       rK   on_disconnect_requestz/PyDevJsonCommandProcessor.on_disconnect_request  s     ..++E2)88AHj!XtDD.3+''u5##E$#?%44W=*a4@@rM   c                     | j                   sT|j                  dk(  rt        g       }nt        g       }t	        j
                  ||ddd      }t        t        d|d      S y )	NsetFunctionBreakpointsFzABreakpoints may only be set after the launch request is received.r  r   r   Tr   )r   r   r   r   r   r   r/   r#   )rk   r   r   r   s       rK   _verify_launch_or_attach_donez7PyDevJsonCommandProcessor._verify_launch_or_attach_done  sg    22 "::9"=1"5)88 $bH j!XtDD 3rM   c                 <   | j                  |      }||S |j                  }g }d}d}d}g }	|j                  D ]  }
| j                  |
j	                  d            }|
j	                  d      }|j                  t        |
d   |||||             |	j                  t        j                  d| j                               j                                 | j                  j                  ||       d	|	i}t        j                  |d
|i      }t        t         d|d      S )z?
        :param SetFunctionBreakpointsRequest request:
        NALLFhitCondition	conditionrH   T)verifiedidbreakpointsr   r   r   r   )r  r   r  r  rS   rW   r!   r   
Breakpointr}   r   r{   set_function_breakpointsr   r   r/   r#   )rk   r   r   r   r   function_breakpointssuspend_policyis_logpoint
expressionbreakpoints_setbpr  r  r   set_breakpoints_responses                  rK   !on_setfunctionbreakpoints_requestz;PyDevJsonCommandProcessor.on_setfunctionbreakpoints_request  s,    55g>O%%	! 
'' 		MB >>rvvn?UVM{+I ''"2f:y*nVcepqs ""=#;#;!d&>&>&@$BBI')M		M 	))%1EF/#5#D#DWV\^bUc#d *a)A4PPrM   c                    | j                  |      }||S |j                  }| j                  j                  |j                  j
                        }d}| j                  j                  ||       d}d}|j                         j                  d      s1| j                  j                  rd}n| j                  j                  rd}g }	|j                  D ]  }
t        di |
}
|
j                  }|
j                  }| j!                         }| j#                  |
j$                        }|
j&                  }|sd}d}nd}t)        |      }t+        | j,                  ||j                        }| j                  j/                  |||||||||||d|	      }| j1                  ||j                  ||      }|	j3                  |        d
|	i}t5        j6                  |d|i      }t9        t:        d|d      S )z7
        :param SetBreakpointsRequest request:
        NNonezpython-liner  z.pyzdjango-linezjinja2-lineT)adjust_lineon_changed_breakpoint_stater  r   r   r   r   rv   )r  r   r{   filename_to_strsourcer>   remove_all_breakpointsr   rV   r|   rV  rW  r  r   r  r  r}   r  r  
logMessager0   r   _on_changed_breakpoint_stateadd_breakpoint-_create_breakpoint_from_add_breakpoint_resultrW   r   r   r/   r#   )rk   r   r   r   r   filename	func_namebtyper  r  source_breakpointr  r  breakpoint_idr  log_messager  r  r  resultr  r   r  s                          rK   on_setbreakpoints_requestz3PyDevJsonCommandProcessor.on_setbreakpoints_request  s    55g>O%%	88++I,<,<,A,AB	''x8~~((/}}))%**%!*!6!6 	' 0 E3D E$))D)33I 446M >>?P?]?]^M+66K"!
"B;O
*1$2S2SUZ\e\l\l*m'XX,,xtY	S]{  kF - GF CCE9K[K[]jlrsB""2&+	'. /#5#D#DWV\^bUc#d *a)A4PPrM   c                     | j                  ||||      }t        d|      }t        |      }d}|j                  j	                  t        |d|d             y )Nchanged)reason
breakpointr   Tr   )r  r   r   r   r   r/   )	rk   r   r  r  r  r  r   r  event_ids	            rK   r  z6PyDevJsonCommandProcessor._on_changed_breakpoint_state/  sW    ??v}^de"
  %  Ha!MNrM   c                    |j                   }|r|| j                  j                  k(  rd}nk|| j                  j                  k(  rd}|j	                         r@|dz  }n:|| j                  j
                  k(  rd}n|| j                  j                  k(  rd}nd}t        j                  d||j                  ||      j                         S t        j                  d	||j                  |
      j                         S )Nz'Breakpoint in file that does not exist.z'Breakpoint in file excluded by filters.z
Note: may be excluded because of "justMyCode" option (default == true).Try setting "justMyCode": false in the debug configuration (e.g., launch.json).
z3Waiting for code to be loaded to verify breakpoint.z!Breakpoint added to invalid line.zBBreakpoint not validated (reason unknown -- please report as bug).F)r  r  r  r   r  T)r  r  r  r  )
error_coder{   ADD_BREAKPOINT_FILE_NOT_FOUND'ADD_BREAKPOINT_FILE_EXCLUDED_BY_FILTERSr  ADD_BREAKPOINT_LAZY_VALIDATIONADD_BREAKPOINT_INVALID_LINEr   r  translated_liner   )rk   r   r  r  r  r  r   s          rK   r  zGPyDevJsonCommandProcessor._create_breakpoint_from_add_breakpoint_result9  s    &&
TXXCCCE	txxOOOE	113 #x yI txxFFFQ	txxCCC?	 a	 ++=v7M7MW`ioqqxqxqz{ !++-f6L6LU[]]d]d]fgrM   c                 R   |j                   }|j                  }|j                  }| j                  j	                  |       d}d}d}|j                         rdnd}	|rd}
d}|D ]  }t        di |}|j                  s|j                  dk(  rdnd}|j                  dk(  rdnd}|j                  dk(  rdnd}|j                  }|
|z  }
||z  }g }t        |      dk(  r{t        |      dk(  rd|d   d	   v rAd
g}n=t        |      }dt        |      d	   v r"|D ]  }|d	   D ]  }|j                  |         |D ]%  }| j                  j                  |||||||||		       '  nId|v }
d|v }d|v }|
s|s|r7|
rdnd}|rdnd}|rdnd}d
}| j                  j                  |||||||||		       |
rRd}| j                  j                  rd}n| j                  j                   rd}|r| j                  j#                  ||d
       t%        j&                  |      }t)        t*        d|d      S )z@
        :param SetExceptionBreakpointsRequest request:
        NFr   r   always	unhandledr   zPython ExceptionsnamesBaseExceptionr   r   djangojinja2Tr   rv   )r   filtersexceptionOptionsr{    remove_all_exception_breakpointsr  r	   r>   	breakModerG   iterrg   rW   add_python_exception_breakpointr|   rV  rW   add_plugins_exception_breakpointr   r   r/   r#   )rk   r   r   r   r  exception_optionsr  r  notify_on_first_raise_onlyignore_librariesbreak_raisedbreak_uncaughtoptionnotify_on_handled_exceptionsnotify_on_unhandled_exceptions#notify_on_user_unhandled_exceptionsexception_pathsexception_namespath_iteratorr>   ex_nameexception_name
break_userr   r  r  s                             rK   "on_setexceptionbreakpoints_requestz<PyDevJsonCommandProcessor.on_setexceptionbreakpoints_requestV  s   
 %%	##%6611%8 	
%*" % > > @1a L"N+ .)3F3{{ 5;4D4D4PqVW,6<6F6F+6U[\.;A;K;K;^ade3"(++ <<"@@"$'1,)Q.*oa.@.II+:*; %)$9M*d=.A'.JJ$1 @D+/= @ / 6 6w ?@@ '6 NHH<<&!"46;2(
G.b $w.L'72N(G3J~4@qa,6D!.;Ea13+	88027.$
 E}})) ** 995/3 $6#D#DW#M *a)A4PPrM   c                 j   |j                   }|j                  }|j                  rt        |j                        }nd}|j                  rt        |j                        }nd}|j
                  }t        |d      r|j                         }| j                  j                  ||j                  ||||       y)z3
        :param StackTraceRequest request:
        r   r   )fmtstart_framelevelsN)r   r  
startFramer  r  r  hasattrr   r{   request_stackr   )rk   r   r   stack_trace_argumentsr  r  r  r  s           rK   on_stacktrace_requestz/PyDevJsonCommandProcessor.on_stacktrace_request  s    
 !( 1 1)22	 ++3>>?KK ''.556FF#**3	"++-Cugkk9#S^gmnrM   c                 ,   |j                   }|j                  }| j                  j                  }t	        |      }| | j
                  j                  |||||       yt        |j                  d|j                  d|i       }t        t        d|d      S )z6
        :param ExceptionInfoRequest request:
        NFr  r  r   Tr   )r   r  r|   max_exception_stack_framesr;   r{   request_exception_info_jsonr   r   r   r/   r#   )rk   r   r   exception_into_argumentsr  
max_framesr  r   s           rK   on_exceptioninfo_requestz2PyDevJsonCommandProcessor.on_exceptioninfo_request  s    
 $+#4#4 ,55	]]==
))4HH00FT^_#KKFOQH j!XtDDrM   c           	      $   |j                   j                  }|}t        dt        t	        |      d      dd      t        dt        t	        |      d      d      g}t        |      }t        j                  |d|i      }t        t        d	|d
      S )z
        Scopes are the top-level items which appear for a frame (so, we receive the frame id
        and provide the scopes it has).

        :param ScopesRequest request:
        LocalslocalsF)presentationHintGlobalsglobalsr   r   r   Tr   )
r   r  r   r1   r  r   r   r   r/   r#   )rk   r   r   r  variables_referencescopesr   scopes_responses           rK   on_scopes_requestz+PyDevJsonCommandProcessor.on_scopes_request  s     $$,,&(L-@)A8Lefno)\#.A*BINPUV
 "&),;;GVUYN[*a$GGrM   c                 n   |j                   }|j                  | j                  j                  ||d       y|j                  j                  |j                        }|| j                  j                  |||       yt        dd      }t        j                  ||ddd	      }t        t        d|d
      S )z1
        :param EvaluateRequest request:
        Nr@   r  r  r   Fz%Unable to find thread for evaluation.r  r   Tr   )r   r  r{   request_exec_or_evaluate_jsonr	  r
  r   r   r   r/   r#   rk   r   r   r   r  r   r   s          rK   on_evaluate_requestz-PyDevJsonCommandProcessor.on_evaluate_request  s    
 %%	$HH225'S2Q66[[!!#I $667I/ ,B2-<< $#(#J "*a4HHrM   c                    |j                   }|j                  j                  |j                        }|| j                  j                  |||       y t        d      }t        j                  ||ddd      }t        t        d|d      S )	Nr  Fz(Unable to find thread to set expression.r  r   r   Tr   )r   r	  r
  r  r{   request_set_expression_jsonr   r   r   r/   r#   r4  s          rK   on_setexpression_requestz2PyDevJsonCommandProcessor.on_setexpression_request  s    %%	22WW	  HH00K,R0D)88 $IH j!XtDDrM   c                 V   |j                   }|j                  }t        |t              r|j                  }|j
                  j                  |      }|| j                  j                  |||       yg }t        |      }t        j                  ||ddd      }t        t        d|d      S )	a  
        Variables can be asked whenever some place returned a variables reference (so, it
        can be a scope gotten from on_scopes_request, the result of some evaluation, etc.).

        Note that in the DAP the variables reference requires a unique int... the way this works for
        pydevd is that an instance is generated for that specific variable reference and we use its
        id(instance) to identify it to make sure all items are unique (and the actual {id->instance}
        is added to a dict which is only valid while the thread is suspended and later cleared when
        the related thread resumes execution).

        see: SuspendedFramesManager

        :param VariablesRequest request:
        NF5Unable to find thread to evaluate variable reference.r  r   r   Tr   )r   variablesReferencerP   r1   variable_referencer	  r
  r{   request_get_variable_jsonr   r   r   r/   r#   )	rk   r   r   r   r.  r  	variablesr   r  s	            rK   on_variables_requestz.PyDevJsonCommandProcessor.on_variables_request-  s     %%	'::)<8"5"H"H22WW!	 HH..ugyII(3D!3!B!B7 RT "
 j!-?NNrM   c                    |j                   }|j                  }t        |t              r|j                  }|j
                  j                  d      r7t        j                  |t        d      ddd      }t        t        d|d	      S |j                  j                  |      }|| j                  j                  |||       y t        j                  |t        d      dd
d      }t        t        d|d	      S )Nz	(return) r  FzCannot change return valuer  r   r   Tr   r:  )r   r;  rP   r1   r<  rH   r   r   r   r   r/   r#   r	  r
  r{   request_change_variable_json)rk   r   r   r   r.  r   r  s          rK   on_setvariable_requestz0PyDevJsonCommandProcessor.on_setvariable_requestP  s    %%	'::)<8"5"H"H>>$$[1)883B7$;H j!XtDD22WW!	  HH11%)L)883B7$VH j!XtDDrM   c                     |j                   j                  }|j                         }t        |      }t	        j
                  |d|i      }t        t        d|d      S )Nr   r   r   Tr   )cmd_factorymodules_managerget_modules_infor   r   r   r/   r#   )rk   r   r   rE  modules_infor   r  s          rK   on_modules_requestz,PyDevJsonCommandProcessor.on_modules_requestp  sV    ++;;&779"<0/>>wPVX\~^*a);TJJrM   c                 l   |j                   j                  }dd}|dk7  rt        j                  |      st        j                  |      ru	 t        d      5 }|j                         }ddd       |Mfdt        j                  d      D        }t        j                  t        |      }dj                  |      xs d}|Kt        j                  |      }t        j                  d||       |	 | j                  j!                  ||      }t'        |xs d      }d	|i}	|*|dk(  rd
}
nrd}
nd|fz  }
|	j)                  d|
d       t+        j,                  ||	      }t/        t0        d|d      S # 1 sw Y   xY w#  Y xY w# t"        $ r t        j$                  d|       d}Y w xY w)z/
        :param SourceRequest request:
        Nr   rc              3   J   K   | ]  }t        j                  |        y wrE   )	linecachegetline).0iserver_filenames     rK   	<genexpr>z>PyDevJsonCommandProcessor.on_source_request.<locals>.<genexpr>  s     _qY..B_s    #r   r  z+Found frame id: %s for source reference: %sz%Error getting source for frame id: %sr   zSource unavailablezUnable to retrieve source for zInvalid sourceReference %dFr  r   Tr   )r   sourceReferencerM  )get_server_filename_from_source_reference,get_source_reference_filename_from_linecacheopenreadrh   ri   	takewhilerL  join"get_frame_id_from_source_referencer   debugr{   #get_decompiled_source_from_frame_idr   r   r   updater   r   r/   r#   )rk   r   r   source_referencecontentstreamlinesr  r   response_argsr   r   rP  s               @rK   on_source_requestz+PyDevJsonCommandProcessor.on_source_requestw  s    #,,<<q /YYZjkO""3"`"`aq"ros3 0v"(++-0
 ? `IOO\]L^_E%//e<E !ggen4G,OOP`a MxYij''"&(("N"NuV^"_
 "'-R0?1$. @OQ6:J9LL  Uw!GH%44W]S*a4@@O0 0& % '!++,SU]^"&'s6   F E:-F 5F :F?F F!F32F3c                 4   |j                   j                  j                  }|j                   j                  }| j                  j                  ||f      }||d||d}t        |g      }d|i}t        j                  ||      }	t        t        d|	d      S )	N:)r  r   r  )targetsr   r   r   Tr   )r   r  r>   r  r~   rr   r
   r   r   r/   r#   )
rk   r   r   r>   r  r  targetr   ra  r   s
             rK   on_gototargets_requestz0PyDevJsonCommandProcessor.on_gototargets_request  s      '',,  %%**55tTlC	 $d+

 'x8%44W]S*a4@@rM   c           	         t        |j                  j                        }|j                  j                  }	 | j                  j                  |      \  }}| j                  j                  ||j                  |t        ||d       y # t        $ r5 t        j                  |i dd|fz  d      }t        t        d|d      cY S w xY w)	NFzUnknown goto target id: %dr  r   r   Tr   r@   )r  r   r  r  r~   rn   rp   r   r   r/   r#   r{   request_set_nextr   r$   )rk   r   r   r  r  r>   r  r   s           rK   on_goto_requestz)PyDevJsonCommandProcessor.on_goto_request  s    ))223	%%..	
	E//<<YGJD$ 	!!%iAWY]_cehi  	E)88$;ylJH j!XtDD	Es   B ;CCc                    |j                   }|j                  %| j                  j                  |j                         |j                  S|j
                  Gt        |j                        }t        |j
                        }| j                  j                  |||       |j                  !t        d |j                  D              |_	        |j                  !t        d |j                  D              |_        |j                  |j                  |_        t        j                  |di i      }t!        t"        d|d      S )Nc              3   2   K   | ]  }t        |        y wrE   r    rN  xs     rK   rQ  zKPyDevJsonCommandProcessor.on_setdebuggerproperty_request.<locals>.<genexpr>  s      ?W+,#A&?W   c              3   2   K   | ]  }t        |        y wrE   rm  rn  s     rK   rQ  zKPyDevJsonCommandProcessor.on_setdebuggerproperty_request.<locals>.<genexpr>  s      :S+,#A&:Srp  r   r   r   Tr   )r   ideOSr{   rK  dontTraceStartPatternsdontTraceEndPatternsr]  !set_dont_trace_start_end_patterns skipSuspendOnBreakpointException$skip_suspend_on_breakpoint_exceptionskipPrintBreakpointExceptionskip_print_breakpoint_exceptionmultiThreadsSingleNotification!multi_threads_single_notificationr   r   r/   r#   )rk   r   r   re  start_patternsend_patternsr   s          rK   on_setdebuggerproperty_requestz8PyDevJsonCommandProcessor.on_setdebuggerproperty_request  s     ::!HH

+&&2t7P7P7\"4#>#>?N !:!:;LHH66unl[00<9> ?W040U0U?W :WE6 ,,849 :S040Q0Q:S 5SE1 ..:6:6Y6YE3 &44Wfb\R*a4@@rM   c                    	 t        j                         }|j                         xs | j                  j                         }	 t        j                         }t        j                  t        t        j                  t        t        |            }t        j                  t        j                        }t        j                   ||t        j"                  t$        rdnd      }t        j&                  t(        t*              }	||||	d}
t-        j.                  |d	|
i
      }t1        t2        d|d      S # t        $ r d }Y -w xY w# t        $ r
 t        }Y w xY w)N)rH   versiondescription)r  implementation)rH   @       )pidppid
executablebitness)usingCythonusingFrameEval)pythonplatformprocessr   r   r   r   Tr   )rT   r   AttributeErrorget_arg_ppidr{   get_ppidr  python_implementationr2   r   PydevdPythonInfor4   PydevdPythonImplementationInfor5   PydevdPlatformInfor[  PydevdProcessInfor  r6   
PydevdInfor7   r8   r   r   r/   r#   )rk   r   r   r  r  	impl_descpy_infoplatform_infoprocess_infor   r   r   s               rK   on_pydevdsysteminfo_requestz5PyDevJsonCommandProcessor.on_pydevdsysteminfo_request  s/   	))+C !!#:txx'8'8':	% 668I  00"(GG!+%
 &88cllK$66~~*B	
 $..$+

 %#!	
 &44Wfd^T*a4@@S  	C	  	%$I	%s#   D5 E 5EEEEc                    |j                   }| j                  j                  }|j                  j                  }|j
                  }|D cg c]5  } ||d   |d   |d   | j                  j                  |d   d               7 }}| j                  j                  |||      }	|	r.t        j                  |i d|	d      }
t        t        d	|
d
      S t        j                  |      }
t        t        d	|
d
      S c c}w )Nr  endLineruntimeLineruntimeSourcer>   Fr  r   r   Tr   )r   r{   SourceMappingEntryr  r>   pydevdSourceMapsr  set_source_mappingr   r   r/   r#   )rk   r   r   re  r  r>   source_maps
source_mapnew_mappingsr   r   s              rK   on_setpydevdsourcemap_requestz7PyDevJsonCommandProcessor.on_setpydevdsourcemap_request   s     !XX88{{++ !,
  6"9%=)((O)DV)LM	
 
 HH//t\J	)88$(H j!XtDD%44W=*a4@@+
s   	:C:N)T).rs   rt   ru   rl   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  r!  r'  r1  r5  r8  r?  rB  rH  rb  rg  rj  r~  r  r  rv   rM   rK   rx   rx   v   s   4C.JA2AhT9A2fBRIhX(	A\\
A2(A"9AvA,A":A E" QD3QjOg:hQTo.E*H$I6E(!OFE@K7ArA&AB,A\ArM   rx   )Urh   r   rL  rT   r  r[  	functoolsr   rM  _pydev_bundler   _pydevd_bundle._debug_adapterr   r   +_pydevd_bundle._debug_adapter.pydevd_schemar   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _pydevd_bundle.pydevd_apir   !_pydevd_bundle.pydevd_breakpointsr    r!   $_pydevd_bundle.pydevd_comm_constantsr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   _pydevd_bundle.pydevd_filteringr,   (_pydevd_bundle.pydevd_json_debug_optionsr-   r.   !_pydevd_bundle.pydevd_net_commandr/   _pydevd_bundle.pydevd_utilsr0   r1   _pydevd_bundle.pydevd_constantsr2   r3   r4   r5   r6   $_pydevd_bundle.pydevd_trace_dispatchr7   )_pydevd_frame_eval.pydevd_frame_eval_mainr8   _pydevd_bundle.pydevd_commr9   ,_pydevd_bundle.pydevd_additional_thread_infor:   &_pydevd_bundle.pydevd_thread_lifecycler;   ra   objectrc   rx   rv   rM   rK   <module>r     s       	  
   # K+ + + + + + + 0 U. . . : Y 8 [+ + = F H S K7tF (FA FArM   