
    Bh{6                       d Z ddlmZ ddlZddlmZ ddlm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 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! d!dZ"d"dZ#d#dZ$ G d d      Z% G d d      Z& G d d      Z'd$dZ(d$dZ)	 	 	 	 	 	 	 	 d%dZ*	 	 	 	 d&dZ+d'd Z,y)(z4Interactive debugging with PDB, the Python Debugger.    )annotationsN)Callable)	Generator)Any)outcomes)ExceptionInfo)CaptureManager)Config)ConftestImportFailure)hookimpl)PytestPluginManager)Parser)
UsageError)Node)
BaseReport)CallInfoc                    	 | j                  d      \  }}||fS # t        $ r}t        j                  | d      |d}~ww xY w)z#Validate syntax of --pdbcls option.:z) is not in the format 'modname:classname'N)split
ValueErrorargparseArgumentTypeError)valuemodname	classnamees       \/var/www/html/Telegram-Engagement-Pod-/env/lib/python3.12/site-packages/_pytest/debugging.py_validate_usepdb_clsr      sZ    "[[-
 Y	  ((i@A
	s    	A<Ac                    | j                  d      }|j                  dddd       |j                  ddd	t        d
       |j                  dddd       y )Ngeneralz--pdbusepdb
store_truezDStart the interactive Python debugger on errors or KeyboardInterrupt)destactionhelpz--pdbcls
usepdb_clszmodulename:classnamez{Specify a custom interactive Python debugger for use with --pdb.For example: --pdbcls=IPython.terminal.debugger:TerminalPdb)r#   metavartyper%   z--tracetracez(Immediately break when running each test)getgroup	addoptionr   )parsergroups     r   pytest_addoptionr.   )   sq    OOI&E	OOS	   
OO&!F   
OO7	      c                
   dd l | j                  d      r$| j                  j                  t	               d       | j                  d      r$| j                  j                  t               d       t        j                  j                  j                  t        j                  t        j                  f       t        j                  _	        | j                  t        _
        | t        _        dfd}| j                  |       y )Nr   r)   pdbtracer!   	pdbinvokec                 x    t         j                  j                         \   _        t         _        t         _        y N)	pytestPDB_savedpop	set_trace_pluginmanager_config)pdbs   r   finzpytest_configure.<locals>.finR   s-    
   "		
M$r/   returnNone)r;   getvaluepluginmanagerregisterPdbTrace	PdbInvoker5   r6   appendr8   r9   r:   add_cleanup)configr<   r;   s     @r   pytest_configurerH   A   s    w%%hj*=x %%ik;?		00)2C2CD ''CM%33II# sr/   c                      e Zd ZU dZdZded<   dZded<   g Zded<   d	ZdZ	d
ed<   e
dd       Ze
dd       Ze
dd       Ze
d        Ze
dd       Zy)r5   z'Pseudo PDB that defers to the real pdb.NzPytestPluginManager | Noner9   zConfig | Noner:   zKlist[tuple[Callable[..., None], PytestPluginManager | None, Config | None]]r6   r   z"tuple[type[Any], type[Any]] | None_wrapped_pdb_clsc                (    |r|j                         S y)NF)is_capturing)clscapmans     r   _is_capturingzpytestPDB._is_capturingg   s    &&((r/   c                J   | j                   sdd l}|j                  S | j                   j                  d      }| j                  r!| j                  d   |k(  r| j                  d   S |r[|\  }}	 t        |       t        j                  |   }|j                  d      }t        ||d         }|dd  D ]  }	t        ||	      } ndd l}|j                  }| j                  ||      }||f| _        |S # t        $ r*}
dj                  ||f      }t        d|d|
       |
d }
~
ww xY w)Nr   r&      .r   z--pdbcls: could not import z: )r:   r;   Pdbr@   rJ   
__import__sysmodulesr   getattr	Exceptionjoinr   _get_pdb_wrapper_class)rM   rN   r;   r&   r   r   modpartspdb_clspartexcr   wrapped_clss                r   _import_pdb_clszpytestPDB._import_pdb_clsm   s3   {{ 77N[[)),7
C$8$8$;z$I''**!+GY7#kk'* ",!#uQx0!!"ID%gt4G & ggG00&A *K8  '9!56 1%"SEBs   -AC/ /	D"8%DD"c                6     dd l  G  fdd      }|S )Nr   c                  N    e Zd ZW ZdZ fdZ eW d      rW j
                  j                  e_         fdZ eW d      rW j                  j                  e_        exZ	Z
 fdZ eW d      rW j                  j                  e_        eZeZ fdZ fd	Z xZS )
:pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapperFc                z    xj                   dz  c_         t        | 	  |      }xj                   dz  c_         |S )NrQ   )_recursive_debugsuperdo_debugselfargret	__class__rM   s      r   rh   zCpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_debug   s9    $$)$g&s+$$)$
r/   rh   c                F   t         |   |      }j                  dk(  rj                  J j                  j                  j                        }|j                          | j                  }t        j                  |      }|rC|dk(  r|j                  dd       n|j                  dd| d       |J |j                          n|j                  dd       j                  J j                  j                  j                  j                  |        d	| _        |S )
Nr   global>z#PDB continue (IO-capturing resumed)z'PDB continue (IO-capturing resumed for )zPDB continuerG   r;   T)rg   do_continuerf   r:   rG   create_terminal_writerline_pytest_capmanr5   rO   sepresumer9   hookpytest_leave_pdb
_continued)	rj   rk   rl   twrN   	capturingrm   _pytestrM   s	         r   rs   zFpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_continue   s	   g)#.''1,;;222 >>s{{KBGGI!00F ) 7 7 ?I $0FF3(MNFF #"I)TU V  &111sN3))555""''88QU8V"&
r/   rs   c                n    t         |   |      }j                  dk(  rt        j                  d       |S )Nr   Quitting debugger)rg   do_quitrf   r   exitri   s      r   r   zBpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.do_quit   s3     goc*''1,MM"56
r/   r   c                    t         |   ||      }|s4| j                  r(| j                  r| j                  j	                  d       |S )zSuspend on setup().

                Needed after do_continue resumed, and entering another
                breakpoint again.
                Tin_)rg   setupr{   rv   suspend_global_capture)rj   ftbrl   rm   s       r   r   z@pytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.setup   sE     gmAr*t **++BBtBL
r/   c                   t         |   ||      \  }}|ft        dt        |      dz
        }|rL||   d   j                  j                  dd      r*|dz  }|r#||   d   j                  j                  dd      r*||fS )Nr   rQ   __tracebackhide__F)rg   	get_stackmaxlenf_localsget)rj   r   tstackirm   s        r   r   zDpytestPDB._get_pdb_wrapper_class.<locals>.PytestPdbWrapper.get_stack   s     7,Q2q9As5zA~.Aa 4 4 8 89Le TQ a 4 4 8 89Le Taxr/   )__name__
__module____qualname__rv   r{   rh   hasattr__doc__rs   do_cdo_contr   do_qdo_exitr   r   __classcell__)rm   r~   rN   rM   r]   s   @r   PytestPdbWrapperrd      s    #NJ w
+#*#3#3#;#; 4 w.&-&9&9&A&A#((D7 w	*")//"9"9DG   r/   r   )_pytest.config)rM   r]   rN   r   r~   s   ``` @r   rZ   z pytestPDB._get_pdb_wrapper_class   s#    T	  T	 w T	 l  r/   c                   ddl }| j                  d}n| j                  j                  d      }|r|j                  d       | j                  r|j
                  j                  | j                        }|j                          | j                  dk(  r|j                  dd      }||j                  d|       n^| j                  |      }|dk(  r|j                  dd	| d
       n1|r|j                  dd	| d| d       n|j                  dd	|         | j                  |      di |}	| j                  r1| j                  j                  j                  | j                  |	       |	S )z4Initialize PDB debugging, dropping any IO capturing.r   NcapturemanagerTr   headerrp   ro   zPDB z (IO-capturing turned off)z (IO-capturing turned off for rq   rr    )r   r9   	getpluginsuspendr:   rG   rt   ru   rf   r7   rw   rO   ra   ry   pytest_enter_pdb)
rM   methodargskwargsr~   rN   r|   r   r}   _pdbs
             r   	_init_pdbzpytestPDB._init_pdb   sQ    	%,0F''112BCFNNtN$;;66s{{CBGGI##q(Hd3%FF3' # 1 1& 9I H,sd6(2L$MN""6(*HSTU
 sd6(O4*s""6*4V4##44CKKT4Rr/   c                    t        j                         j                  } | j                  dg|i |}|j	                  |       y)zBInvoke debugging via ``Pdb.set_trace``, dropping any IO capturing.r8   N)rU   	_getframef_backr   r8   )rM   r   r   framer   s        r   r8   zpytestPDB.set_trace  s;     &&s}}[:4:6:ur/   )rN   CaptureManager | Noner>   z
str | bool)rN   r   r=   )r   r   r   r   r9   __annotations__r:   r6   rf   rJ   classmethodrO   ra   rZ   r   r8   r   r/   r   r5   r5   \   s    115N.5!G]! 	    ;?8? 
 $ $L Y  Y v $ $L  r/   r5   c                  ,    e Zd Z	 	 	 	 	 	 	 	 ddZddZy)rD   c                   |j                   j                  j                  d      }|rc|j                  d       |j	                         \  }}t
        j                  j                  |       t
        j                  j                  |       |j                  J t        |j                  j                  t        j                        st        ||j                  |       y y )Nr   Tr   )rG   rA   r   r   read_global_capturerU   stdoutwriteexcinfo
isinstancer   unittestSkipTest
_enter_pdb)rj   nodecallreportrN   outerrs          r   pytest_exception_interactz#PdbInvoke.pytest_exception_interact   s     **445EF))d)3113HCJJS!JJS!||'''$,,,,h.?.?@tT\\62 Ar/   c                0    t        |      }t        |       y r4   )_postmortem_exc_or_tbpost_mortem)rj   r   	exc_or_tbs      r   pytest_internalerrorzPdbInvoke.pytest_internalerror.  s    )'2	Ir/   N)r   r   r   zCallInfo[Any]r   r   r>   r?   )r   ExceptionInfo[BaseException]r>   r?   )r   r   r   r   r   r   r/   r   rD   rD     s,    33 -37A3	3r/   rD   c                  ,    e Zd Z ed      dd       Zy)rC   T)wrapperc              #  (   K   t        |       d S wr4   ) wrap_pytest_function_for_tracing)rj   
pyfuncitems     r   pytest_pyfunc_callzPdbTrace.pytest_pyfunc_call4  s     (4s   N)r>   zGenerator[None, object, object])r   r   r   r   r   r   r/   r   rC   rC   3  s    d r/   rC   c                    t         j                  d      | j                  t        j                        dfd       }|| _        y)zChange the Python function object of the given Function item by a
    wrapper which actually enters pdb before calling the python function
    itself, effectively leaving the user in the pdb prompt in the first
    statement of the function.runcallc                 Z    t        j                  g| i |}j                  |       y r4   )	functoolspartialr   )r   r   funcr   testfunctions      r   r   z1wrap_pytest_function_for_tracing.<locals>.wrapperE  s)      ???Tr/   Nr=   )r5   r   objr   wraps)r   r   r   r   s     @@r   r   r   :  sD    
 y)D>>L
 __\" # JNr/   c                R    | j                   j                  d      rt        |        yy)zaWrap the given pytestfunct item for tracing support if --trace was given in
    the command line.r)   N)rG   r@   r   )r   s    r   &maybe_wrap_pytest_function_for_tracingr   M  s%     !!'*(4 +r/   c                D   | j                   j                  j                  d      j                  }|j	                          | j                   j
                  j                  }d|j                  fd|j                  fd|j                  ffD ]B  \  }}||dfv s|s|j                  dd|z          |dd  d	k(  r|d d }|j	                  |       D |j                  dd
       |j                  |       |j                  dd       t        |      }d|_        t        |       |S )Nterminalreporterr   stderrlogallrp   z	captured 
	tracebackzentering PDBT)rG   rA   r   _twru   optionshowcapture	capstdout	capstderrcaplogrw   
toterminalr   	_pdbshownr   )r   r   repr|   r   sectionnamecontent	tb_or_excs           r   r   r   T  s    
	"	"	,	,-?	@	D	DBGGI++$$00K 
3==!	3==!	

!W
 ;..7FF3k12rs|t#!#2,GGG! FF3NN2FF3%g.ICM	Jr/   c                   ddl m} t        j                  dk\  }t	        | j
                  |      r,| j
                  }|r|j                  d   S |j                  d   S t	        | j
                  t              r4| j
                  j                  }|r|S |j                  J |j                  S | j                  J |r| j                  d   S | j                  d   S )Nr   )UnexpectedException)      rQ      )doctestr   rU   version_infor   r   exc_infor   cause__traceback___excinfo)r   r   get_excunderlying_excr   s        r   r   r   s  s     ,')G'--!45 !!**1--&&q))	GMM#8	9 ##L""..."""+++##A&&""r/   c                    t         j                  d      }|j                          |j                  d |        |j                  rt        j                  d       y y )Nr   r   )r5   r   resetinteractionquittingr   r   )r   ps     r   r   r     sB    M*AGGIMM$	"zz)* r/   )r   strr>   ztuple[str, str])r,   r   r>   r?   )rG   r
   r>   r?   r=   )r   r   r   r   r   r   r>   r   )r   r   r>   #types.TracebackType | BaseException)r   r  r>   r?   )-r   
__future__r   r   collections.abcr   r   r   rU   typestypingr   r   r~   r   _pytest._coder   _pytest.capturer	   r   r
   r   r   r   _pytest.config.argparsingr   _pytest.config.exceptionsr   _pytest.nodesr   _pytest.reportsr   _pytest.runnerr   r   r.   rH   r5   rD   rC   r   r   r   r   r   r   r/   r   <module>r     s    ; "  $ %  
     ' * ! 0 # . , 0  & # 06@ @F ( &5
5<F>#)#(#>+r/   