a
    ñ»jŸ  ã                   @   sv   d Z ddlZddlZddlZddlZddlZddlZddlmZ e 	e
¡Zdd„ Zddd„Zd	d
„ ZG dd„ dƒZdS )z‘Simple traceback introspection. Used to add additional information to
AssertionErrors in tests, so that failure messages may be more informative.é    N)ÚStringIOc              
   C   sX  t  d| ¡ | jr| j} q| j}t| ƒ\}}t||ƒ\}}tt d 	|¡¡ƒ}t
|j|jƒ}|rözt |j¡D ]}||Ž  qnW qö tjyð }	 zXt  d|	¡ | d¡ |d8 }tt d 	|¡¡ƒ}t
|j|jƒ}W Y d}	~	q\W Y d}	~	qöd}	~	0 0 qöq\g }
|j�rN|j d¡}d}|D ]6}||k�r4|
 d| ¡ n|
 d	| ¡ |d7 }�qd 	|
¡S )
zÚInspect a traceback and its frame, returning source for the expression
    where the exception was raised, with simple variable replacement performed
    and the line on which the exception was raised marked with '>>' zinspect traceback %sÚ zTokenizer error: %sr   é   NÚ
z>>  z    )ÚlogÚdebugÚtb_nextÚtb_frameÚtbsourceÚfind_inspectable_linesr   ÚtextwrapÚdedentÚjoinÚExpanderÚf_localsÚ	f_globalsÚtokenizeÚgenerate_tokensÚreadlineÚ
TokenErrorÚpopÚexpanded_sourceÚsplitÚappend)ÚtbÚframeÚlinesZexc_lineZinspect_linesZ	mark_lineÚsrcÚexpÚtokÚeÚpaddedZ	exp_linesÚepÚline© r$   ú4E:\soccer\ml_env\Lib\site-packages\nose/inspector.pyÚinspect_traceback   s<    
"
r&   é   c           	      C   s  | j }| j}|dkrà|d |d  }t d||¡ zt |¡\}}W n tyb   dgd }}Y qì0 |}t|dƒ}tdt|t	|ƒ| ƒƒ}|||| … }|d | }|dkrì||d   
¡  d¡rì|d8 }|||| … }q®ndgd }}t d||¡ ||fS )a9  Get source from  a traceback object.
    A tuple of two things is returned: a list of lines of context from
    the source code, and the index of the current line within that list.
    The optional second argument specifies the number of lines of context
    to return, which are centered around the current line.r   r   é   zlineno: %s start: %sr   ú\z'tbsource lines '''%s''' around index %s)Ú	tb_linenor	   r   r   ÚinspectÚ
findsourceÚIOErrorÚmaxÚminÚlenÚstripÚendswith)	r   ÚcontextÚlinenor   Ústartr   ÚdummyÚindexÚ	all_linesr$   r$   r%   r
   3   s*    
r
   c                 C   s4  t  d¡}t  d¡}t  d¡}g }| | }| |¡ ¡ d }| t|d dƒ|… }| ¡  | |d t|d t| ƒƒ… }	|D ]*}
| |
¡ ¡ d |kr¢| |
¡ q| q¨q|| ¡  | |¡ t|ƒd }| 	|¡}|	D ]H}
|sô| |
¡ ¡ d |k�r| 	|
¡�s| |
¡ | 	|
¡}qÔ �qqÔt
 d||¡ ||fS )	a  Find lines in home that are inspectable.
    Walk back from the err line up to 3 lines, but don't walk back over
    changes in indent level.
    Walk forward up to 3 lines, counting \ separated lines as 1. Don't walk
    over changes in indent level (unless part of an extended line)z
\\[\s\n]*$z	:[\s\n]*$z^(\s*)r   é   r   é   z#Inspecting lines '''%s''' around %s)ÚreÚcompileÚmatchÚgroupsr.   Úreverser/   r0   r   Úsearchr   r   )r   ÚposZcntZdfÚindZ	toinspectÚhomeZhome_indentÚbeforeÚafterr#   Zhome_posÚ	continuedr$   r$   r%   r   R   s:    




ÿÿþ
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   zsSimple expression expander. Uses tokenize to find the names and
    expands any that can be looked up in the frame.c                 C   s   || _ || _d | _d| _d S )Nr   )ÚlocalsÚglobalsÚlposr   )ÚselfrG   rH   r$   r$   r%   Ú__init__z   s    zExpander.__init__c                 C   sF  | j d urZ|d | j kr6|  jd|d | j   7  _n$|d | j k rZ|  jd|d  7  _|d | _ |tjkrpnª|tjk�rz*| j| }t|tjj	ƒrœ|}nt
|ƒ}W nT tyú   z*| j| }t|tjj	ƒrÔ|}nt
|ƒ}W n tyô   |}Y n0 Y n0 |  j|7  _n|  j|7  _t d||d d … ¡�rB|  jd7  _d S )Nr   ú z\s+\\\nz \
)rI   r   r   ÚINDENTÚNAMErG   Ú
isinstanceÚcollectionsÚabcÚCallableÚreprÚKeyErrorrH   r;   r=   )rJ   Úttyper   r5   Úendr#   Úvalr$   r$   r%   Ú__call__€   s4    




zExpander.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rK   rX   r$   r$   r$   r%   r   w   s   r   )r'   )r\   r+   Úloggingr;   r   r   rP   Úior   Ú	getLoggerrY   r   r&   r
   r   r   r$   r$   r$   r%   Ú<module>   s   
%
%