Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/logilab/common/__pycache__/debugger.cpython-37.pyc

B

�d{T��@s�dZddlmZdZyddlZWnek
r8dZYnXddlZddlmZ	ddl
Z
ddlmZddl
Z
ddlmZyddlmZWn$ek
r�dd	�Zd
d�ZYnXdd	�Zd
d�Zdd�ZGdd�de�Zdd�Zdd�ZdS)z�Customized version of pdb's default debugger.

- sets up a history file
- uses ipython if available to colorize lines of code
- overrides list command to search for current block instead
  of using 5 lines of context




�)�print_functionzrestructuredtext enN)�Pdb)�StringIO)�
PyColorizecGs|S)zfallback colorize function�)�source�argsrr�H/opt/alt/python37/lib/python3.7/site-packages/logilab/common/debugger.py�colorize1sr
cGs|S)Nr)rrrrr	�colorize_source4src	Cs|t��}t�}|�||�g}xRt|�����D]>\}}||}||kr\|�d||f�q0|�d||f�q0Wd�|�S)zUcolorize and annotate source with linenos
        (as in pdb's list command)
        z	%4s	->	%sz%4s		%s�
)	r�Parserr�format�	enumerate�getvalue�
splitlines�append�join)	r�start_linenoZ	curlineno�parser�outputZ	annotated�index�line�linenorrr	r
7scCs"t��}t�}|�||�|��S)zcolorize given source)rr
rrr)rrrrrr	rGscCst�|�\}}d�|�|fS)aReturn the text of the source code for an object.

    The argument may be a module, class, method, function, traceback, frame,
    or code object.  The source code is returned as a single string.  An
    IOError is raised if the source code cannot be retrieved.�)�inspect�getsourcelinesr)�obj�lines�lnumrrr	�	getsourceOsr c@sjeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZeZ
dd�ZeZdS)�Debuggerz�custom debugger

    - sets up a history file
    - uses ipython if available to colorize lines of code
    - overrides list command to search for current block instead
      of using 5 lines of context
    NcCsDt�|�|��|r,x|jdk	r*|j}qW||_tj�d�|_dS)Nz
~/.pdbhist)	r�__init__�reset�tb_next�_tcbk�os�path�
expanduser�	_histfile)�self�tcbkrrr	r"bs

zDebugger.__init__cCs2tdk	r.yt�|j�Wntk
r,YnXdS)z8if readline is available, read pdb history file
        N)�readline�read_history_filer)�IOError)r*rrr	�setup_history_fileks
zDebugger.setup_history_filecCs|�|jj|j�dS)zstarts the interactive modeN)Zinteractionr%�tb_frame)r*rrr	�startvszDebugger.startcCs|��t�|||�dS)zsetup hook: set up history fileN)r/r�setup)r*�framer+rrr	r2zszDebugger.setupcCs"tdk	rt�|j�t�|�dS)z,quit hook: save commands in the history fileN)r,�write_history_filer)r�set_quit)r*rrr	r5szDebugger.set_quitcs@t|jj�}|�|jj�d�kr.|��|�S�fdd�|D�S)z7provide variable names completion for the ``p`` command�.csg|]}|���r|�qSr)�
startswith)�.0Zvarname)�textrr	�
<listcomp>�sz'Debugger.complete_p.<locals>.<listcomp>)�dict�curframe�	f_globals�update�f_locals�attr_matches)r*r9rZ	begin_idxZend_idx�	namespacer)r9r	�
complete_p�s
zDebugger.complete_pcCs�ddl}|�d|�}|sdS|�dd�\}}t||�}t|�}t|d�rb|�d�||�|j�}g}	t	|�}
x6|D].}|d|
�|krt|dkrt|	�d||f�qtW|	S)	aimplementation coming from rlcompleter.Completer.attr_matches
        Compute matches when text contains a dot.

        Assuming the text is of the form NAME.NAME....[NAME], and is
        evaluatable in self.namespace, it will be evaluated and its attributes
        (as revealed by dir()) are used as possible completions.  (For class
        instances, class members are also considered.)

        WARNING: this can still invoke arbitrary C code, if an object
        with a __getattr__ hook is evaluated.

        rNz(\w+(\.\w+)*)\.(\w*)���	__class__�__builtins__z%s.%s)
�re�match�group�eval�dir�hasattrr�get_class_membersrE�len)r*r9rArG�m�expr�attr�object�words�matches�n�wordrrr	r@�s 




zDebugger.attr_matchescCs4t|�}t|d�r0x|jD]}||�|�}qW|S)z8implementation coming from rlcompleter.get_class_members�	__bases__)rKrLrWrM)r*�klass�ret�baserrr	rM�s

zDebugger.get_class_memberscCs|d|_|sly,t|j�\}}ttd�|�||jj��Wqxtk
rJYqxtk
rht	�
||�YqxXnt	�
||�dS)znoverrides default list command to display the surrounding block
        instead of 5 lines of context
        �listrN)Zlastcmdr r<�printr
r�f_lineno�KeyboardInterruptr.r�do_list)r*�argrrrrr	r_�szDebugger.do_listcCs,|jjj}|jj}d||f}t�|�dS)z:opens source file corresponding to the current stack levelzemacsclient --no-wait +%s %sN)r<�f_code�co_filenamer]r&�system)r*r`�filenamer�cmdrrr	�do_open�s
zDebugger.do_open)N)�__name__�
__module__�__qualname__�__doc__r"r/r1r2r5rBr@rMr_Zdo_lrfZdo_orrrr	r!Zs
			r!cCsttj�}|��dS)zuse our custom debuggerN)r!�sys�last_tracebackr1)Zdbgrrr	�pm�s
rmcCst��t��j�dS)N)r!�	set_tracerk�	_getframe�f_backrrrr	rn�srn)rj�
__future__r�
__docformat__r,�ImportErrorr&�os.pathr'Zosprk�pdbrrZlogilab.common.compatrZIPythonrr
rr r!rmrnrrrr	�<module>s.
v