
    ViT)                        S r SSKrSSKr \  SSKJr   SSK
Jr  \" SS9r/ SQrSS jrSS	 jr\" 5       rS
\l        S
\l        \R                  rS0 \4S jr\SSS4S jr\S:X  a/  \" 0 5      rS\S'   \R4                    SSKr\R8                  " 5         gg! \ a    \\4rSSK	Jr   Nf = f! \ a
    \" 5       r Nf = f)z
A small set of utilities useful for debugging misbehaving
applications. Currently this focuses on ways to use :mod:`pdb`, the
built-in Python debugger.
    N)Repr)make_sentinel_UNSET)var_name)pdb_on_signalpdb_on_exception
wrap_tracec                    ^ ^^^ SSK mSSKmT (       d  TR                  m TR                  T 5      mUUUU 4S jnTR                  T U5        g)a  Installs a signal handler for *signalnum*, which defaults to
``SIGINT``, or keyboard interrupt/ctrl-c. This signal handler
launches a :mod:`pdb` breakpoint. Results vary in concurrent
systems, but this technique can be useful for debugging infinite
loops, or easily getting into deep call stacks.

Args:
    signalnum (int): The signal number of the signal to handle
        with pdb. Defaults to :mod:`signal.SIGINT`, see
        :mod:`signal` for more information.
r   Nc                 b   > TR                  TT5        TR                  " 5         [        T5        g N)signal	set_tracer   )sigframeold_handlerpdbr   	signalnums     e/home/james-whalen/.local/share/pipx/venvs/semgrep/lib/python3.13/site-packages/boltons/debugutils.pypdb_int_handler&pdb_on_signal.<locals>.pdb_int_handlerM   s"    i-i     )r   r   SIGINT	getsignal)r   r   r   r   r   s   ` @@@r   r   r   :   sD     MM	""9-K! !
 MM)_-
r   c                 >   ^ ^^ SSK mSSKnSSKmU UU4S jnX!l        g)a  Installs a handler which, instead of exiting, attaches a
post-mortem pdb console whenever an unhandled exception is
encountered.

Args:
    limit (int): the max number of stack frames to display when
        printing the traceback

A similar effect can be achieved from the command-line using the
following command::

  python -m pdb your_code.py

But ``pdb_on_exception`` allows you to do this conditionally and within
your application. To restore default behavior, just do::

  sys.excepthook = sys.__excepthook__
r   Nc                 J   > TR                  UTS9  TR                  " U5        g )N)limit)print_tbpost_mortem)exc_typeexc_valexc_tbr   r   	tracebacks      r   pdb_excepthook(pdb_on_exception.<locals>.pdb_excepthookm   s"    6/r   )r   sysr"   
excepthook)r   r%   r#   r   r"   s   `  @@r   r   r   V   s    &   $N
r   2    c                    U R                  S5      [        R                  " 5       UR                  S5      UR                  R                  U4nU S:X  a  SnU[        U5      4-  nOU S:X  a  SnU[        US   5      4-  nOU S:X  a  S	nOS
nUSR                  U V	s/ s H  n	[        U	5      PM     sn	5      4-  nU(       aJ  SnUSR                  UR                  5        V
Vs/ s H  u  pU
< S[        U5      < 3PM     snn
5      4-  nU[        La  US-  nU[        U5      4-  n[        X-  5        g s  sn	f s  snn
f )N   
   getz%s %s - %s - %s.%s -> %ssetz%s %s - %s - %s.%s = %sr   delz%s %s - %s - %s.%sz%s %s - %s - %s.%s(%s)z, z%s %s - %s - %s.%s(%s, %s)=z -> %s)
ljusttimerjust	__class____name__
brief_reprjoinitemsr   print)eventlabelobj	attr_nameargskwargsresultfargstmplakvs               r   trace_print_hookrE   {   s:   [[^TYY[%++b/]]##Y0E~)*V$&&	%(*T!W%''	%#'$))D9DqZ]D9:<</Ddii-3\\^!=-;TQ -.z!}!=-;!= > @ @EHDj(**E	$,
 :!=s   D6
"D;c                   ^ ^^^^^^^^^ [        T[        5      (       a  U4S jnOF[        [        TSS5      5      (       a  U4S jnO$Tb  [        T5      (       a  TnO[	        ST-  5      eT=(       d    [        [        T 5      5      m[        U[        5      (       a  U/nU(       + =(       d    SU;   mU(       + =(       d    SU;   mU(       + =(       d    SU;   mU(       + =(       d    S	U;   mU(       + =(       d    S
U;   mU(       + =(       d    SU;   mTT4UUUUU 4S jjnUUUU 4S jnUUUU 4S jnUUUU 4S jn	0 n
[        T 5       He  n [        T U5      n[        U5      (       a  US;   a  M(  U(       a  U" X5      (       d  M>  US:X  a  UnOUS:X  a  UnOUS:X  a  U	nOU" X5      nXU'   Mg     T R                  R                  nXR                  5       :X  a  SU-   nOSU-   n[        T S5      (       a  T R                  4nOT R                  [        4n[        UUU
5      nUR                   H  n UR!                  U5      s  $    [	        ST R                  < ST < 35      e! [         a     GM+  f = f! [         a     MU  f = f)a8  Monitor an object for interactions. Whenever code calls a method,
gets an attribute, or sets an attribute, an event is called. By
default the trace output is printed, but a custom tracing *hook*
can be passed.

Args:
   obj (object): New- or old-style object to be traced. Built-in
       objects like lists and dicts also supported.
   hook (callable): A function called once for every event. See
       below for details.
   which (str): One or more attribute names to trace, or a
       function accepting attribute name and value, and returning
       True/False.
   events (str): One or more kinds of events to call *hook*
       on. Expected values are ``['get', 'set', 'del', 'call',
       'raise', 'return']``. Defaults to all events.
   label (str): A name to associate with the traced object
       Defaults to hexadecimal memory address, similar to repr.

The object returned is not the same object as the one passed
in. It will not pass identity checks. However, it will pass
:func:`isinstance` checks, as it is a new instance of a new
subtype of the object passed.

c                    > U T:H  $ r   r(   r<   attr_valwhichs     r   <lambda>wrap_trace.<locals>.<lambda>   
    e1Cr   __contains__Nc                    > U T;   $ r   r(   rH   s     r   rK   rL      rM   r   z*expected attr name(s) or callable, not: %rr,   r-   r.   callraisereturnc                 @  >^ ^^ UU UUUUUU	4S jnTR                   Ul         TR                  Ul         TR                  Ul         TR                  (       a%  UR                  R                  TR                  5        U$ ! [         a     NEf = f! [         a     U$ f = f)Nc                     > U SS  n T(       a
  T	" STT
TXS9  T(       a
   T" U 0 UD6nOT" U 0 UD6nT(       a  T	" STT
TXWS9  W$ !   T	" STT
TX[         R                  " 5       S9(       d  e  N<= f)N   rP   )r9   r:   r;   r<   r=   r>   rQ   )r9   r:   r;   r<   r=   r>   r?   rR   )r%   exc_info)rB   kwret_labelr<   do_calldo_raise	do_returnfunchookr;   s      r   wrapped0wrap_trace.<locals>.wrap_method.<locals>.wrapped   s    !"A6S(q=.R.C Ann86s(qCIJgV*3!'*||~7 7s   A &A-)r4   __doc__
__module__	Exception__dict__update)
r<   r]   _hookrY   r_   rZ   r[   r\   r^   r;   s
   `` ` r   wrap_methodwrap_trace.<locals>.wrap_method   s    	 	(  ==,,	!%G	}}  ''6   		
  		s#   A? 6B ?
BB
BBc           
         > [        T5      R                  TU5      n[        U5      (       a  [        T5      R                  X5      nT(       a  T" STTUS0 US9  U$ )Nr,   r(   )r?   )type__getattribute__callable)selfr<   rX   do_getr^   r:   r;   s      r   rk   $wrap_trace.<locals>.__getattribute__   sR    3i((i8C==s),,T=CsIr2cB
r   c                 d   > [        T5      R                  TX5        T(       a  T" STTX40 5        g )Nr-   )rj   __setattr__)rm   r<   valuedo_setr^   r:   r;   s      r   rq   wrap_trace.<locals>.__setattr__   s/    S	c94sIx<r   c                 d   > [        T5      R                  TU5        T(       a  T" STTUS0 5        g )Nr.   r(   )rj   __delattr__)rm   r<   do_delr^   r:   r;   s     r   rv   wrap_trace.<locals>.__delattr__   s/    S	c9-sIr26r   )__new__rk   rq   rv   traced_Traced__mro__zunable to wrap_trace z
 instance )
isinstance
basestringrl   getattr	TypeErrorhexiddirrc   r3   r4   lowerhasattrobjectrj   r|   ry   )r;   r^   rJ   eventsr:   
which_funcrg   rk   rq   rv   attrsr<   rI   wrapped_methodcls_name	type_namebases
trace_typeclsrZ   rw   rn   r[   r\   rs   s   ``` `              @@@@@@r   r	   r	      sf   B %$$C
	'%6	7	7C
	(5//
DuLMM!SC\E&*%%Z*5F?FZ*5F?FZ*5F?Fj,Ff,Gz.W.H
0h&0I+/    D    EX		sI.H !!Y,%>
9 ? ?**-N-'(N-'(N(=N)i' * }}%%H>>##(	x'	sI  'i.J!!	;;z** "
 }}c+ , ,K  		F  		s$   I'5I9'
I65I69
JJ__main__hellohir   )d   )ra   r%   r1   r~   reprr   	NameErrorstrbytesreprlib	typeutilsr   r   ImportErrorr   __all__r   r   	_repr_obj	maxstringmaxotherr5   rE   r	   r4   r;   failr   r   r(   r   r   <module>r      s   B  
'H-F >8< F		 	 ^^

 R4 *$dU,p z
R.CCIHHs}}	 A  uJ  XFs"   B B- B*)B*-B=<B=