
    "eM3                     *   d dl mZmZmZ d dlmZ d dlZd dlmZm	Z	  G d de
      Z G d de
      Zd	 Zd
 ZddgZd Zd Zd Z G d d      ZdZdZdZdedefdZdefdZ G d de
      Z G d de
      ZdZdZd  Zerd! Z d" Z!nd# Z!d&d$Z"d% Z#y)'    )EXCEPTION_TYPE_USER_UNHANDLEDEXCEPTION_TYPE_UNHANDLEDIS_PY311_OR_GREATER)	pydev_logN)AnyDictc                       e Zd Z	 	 ddZy)FrameNc                     || _         || _        || _        || _        || _        || _        | j                  i | _        y y N)f_backf_linenof_codef_locals	f_globalsf_trace)selfr   f_filenor   r   r   r   s          C/usr/lib/python3/dist-packages/_pydevd_bundle/pydevd_frame_utils.py__init__zFrame.__init__
   sD       ">>!DN "    )NN__name__
__module____qualname__r    r   r   r
   r
      s      r   r
   c                       e Zd Zd Zy)FCodec                 <    || _         || _        d| _        d| _        y )N   r   )co_nameco_filenameco_firstlinenoco_flags)r   namefilenames      r   r   zFCode.__init__   s     #r   Nr   r   r   r   r   r      s    r   r   c                 "    || j                   d<   y N__exception__)r   )frameexception_infos     r   add_exception_to_framer,   &   s    &4ENN?#r   c                 <    | j                   j                  dd        y r(   )r   pop)r*   s    r   remove_exception_from_framer/   *   s    	NN-r   zpydev_monkey_qt.pyzpydev_import_hook.pyc                 $    | y| j                   d u S )NF)tb_next)traces    r   just_raisedr3   1   s    }==D  r   c                     | R| j                   j                  j                  }|dv ryt        D ]  }|j	                  |      s y | j
                  } | Ry)N)z<frozen importlib._bootstrap>z&<frozen importlib._bootstrap_external>TF)tb_framer   r"   FILES_WITH_IMPORT_HOOKSendswithr1   )r2   r&   files      r   ignore_exception_tracer9   7   sk    

>>((44 W W  , 	D  &	  
 r   c                 p    d|j                   z   }t        | |      st        | | ||        t        | |      S )N_cached_)r   hasattrsetattrgetattr)objfuncargscached_names       r   cached_callrC   I   s7    t}},K3$[$+.3$$r   c                       e Zd Zd ZdefdZy)_LineColInfoc                 <    || _         || _        || _        || _        y r   )lineno
end_linenocolno	end_colno)r   rG   rH   rI   rJ   s        r   r   z_LineColInfo.__init__S   s    $
"r   original_linec                 T   t        || j                        }t        || j                        }| j                  | j                  k(  rN	 t        |||       }|8t        ||d   | j                  z         t        ||d   | j                  z         fS 	 ||fS ||fS # t        $ r Y ||fS w xY w)a  
        The columns internally are actually based on bytes.

        Also, the position isn't always the ideal one as the start may not be
        what we want (if the user has many subscripts in the line the start
        will always be the same and only the end would change).
        For more details see:
        https://github.com/microsoft/debugpy/issues/1099#issuecomment-1303403995

        So, this function maps the start/end columns to the position to be shown in the editor.
        r   r    )%_utf8_byte_offset_to_character_offsetrI   rJ   rG   rH   1_extract_caret_anchors_in_bytes_from_line_segment	Exception)r   rK   rI   rJ   rets        r   map_columns_to_linez _LineColInfo.map_columns_to_lineY   s     6mTZZP9-X	;;$//)
G!%	2 ?=mSQRVVZV`V`M`a=mSQRVVZV`V`M`a  # iui  is   AB 	B'&B'N)r   r   r   r   strrQ   r   r   r   rE   rE   Q   s    #   r   rE      i   i   soffsetc                     d}d}t        |       D ]I  \  }}|dz  }t        |      }|t        k\  r|dz  }n|t        k\  r|dz  }n|t        k\  r|dz  }||kD  sH |S  |dz  }|S )Nr   r          )	enumerateord_utf8_with_4_bytes_utf8_with_3_bytes_utf8_with_2_bytes)rT   rU   byte_offsetchar_offset	character	codepoints         r   rM   rM   }   s    KK"+A, Yq	N	**1K,,1K,,1K '" 	qr   segmentc                    dd l }	 | j                  d      } 	 |j                  |       }t        |j                        dk7  ry |j                  d   }t        ||j                        r|j                  }t        ||j                        r| |j                  j                  |j                  j                   }t        |      t        |j                               z
  }|j                  j                  |z   }|dz   }|dz   t        |      k  r||dz      t!        d      k(  s|dz  }||fS t        ||j"                        r/|j                  j                  |j$                  j                  dz   fS y # t        $ r Y y w xY w# t        $ r Y y w xY w)Nr   zutf-8r        )astencodeUnicodeEncodeErrorparseSyntaxErrorlenbody
isinstanceExprvalueBinOpleftend_col_offsetright
col_offsetlstriprZ   	Subscriptslice)	rb   re   tree	statementexproperator_stroperator_offsetleft_anchorright_anchors	            r   rN   rN      se   ..)yy! 499~		!I)SXX&dCII&"499#;#;DJJ<Q<QRL!,/#l6I6I6K2LLO))22_DK&?L!#c,&77$_q%89SYF!,,dCMM*::,,djj.G.G!.KKK9    s"   E. E= .	E:9E:=	F	F	c                   4    e Zd Zd Zd Zd Zd Zd Zd ZeZ	y)
FramesListc                     g | _         i | _        i | _        d | _        d | _        d | _        d | _        d| _        d | _        y )N )	_framesframe_id_to_linenoframe_id_to_line_col_infoexc_typeexc_desc	trace_objcurrent_frameexc_context_msgchained_frames_listr   s    r   r   zFramesList.__init__   sL    
 #%BD&
 "  "#' r   c                 :    | j                   j                  |       y r   )r   append)r   r*   s     r   r   zFramesList.append   s    E"r   c                      | j                   d   S )N)r   r   s    r   
last_framezFramesList.last_frame   s    ||Br   c                 ,    t        | j                        S r   )rj   r   r   s    r   __len__zFramesList.__len__   s    4<<  r   c                 ,    t        | j                        S r   )iterr   r   s    r   __iter__zFramesList.__iter__   s    DLL!!r   c                    dg}|j                  d       |j                  t        | j                               |j                  d       |j                  t        | j                               |j                  d       |j                  t        | j                               |j                  d       |j                  t        | j
                               | j                  D ]>  }|j                  d       |j                  t        |             |j                  d       @ | j                  5|j                  d       |j                  t        | j                               |j                  d	       d
j                  |      S )NzFramesList(z
    exc_type: z
    exc_desc: z
    trace_obj: z
    current_frame: z
    ,z
--- Chained ---
z
)r   )
r   rR   r   r   r   r   r   reprr   join)r   lstr*   s      r   __repr__zFramesList.__repr__   s   o

%&

3t}}%&

%&

3t}}%&

&'

3t~~&'

*+

3t))*+\\ 	EJJx JJtE{#JJsO	
 ##/JJ,-JJs43345

5wws|r   N)
r   r   r   r   r   r   r   r   r   __str__r   r   r   r   r      s'    (.# !"8 Gr   r   c                   <    e Zd Zd Zed        Zed        Zd ZeZy)_DummyFrameWrapperc                     || _         || _        || _        d | _        |j                  }|j
                  }t        ||j                        | _        y r   )_base_framer   r   r   r   r!   r   r"   )r   r*   r   r   original_coder%   s         r   r   z_DummyFrameWrapper.__init__  sG      $$D-";";<r   c                 .    | j                   j                  S r   )r   r   r   s    r   r   z_DummyFrameWrapper.f_locals  s    (((r   c                 .    | j                   j                  S r   )r   r   r   s    r   r   z_DummyFrameWrapper.f_globals  s    )))r   c                 |    d| j                   j                  d| j                  d| j                   j                  S )Nz<_DummyFrameWrapper, file 'z', line z, )r   r"   r   r!   r   s    r   r   z_DummyFrameWrapper.__str__  s-    @D@W@WY]YfYfhlhshsh{h{||r   N)	r   r   r   r   propertyr   r   r   r   r   r   r   r   r      s<    = ) ) * *} Hr   r   zG
The above exception was the direct cause of the following exception:

zF
During handling of the above exception, another exception occurred:

c                    g }d}	 t        |dd       }t        }|	 t        |dd       }t        }|t	        |      |v ry |j                  t	        |             |j                  }t               }	t        |      |	_	        ||	_
        ||	_        ||	_        |U|j                  t        |j                  |j                   d       |j                   t#        |      f       |j$                  }|U|D ]G  \  }
}}|	j                  |
       ||	j&                  t	        |
      <   ||	j(                  t	        |
      <   I |	S # t        $ r d }Y .w xY w# t        $ r d }Y *w xY w)Nz<Unknown context>	__cause____context__)r>   _cause_messagerO   _context_messageidadd__traceback__r   typer   r   r   r   r   r   r5   	tb_lineno_get_line_col_info_from_tbr1   r   r   )r   r*   r   r   memor   msg	exc_causetbframes_listr5   r   line_col_infos                r   'create_frames_list_from_exception_causer   "  sm   
C
CHk48	 	->I"C ByMT1 	HHR	]		 	 B,K	?K$KK"%K
. 	

&r{{BLL$GWqrtWuvwZZ . /2 L*)]8$7@&&r(|4>K--bl;L
 G  	  	I	s"   D9 E 9EEEEc                 t    |dk  ry| j                         }t        t        j                  ||dz  d             S )Nr   )NNNNrX   )co_positionsnext	itertoolsislice)codeinstruction_indexpositions_gens      r   _get_code_positionr   P  s;    q +))+I$$]4E4JDQRRr   c                     t        | j                  j                  | j                        }|d   t	        | j
                  g|dd   S t	        | S )Nr   r    )r   r5   r   tb_lastirE   r   )r   	positionss     r   r   r   W  sK    &r{{'9'92;;G	Q<=y}==++r   c                      y r   r   )r   s    r   r   r   `  s    r   c                    g }| }|R|j                   F|j                   j                  }|.|j                  d||j                  df       |j                  }|.|@|j	                  |j                   |j
                  t        |      f       |j                  }|@d}t        |      D ]e  \  }	}
}|||	u s|	|t        k(  r
t               }|%|j	                  |	       |
|j                  t        |	      <   ||j                  t        |	      <   g |"| t        j                  d       t!        |      }||_        ||_        | |_        |t        k(  r||_        n,|t*        k(  r#t-        |      dkD  r|j/                         |_        |}t1               }|j3                  t        |             	 t5        ddd|j$                  |      }|	 |S ||_        |}()a  
    :param trace_obj:
        This is the traceback from which the list should be created.

    :param frame:
        This is the first frame to be considered (i.e.: topmost frame). If None is passed, all
        the frames from the traceback are shown (so, None should be passed for unhandled exceptions).

    :param exception_type:
        If this is an unhandled exception or user unhandled exception, we'll not trim the stack to create from the passed
        frame, rather, we'll just mark the frame in the frames list.
    Nr   zEcreate_frames_list_from_traceback did not find topmost frame in list.)r5   r   insertr   r   r   r   r1   reversedr   r   r   r   r   r   infocreate_frames_list_from_framer   r   r   r   r   rj   r   setr   r   r   )r   r*   r   r   exception_typer   r   fr   r5   r   r   currr   chaineds                  r   !create_frames_list_from_tracebackr   e  s    C	B	~"++1KKmJJq1ajj$/0A m .

BKK/I"/MNOZZ . K.6sm P*)]("#@@$,K"x(;DK**2h<8BOK11"X,?P u0^_3E:#K#K%K66$)!	3	3{a(3(>(>(@K%D5DHHR\
9$dDMM[_`?
  (/D$D r   c                 ^    t               }|  |j                  |        | j                  } |  |S r   )r   r   r   )r*   r   s     r   r   r     s3    
,C



5 
 Jr   r   )$_pydevd_bundle.pydevd_constantsr   r   r   _pydev_bundler   r   typingr   r   objectr
   r   r,   r/   r6   r3   r9   rC   rE   r]   r\   r[   rR   intrM   rN   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s     #   F  *F 5. 01GH !$%$  $ N    S # 6!s !HA AH 4& 
& 
)X S,
DNr   