o
    ˷e'                     @   s(  d dl mZ d dlZd dlZd dlmZ dZd dlmZ d dl	m
Z
 d dlmZ d dlmZ zd dlZW n   d dlZY d	d
 Zdg fddZdd Zd(ddZdd ZG dd deZdd Zd)ddZdd Zd*ddZdd Zd*d d!Zed"d# Ze Zd$e Z d%d& Z!e"d'kre!  dS dS )+    )print_functionN)contextmanagerz0.13.9)get_ipython)BdbQuit_excepthook)TerminalIPythonApp)InteractiveShellEmbedc                  C   sN   t  } | d u rt }d|_|dg |j} | j
S t| tr$tj	d | j
S )NFz--no-term-titlezZ
You are currently into an embedded ipython shell,
the configuration will not be loaded.

)r   r   interact
initializeshell
isinstancer   sysstderrwritedebugger_cls)r
   ipapp r   D/var/www/ideatree/venv/lib/python3.10/site-packages/ipdb/__main__.py_get_debugger_cls   s   
r   c                 C   sT   | d u rt dt } t }z|| d}W n ty!   | }Y nw |j| |S )NIPDB_CONTEXT_SIZE)context)osgetenvget_context_from_configr   	TypeErrorrcLinesextend)r   commandsr   pr   r   r   	_init_pdb3   s   
r   c                   C   s    t jtkrt jt_tt _d S d S N)r   
excepthookr   excepthook_orir   r   r   r   wrap_sys_excepthook?   s   

r"   Tc                 C   sR   |sd S t   | d u rt j} t|| }|r%t|dr'|j  d S d S d S )Nr
   )	r"   r   	_getframef_backr   	set_tracehasattrr
   restore_sys_module_state)framer   condr   r   r   r   r%   G   s   
r%   c               	   C   s\   z
t  } | ddW S  tjtjfy   Y dS  ty-   | dd}td| j|f w )Nipdbr      z?In %s,  context value [%s] cannot be converted into an integer.)
get_configgetintconfigparserNoSectionErrorNoOptionError
ValueErrorgetfilepath)parservaluer   r   r   r   R   s   r   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )
ConfigFilez
    Filehandle wrapper that adds a "[ipdb]" section to the start of a config
    file so that users don't actually have to manually add a [ipdb] section.
    Works with configparser versions from both Python 2 and 3
    c                 C   s>   d| _ t|}| | _W d    d S 1 sw   Y  d S )NT)firstopen	readlineslines)selfr3   fr   r   r   __init__g   s   
"zConfigFile.__init__c                 C   s    z|   W S  ty   Y dS w )N )__next__StopIterationr;   r   r   r   readlinem   s
   
zConfigFile.readlinec                 C   s   |   S r   )r?   rA   r   r   r   nextt   s   zConfigFile.nextc                 C   s   | S r   r   rA   r   r   r   __iter__x   s   zConfigFile.__iter__c                 C   s&   | j rd| _ dS | jr| jdS t)NFz[ipdb]
r   )r7   r:   popr@   rA   r   r   r   r?   {   s   zConfigFile.__next__N)	__name__
__module____qualname____doc__r=   rB   rC   rD   r?   r   r   r   r   r6   `   s    r6   c               	   C   s  t  } g }dD ]}tjt |}tj|r|| qtd}|r8tj|d}tj|r8|| td}|rJtj|rJ|| |rz| j	}W n t
y]   | j}Y nw |D ]g}|| _|drt|}	| d ||	 W d   n1 sw   Y  q`|drd	dl}
|
|}d
|v rd|d
 v r| ds| d |d
 d  D ]\}}| d|t| qq`|t| q`| S )a  
    Get ipdb config file settings.
    All available config files are read.  If settings are in multiple configs,
    the last value encountered wins.  Values specified on the command-line take
    precedence over all config file settings.
    Returns: A ConfigParser object.
    )	setup.cfg.ipdbpyproject.tomlHOMErK   IPDB_CONFIGrJ   r*   NrL   r   tool)r.   ConfigParserr   pathjoingetcwdisfileappendr   	read_fileAttributeErrorreadfpr3   endswithr8   remove_sectiontomlloadhas_sectionadd_sectionitemssetstrr6   )r4   	filepathscfg_filecwd_filepathhomedefault_filepathenv_filepath	read_funcr3   r<   r[   	toml_filekeyr5   r   r   r   r,      sP   














r,   c                 C   s@   t   t }|  | d u rt d } | r|d |  d S d S )N   )r"   r   resetr   exc_infointeraction)tbr   r   r   r   post_mortem   s   rp   c                   C   s   t tj d S r   )rp   r   last_tracebackr   r   r   r   pm   s   rr   c                 C   s   t  | || d S r   )r   run)	statementglobalslocalsr   r   r   rs      s   rs   c                  O   s   t  j| i |S r   )r   runcall)argskwargsr   r   r   rw      s   rw   c                 C   s   t  | ||S r   )r   runeval)
expressionru   rv   r   r   r   rz      s   rz   c                  c   sT    z'zd V  W W d S  t y(   t \} }}t| tjd t| Y W d S w w )N)file)	Exceptionr   rm   print__repr__r   rp   )emro   r   r   r   launch_ipdb_on_exception   s   
r   a  usage: python -m ipdb [-m] [-c command] ... pyfile [arg] ...

Debug the Python program given by pyfile.

Initial commands are read from .pdbrc files in your home directory
and in the current directory, if they exist.  Commands supplied with
-c are executed after commands from .pdbrc files.

To let the script run until an exception occurs, use "-c continue".
To let the script run up to a given line X in the debugged file, use
"-c 'until X'"

Option -m is available only in Python 3.7 and later.

ipdb version %s.c               
   C   s6  dd l } dd l}dd l}zddlm} W n ty%   G dd dt}Y nw |jdkr<||jdd  ddd	g\}}n||jdd  d
dd	g\}}g }d}|D ]!\}}	|dv rct	t
 |  qR|dv rm||	 qR|dv rsd}qR|st	t
 |d |d }
|stj|
st	d|
d |d ||_|stj|
|jd< t|d}	 z|r||
 n||
 |jrW d S t	d W nV |y   t	d|
d t	dd|jdd    Y n: ty   t	ddd t	| d  Y n$   |   t	d t	d | d }|d | t	d|
 d  Y q) Nr   )Restartc                   @   s   e Zd ZdS )zmain.<locals>.RestartN)rF   rG   rH   r   r   r   r   r     s    r   )r+         zmhc:helpzcommand=zhc:F)z-hz--help)z-cz	--command)z-mTrk   zError:zdoes not exist)r   z*The program finished and will be restarted
Restartingzwith arguments:	 z0The program exited via sys.exit(). Exit status: r>   )endz2Uncaught exception. Entering post mortem debuggingz1Running 'cont' or 'step' will restart the programz#Post mortem debugger finished. The z will be restarted)	tracebackr   getoptpdbr   ImportErrorr}   version_infoargvr~   _usageexitrU   r   rQ   existsdirnamer   
_runmodule
_runscript_user_requested_quitrR   
SystemExitrm   	print_excrn   )r   r   r   r   optsrx   r   run_as_moduleoptoptarg
mainpyfiler   tr   r   r   main   sr   
" 




 r   __main__)NNTr   )NN)#
__future__r   r   r   	decoratorr   __version__IPythonr   IPython.core.debuggerr   IPython.terminal.ipappr   IPython.terminal.embedr   r.   rP   r   r   r"   r%   r   objectr6   r,   rp   rr   rs   rw   rz   r   iexr   r   rF   r   r   r   r   <module>   sF   

$
;


I
