B
    é¹`dk  ã               @   s†  d dl Z d dlZd dlmZmZmZ eZe j 	dd¡Z
ejd  dkrRd dlmZ nd dlmZ d dlZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZedddƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG d d!„ d!eƒZG d"d#„ d#eƒZG d$d%„ d%eƒZ G d&d'„ d'eƒZ!i Z"d/d)d*„Z#d0d+d,„Z$d1d-d.„Z%dS )2é    N)Ú
CO_VARARGSÚCO_VARKEYWORDSÚisclassÚreprÚreprlibé   )Úformat_exception_onlyc               @   sR   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZed
d„ ƒZ	dd„ Z
ddd„ZdS )ÚCodez$ wrapper around Python code objects c             C   sd   t |dƒstj |¡}y |j| _|jd | _|j| _	W n" t
k
rX   td|f ƒ‚Y nX || _d S )NÚco_filenameé   znot a code object: %r)ÚhasattrÚpyÚcodeÚ
getrawcoder
   ÚfilenameÚco_firstlinenoÚfirstlinenoÚco_nameÚnameÚAttributeErrorÚ	TypeErrorÚraw)ÚselfZrawcode© r   úU/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/py/_code/code.pyÚ__init__   s    
zCode.__init__c             C   s   | j |j kS )N)r   )r   Úotherr   r   r   Ú__eq__   s    zCode.__eq__c             C   s
   | |k S )Nr   )r   r   r   r   r   Ú__ne__!   s    zCode.__ne__c             C   s$   t j | jj¡}| ¡ s | jj}|S )zs return a path object pointing to source code (note that it
        might not point to an actually existing file). )r   ÚpathÚlocalr   r
   Úcheck)r   Úpr   r   r   r   $   s    z	Code.pathc             C   s    ddl m} | | j¡\}}|S )zM return a py.code.Source object for the full source file of the code
        r   )Úsource)Úpy._coder#   Ú
findsourcer   )r   r#   ÚfullÚ_r   r   r   Ú
fullsource0   s    zCode.fullsourcec             C   s   t j | j¡S )zJ return a py.code.Source object for the code object's source only
        )r   r   ÚSourcer   )r   r   r   r   r#   8   s    zCode.sourceFc             C   s:   | j }|j}|r,||jt@ 7 }||jt@ 7 }|jd|… S )z» return a tuple with the argument names for the code object

            if 'var' is set True also return the names of the variable and
            keyword arguments when present
        N)r   Úco_argcountÚco_flagsr   r   Úco_varnames)r   Úvarr   Zargcountr   r   r   Úgetargs>   s    zCode.getargsN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr   r(   r#   r.   r   r   r   r   r	      s   r	   c               @   sN   e Zd ZdZdd„ Zedd„ ƒZdd„ Zdd	„ Zd
d„ Z	dd„ Z
ddd„ZdS )ÚFramezgWrapper around a Python frame holding f_locals and f_globals
    in which expressions can be evaluated.c             C   s6   |j d | _|j| _|j| _|| _tj |j¡| _d S )Nr   )	Úf_linenoÚlinenoÚ	f_globalsÚf_localsr   r   r   r	   Úf_code)r   Úframer   r   r   r   P   s
    zFrame.__init__c             C   s(   | j jdkrtj  d¡S | j j | j¡S )z statement this frame is at NÚ )r   r(   r   r)   Úgetstatementr6   )r   r   r   r   Ú	statementW   s    zFrame.statementc             K   s"   | j  ¡ }| |¡ t|| j|ƒS )z” evaluate 'code' in the frame

            'vars' are optional additional local variables

            returns the result of the evaluation
        )r8   ÚcopyÚupdateÚevalr7   )r   r   Úvarsr8   r   r   r   r@   ^   s    

z
Frame.evalc             K   s*   | j  ¡ }| |¡ tj || j|¡ dS )z^ exec 'code' in the frame

            'vars' are optiona; additional local variables
        N)r8   r>   r?   r   ÚbuiltinÚexec_r7   )r   r   rA   r8   r   r   r   rC   i   s    

zFrame.exec_c             C   s   t j |¡S )zL return a 'safe' (non-recursive, one-line) string repr for 'object'
        )r   ÚioÚsaferepr)r   Úobjectr   r   r   r   r   s    z
Frame.reprc             C   s   |S )Nr   )r   rF   r   r   r   Úis_truew   s    zFrame.is_trueFc          	   C   sL   g }xB| j  |¡D ]2}y| || j| f¡ W q tk
rB   Y qX qW |S )z¬ return a list of tuples (name, value) for all arguments

            if 'var' is set True also include the variable and keyword
            arguments when present
        )r   r.   Úappendr8   ÚKeyError)r   r-   ÚretvalÚargr   r   r   r.   z   s    
zFrame.getargsN)F)r/   r0   r1   r2   r   r3   r=   r@   rC   r   rG   r.   r   r   r   r   r4   L   s   	r4   c               @   s¾   e Zd ZdZdZdZdd„ Zdd„ Zedd„ ƒZ	ed	d
„ ƒZ
dd„ Zedd„ ƒZedd„ ƒZdd„ ZeedddƒZdd„ Zdd„ Zd!dd„ZeeƒZdd„ Zdd„ Zdd„ Zeeddd ƒZdS )"ÚTracebackEntryz a single entry in a traceback Nc             C   s   || _ |jd | _d S )Nr   )Ú	_rawentryÚ	tb_linenor6   )r   Zrawentryr   r   r   r      s    zTracebackEntry.__init__c             C   s   |dkst ‚|| _d S )N)ÚshortÚlong)ÚAssertionErrorÚ_repr_style)r   Úmoder   r   r   Úset_repr_style“   s    zTracebackEntry.set_repr_stylec             C   s   t j | jj¡S )N)r   r   r4   rM   Útb_frame)r   r   r   r   r:   —   s    zTracebackEntry.framec             C   s   | j | jjj S )N)r6   r:   r   r   )r   r   r   r   Úrelline›   s    zTracebackEntry.rellinec             C   s   d| j jj| jd f S )Nz<TracebackEntry %s:%d>r   )r:   r   r   r6   )r   r   r   r   Ú__repr__Ÿ   s    zTracebackEntry.__repr__c             C   s   | j jj}| | j¡S )z1 py.code.Source object for the current statement )r:   r   r(   r<   r6   )r   r#   r   r   r   r=   ¢   s    
zTracebackEntry.statementc             C   s
   | j jjS )z path to the source code )r:   r   r   )r   r   r   r   r   ¨   s    zTracebackEntry.pathc             C   s   | j jS )N)r:   r8   )r   r   r   r   Ú	getlocals­   s    zTracebackEntry.getlocalszlocals of underlaying framec             C   sP   | j dkrJt| jƒ ¡ }tjj|| jdd}t|tƒsDt	d|f ƒ‚|| _ | j S )ztReinterpret the failing statement and returns a detailed information
           about what operations are performed.NT)Zshould_failz interpret returned non-string %r)
ÚexprinfoÚstrr=   Ústripr   r   Z_reinterpretr:   Ú
isinstancer   )r   r#   Úxr   r   r   Úreinterpret±   s    

zTracebackEntry.reinterpretc             C   s   t | jjjdƒS )Nr   )Úmaxr:   r   r   )r   r   r   r   Úgetfirstlinesource¼   s    z!TracebackEntry.getfirstlinesourcec       	      C   s®   ddl m} | jjj}|dkr"dS d }}|dk	rP| jjj}|dk	rP| |d¡}|  ¡ }y|| j||d\}}}W n t	k
r   | jd }Y nX |dk	r¢|||< |||… S )z return failing source code. r   )Úgetstatementrange_astN)Úastnoder   )
Zpy._code.sourcera   r:   r   r(   r   Úgetr`   r6   ÚSyntaxError)	r   Úastcachera   r#   Úkeyrb   Ústartr'   Úendr   r   r   Ú	getsourceÀ   s$    

zTracebackEntry.getsourcec             C   sH   y| j jd S  tk
rB   y| j jd S  tk
r<   dS X Y nX dS )z‰ return True if the current frame has a var __tracebackhide__
            resolving to True

            mostly for internal use
        Z__tracebackhide__FN)r:   r8   rI   r7   )r   r   r   r   ÚishiddenÚ   s    zTracebackEntry.ishiddenc             C   s„   yt | jƒ}W n tjjk
r*   d}Y nX | jjj}yt | jƒ 	¡ }W n$ t
k
r^   ‚ Y n   d}Y nX d|| jd ||f S )Nz???z  File %r:%d in %s
  %s
r   )rZ   r   r   ÚerrorÚErrorr:   r   r   r=   ÚlstripÚKeyboardInterruptr6   )r   Úfnr   Úliner   r   r   Ú__str__è   s    


zTracebackEntry.__str__c             C   s   | j jjjS )N)r:   r   r   r   )r   r   r   r   r   ö   s    zTracebackEntry.namezco_name of underlaying code)N)r/   r0   r1   r2   rR   rY   r   rT   r3   r:   rV   rW   r=   r   rX   Úlocalsr^   r`   ri   r#   rj   rq   r   r   r   r   r   rL   ‰   s(   
rL   c                   sV   e Zd ZdZeZdd„ Zddd„Z‡ fdd„Zd	d
„ fdd„Z	dd„ Z
dd„ Z‡  ZS )Ú	Tracebackz_ Traceback objects encapsulate and offer higher level
        access to Traceback entries.
    c                s8   t |dƒr(‡ fdd„}t ˆ ||ƒ¡ nt ˆ |¡ dS )z0 initialize from given python traceback object. Útb_nextc             3   s$   x| d k	rˆ   | ¡V  | j} qW d S )N)ÚEntryrt   )Úcur)r   r   r   Úf  s    
zTraceback.__init__.<locals>.fN)r   Úlistr   )r   Útbrw   r   )r   r   r     s    
zTraceback.__init__Nc             C   s~   xx| D ]p}|j j}|j}|dks(||kr|dksDt|dƒrD| |¡s|dksV|j|kr|dksl|j jj|krt|jƒS qW | S )a±   return a Traceback instance wrapping part of this Traceback

            by provding any combination of path, lineno and firstlineno, the
            first frame to start the to-be-returned traceback is determined

            this allows cutting the first part of a Traceback instance e.g.
            for formatting reasons (removing some uninteresting bits that deal
            with handling of the exception/traceback)
        NÚrelto)	r:   r   r   r   rz   r6   r   rs   rM   )r   r   r6   r   Zexcludepathr]   r   Zcodepathr   r   r   Úcut  s    


zTraceback.cutc                s0   t t| ƒ |¡}t|ttdƒƒƒr,|  |¡}|S )Nr   )Úsuperrs   Ú__getitem__r\   ÚtypeÚsliceÚ	__class__)r   rf   Úval)r€   r   r   r}   !  s    
zTraceback.__getitem__c             C   s
   |   ¡  S )N)rj   )r]   r   r   r   Ú<lambda>'  ó    zTraceback.<lambda>c             C   s   t t|| ƒƒS )as   return a Traceback instance with certain items removed

            fn is a function that gets a single argument, a TracebackItem
            instance, and should return True when the item should be added
            to the Traceback, False when not

            by default this removes all the TracebackItems which are hidden
            (see ishidden() above)
        )rs   Úfilter)r   ro   r   r   r   r„   '  s    
zTraceback.filterc             C   s<   x2t dt| ƒ d dƒD ]}| | }| ¡ s|S qW | d S )zc return last non-hidden traceback entry that lead
        to the exception of a traceback.
        éÿÿÿÿr   )ÚrangeÚlenrj   )r   ÚiÚentryr   r   r   Úgetcrashentry3  s
    zTraceback.getcrashentryc       	   	   C   sŒ   i }x‚t | ƒD ]v\}}|jjjt|jjjƒ|jf}| |g ¡}|rv|j}|j}x&|D ]}| 	|j
t||d¡rT|S qTW | |jj¡ qW dS )zŠ return the index of the frame/TracebackItem where recursion
            originates if appropriate, None if no recursion occurred
        )Z__recursioncache_locals_1Z__recursioncache_locals_2N)Ú	enumerater:   r   r   Úidr   r6   Ú
setdefaultr8   rG   r@   Úco_equalrH   )	r   Úcacherˆ   r‰   rf   Úlrw   ÚlocZotherlocr   r   r   Úrecursionindex=  s    


zTraceback.recursionindex)NNNN)r/   r0   r1   r2   rL   ru   r   r{   r}   r„   rŠ   r’   Ú__classcell__r   r   )r€   r   rs   û   s   

rs   z6__recursioncache_locals_1 == __recursioncache_locals_2ú?r@   c               @   sZ   e Zd ZdZdZddd„Zdd„ Zdd	d
„Zdd„ Zdd„ Z	ddd„Z
dd„ Zdd„ ZdS )ÚExceptionInfozX wraps sys.exc_info() objects and offers
        help for navigating the traceback.
    r;   Nc             C   s    |d kr^t  ¡ }|d kr^t|d tƒr^t|d dd ƒ}|d krJt|d ƒ}|r^| d¡r^d| _|| _|d | _	|d | _
|d | _| j	j| _tj | j¡| _d S )Nr   Úmsgzassert zAssertionError: r   é   )ÚsysÚexc_infor\   rQ   ÚgetattrrZ   Ú
startswithÚ
_striptextZ_excinfor~   Úvaluery   r/   Útypenamer   r   rs   Ú	traceback)r   ÚtuprY   r   r   r   r   ]  s    



zExceptionInfo.__init__c             C   s   d| j t| jƒf S )Nz<ExceptionInfo %s tblen=%d>)rž   r‡   rŸ   )r   r   r   r   rW   r  s    zExceptionInfo.__repr__Fc             C   sF   t | j| jƒ}d |¡}| ¡ }|rB| | j¡rB|t| jƒd… }|S )a.   return the exception as a string

            when 'tryshort' resolves to True, and the exception is a
            py.code._AssertionError, only the actual exception part of
            the exception representation is returned (so 'AssertionError: ' is
            removed from the beginning)
        r;   N)r   r~   r   ÚjoinÚrstripr›   rœ   r‡   )r   ÚtryshortÚlinesÚtextr   r   r   Úexconlyv  s    
zExceptionInfo.exconlyc             C   s   t | j|ƒS )z4 return True if the exception is an instance of exc )r\   r   )r   Úexcr   r   r   Úerrisinstance†  s    zExceptionInfo.errisinstancec             C   s:   | j dd}| j ¡ }|jjjj|j }}t||d |ƒS )NT)r£   r   )	r¦   rŸ   rŠ   r:   r   r   r
   r6   ÚReprFileLocation)r   r¦   r‰   r   r6   r   r   r   Ú_getreprcrashŠ  s    
zExceptionInfo._getreprcrashrP   Tc             C   sL   |dkr0t tt | j| j| jd j¡ƒ|  ¡ ƒS t|||||d}| 	| ¡S )aA   return str()able representation of this exception info.
            showlocals: show locals per traceback entry
            style: long|short|no|native traceback style
            tbfilter: hide entries (where __tracebackhide__ is true)

            in case of style==native, tbfilter and showlocals is ignored.
        Únativer   )Ú
showlocalsÚstyleÚabspathÚtbfilterÚfuncargs)
ÚReprExceptionInfoÚReprTracebackNativerŸ   Úformat_exceptionr~   r   rM   rª   ÚFormattedExcinfoÚrepr_excinfo)r   r¬   r­   r®   r¯   r°   Úfmtr   r   r   Úgetrepr  s    	
zExceptionInfo.getreprc             C   s*   | j d }t|j|jd |  ¡ ƒ}t|ƒS )Nr…   r   )rŸ   r©   r   r6   r¦   rZ   )r   r‰   r‘   r   r   r   rq   ¦  s    
zExceptionInfo.__str__c             C   s*   | j d }t|j|jd |  ¡ ƒ}| ¡ S )Nr…   r   )rŸ   r©   r   r6   r¦   Ú__unicode__)r   r‰   r‘   r   r   r   r¸   «  s    
zExceptionInfo.__unicode__)NN)F)FrP   FTF)r/   r0   r1   r2   rœ   r   rW   r¦   r¨   rª   r·   rq   r¸   r   r   r   r   r•   X  s   

 
r•   c               @   s€   e Zd ZdZdZdZd"dd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
d#dd„Zd$dd„Zdd„ Zd%dd„Zdd„ Zdd„ Zd d!„ ZdS )&r´   z@ presenting information about failing Functions and Generators. ú>ÚEFrP   Tc             C   s(   || _ || _|| _|| _|| _i | _d S )N)r¬   r­   r¯   r°   r®   re   )r   r¬   r­   r®   r¯   r°   r   r   r   r   ·  s    zFormattedExcinfo.__init__c             C   s„   yt | t|ƒd ¡ƒ}W nP tk
r0   ‚ Y n<   yt |d ƒ}W n tk
r\   ‚ Y n
   dS Y nX dt|ƒt| ¡ ƒ  S )Nr   r…   r   é   )rZ   r<   r‡   rn   rm   )r   r#   Úsr   r   r   Ú
_getindentÀ  s    
zFormattedExcinfo._getindentc             C   s    |  | j¡}|d k	r| ¡ }|S )N)ri   re   Zdeindent)r   r‰   r#   r   r   r   Ú_getentrysourceÏ  s    z FormattedExcinfo._getentrysourcec             C   s   t j |¡S )N)r   rD   rE   )r   Úobjr   r   r   Ú	_safereprÕ  s    zFormattedExcinfo._safereprc             C   sF   | j rBg }x.|jjddD ]\}}| ||  |¡f¡ qW t|ƒS d S )NT)r-   )r°   r:   r.   rH   rÀ   ÚReprFuncArgs)r   r‰   ÚargsÚargnameZargvaluer   r   r   Ú	repr_argsØ  s
    zFormattedExcinfo.repr_argsr…   Nc       	      C   sþ   g }|dks|t |jƒkr*tj d¡}d}|dk r>|t |ƒ7 }d}|r`| ||j|  ¡  ¡ njx$|jd|… D ]}| || ¡ qpW | | jd |j|  ¡ x(|j|d d… D ]}| || ¡ q´W |dk	rú|rÚdn|  |¡}| 	| j
||dd	¡ |S )
z. return formatted and marked up source lines. Nz???r   z    z   r   r»   T)ÚindentÚmarkall)r‡   r¤   r   r   r)   rH   r[   Úflow_markerr½   ÚextendÚget_exconly)	r   r#   Ú
line_indexÚexcinforO   r¤   Zspace_prefixrp   rÅ   r   r   r   Ú
get_sourceß  s$    zFormattedExcinfo.get_sourcer»   c             C   sX   g }d| }|j dd d¡}| j|dd …  }x"|D ]}| || ¡ |s6|}q6W |S )Nú T)r£   Ú
r   )r¦   ÚsplitÚfail_markerrH   )r   rË   rÅ   rÆ   r¤   ZexlinesZ
failindentrp   r   r   r   rÉ   õ  s    
zFormattedExcinfo.get_exconlyc             C   sr   | j rng }dd„ |D ƒ}| ¡  xD|D ]<}|| }|dkrF| d¡ q&|  |¡}| d||f ¡ q&W t|ƒS d S )Nc             S   s   g | ]}|d  dkr|‘qS )r   ú@r   )Ú.0r‘   r   r   r   ú
<listcomp>  s    z0FormattedExcinfo.repr_locals.<locals>.<listcomp>Ú__builtins__z__builtins__ = <builtins>z
%-10s = %s)r¬   ÚsortrH   rÀ   Ú
ReprLocals)r   rr   r¤   Úkeysr   r   Zstr_reprr   r   r   Úrepr_locals  s    

zFormattedExcinfo.repr_localsc             C   s  |   |¡}|d kr$tj d¡}d}n|jt| ¡ dƒ }g }|j}|d krP| j}|dkrî|dk}|sn|  	|¡nd }| j
||||d}	| |	¡ |ržd|j }
n|r¨|jpªd}
|  |j¡}t||jd |
ƒ}d }|sÞ|  |j¡}t|||||ƒS |r| | j|d	d
¡ t|d d d |ƒS )Nz???r   )rO   rP   rO   )rO   zin %sr;   r   r»   )rÅ   )r¾   r   r   r)   r6   r_   r`   rR   r­   rÄ   rÌ   rÈ   r   rž   Ú	_makepathr   r©   rØ   rr   Ú	ReprEntryrÉ   )r   r‰   rË   r#   rÊ   r¤   r­   rO   Zreprargsr¼   Úmessager   ÚfilelocreprZ
localsreprr   r   r   Úrepr_traceback_entry  s4    

z%FormattedExcinfo.repr_traceback_entryc             C   sL   | j sHytj ¡  |¡}W n tk
r.   |S X t|ƒtt|ƒƒk rH|}|S )N)r®   r   r   r    ZbestrelpathÚOSErrorr‡   rZ   )r   r   Únpr   r   r   rÙ   8  s    zFormattedExcinfo._makepathc             C   s¢   |j }| jr| ¡ }d }| t¡r8dt|jƒkr8| ¡ }|d }g }d }xHt|ƒD ]<\}}||krf|phd }	|  	||	¡}
| 
|
¡ ||krRd}P qRW t||| jdS )Nz maximum recursion depth exceededr…   z/!!! Recursion detected (same locals & position))r­   )rŸ   r¯   r„   r¨   ÚRuntimeErrorrZ   r   r’   r‹   rÝ   rH   ÚReprTracebackr­   )r   rË   rŸ   r’   ÚlastÚentriesÚ	extralineÚindexr‰   ZeinfoZ	reprentryr   r   r   Úrepr_tracebackB  s$    

zFormattedExcinfo.repr_tracebackc             C   s   |   |¡}| ¡ }t||ƒS )N)ræ   rª   r±   )r   rË   ÚreprtracebackÚ	reprcrashr   r   r   rµ   V  s    
zFormattedExcinfo.repr_excinfo)FrP   TTF)r…   NF)r»   F)N)r/   r0   r1   r2   rÇ   rÐ   r   r½   r¾   rÀ   rÄ   rÌ   rÉ   rØ   rÝ   rÙ   ræ   rµ   r   r   r   r   r´   ±  s     



 
r´   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTerminalReprc             C   s$   |   ¡ }tjd dk r | d¡}|S )Nr   r   zutf-8)r¸   r˜   Úversion_infoÚencode)r   r¼   r   r   r   rq   \  s    
zTerminalRepr.__str__c             C   s.   t j ¡ }t jj|d}|  |¡ | ¡  ¡ S )N)Úfile)r   rD   ÚTextIOZTerminalWriterÚ
toterminalÚgetvaluer[   )r   rD   Útwr   r   r   r¸   b  s    

zTerminalRepr.__unicode__c             C   s   d| j t| ƒf S )Nz<%s instance at %0x>)r€   rŒ   )r   r   r   r   rW   j  s    zTerminalRepr.__repr__N)r/   r0   r1   rq   r¸   rW   r   r   r   r   ré   [  s   ré   c               @   s&   e Zd Zdd„ Zd	dd„Zdd„ ZdS )
r±   c             C   s   || _ || _g | _d S )N)rç   rè   Úsections)r   rç   rè   r   r   r   r   o  s    zReprExceptionInfo.__init__ú-c             C   s   | j  |||f¡ d S )N)rñ   rH   )r   r   ÚcontentÚsepr   r   r   Ú
addsectiont  s    zReprExceptionInfo.addsectionc             C   s<   | j  |¡ x*| jD ] \}}}| ||¡ | |¡ qW d S )N)rç   rî   rñ   rô   rp   )r   rð   r   ró   rô   r   r   r   rî   w  s    zReprExceptionInfo.toterminalN)rò   )r/   r0   r1   r   rõ   rî   r   r   r   r   r±   n  s   
r±   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )rá   z_ c             C   s   || _ || _|| _d S )N)Úreprentriesrä   r­   )r   rö   rä   r­   r   r   r   r   €  s    zReprTraceback.__init__c             C   sš   d }x~t | jƒD ]p\}}|jdkr,| d¡ | |¡ |t| jƒd k r| j|d  }|jdkst|jdkr|jdkr| | j¡ qW | jr–| | j¡ d S )NrP   r;   r   rO   )	r‹   rö   r­   rp   rî   r‡   rô   Úentryseprä   )r   rð   Z
last_stylerˆ   r‰   Z
next_entryr   r   r   rî   …  s    



zReprTraceback.toterminalN)r/   r0   r1   r÷   r   rî   r   r   r   r   rá   }  s   rá   c               @   s   e Zd Zdd„ ZdS )r²   c             C   s   d| _ t|ƒg| _d | _d S )Nr«   )r­   ÚReprEntryNativerö   rä   )r   Útblinesr   r   r   r   –  s    zReprTracebackNative.__init__N)r/   r0   r1   r   r   r   r   r   r²   •  s   r²   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )rø   r«   c             C   s
   || _ d S )N)r¤   )r   rù   r   r   r   r   ž  s    zReprEntryNative.__init__c             C   s   |  d | j¡¡ d S )Nr;   )Úwriter¡   r¤   )r   rð   r   r   r   rî   ¡  s    zReprEntryNative.toterminalN)r/   r0   r1   r­   r   rî   r   r   r   r   rø   ›  s   rø   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	rÚ   z_ c             C   s"   || _ || _|| _|| _|| _d S )N)r¤   ÚreprfuncargsÚ
reprlocalsÚreprfilelocr­   )r   r¤   rû   rü   rÜ   r­   r   r   r   r   §  s
    zReprEntry.__init__c             C   sÂ   | j dkrD| j |¡ x(| jD ]}| d¡}|j|d|d qW d S | jrV| j |¡ x(| jD ]}| d¡}|j|d|d q^W | jrœ| d¡ | j |¡ | jr¾| jr²| d¡ | j |¡ d S )NrO   zE   T)ZboldÚredr;   )r­   rý   rî   r¤   r›   rp   rû   rü   )r   rð   rp   rþ   r   r   r   rî   ®  s$    




zReprEntry.toterminalc             C   s   dd  | j¡| j| jf S )Nz%s
%s
%srÎ   )r¡   r¤   rü   rý   )r   r   r   r   rq   Ä  s    zReprEntry.__str__N)r/   r0   r1   Z	localssepr   rî   rq   r   r   r   r   rÚ   ¤  s   rÚ   c               @   s   e Zd Zdd„ Zdd„ ZdS )r©   c             C   s   t |ƒ| _|| _|| _d S )N)rZ   r   r6   rÛ   )r   r   r6   rÛ   r   r   r   r   Ê  s    
zReprFileLocation.__init__c             C   s@   | j }| d¡}|dkr$|d |… }| d| j| j|f ¡ d S )NrÎ   r…   z	%s:%s: %s)rÛ   Úfindrp   r   r6   )r   rð   r–   rˆ   r   r   r   rî   Ï  s
    
zReprFileLocation.toterminalN)r/   r0   r1   r   rî   r   r   r   r   r©   É  s   r©   c               @   s   e Zd Zdd„ Zdd„ ZdS )rÖ   c             C   s
   || _ d S )N)r¤   )r   r¤   r   r   r   r   Ù  s    zReprLocals.__init__c             C   s   x| j D ]}| |¡ qW d S )N)r¤   rp   )r   rð   rp   r   r   r   rî   Ü  s    zReprLocals.toterminalN)r/   r0   r1   r   rî   r   r   r   r   rÖ   Ø  s   rÖ   c               @   s   e Zd Zdd„ Zdd„ ZdS )rÁ   c             C   s
   || _ d S )N)rÂ   )r   rÂ   r   r   r   r   á  s    zReprFuncArgs.__init__c             C   sŠ   | j r†d}xb| j D ]X\}}d||f }t|ƒt|ƒ d |jkrT|rN| |¡ |}q|rf|d| 7 }q|}qW |r|| |¡ | d¡ d S )Nr;   z%s = %sr—   z, )rÂ   r‡   Z	fullwidthrp   )r   rð   Z	linesofarr   r   Únsr   r   r   rî   ä  s    

zReprFuncArgs.toterminalN)r/   r0   r1   r   rî   r   r   r   r   rÁ   à  s   rÁ   Tc             C   sj   | r8ddl m}  t dg ¡}| tjjj¡ | jtjj_|rft dg ¡}| tjjj	¡ tj
j	tjj_	dS )z? put compile and AssertionError builtins to Python's builtins. r   )Ú	assertionrQ   ÚcompileN)r$   r  Úoldbuiltinsr   rH   r   rB   ÚbuiltinsrQ   r  r   )r  r  r   r   r   r   Úpatch_builtinsú  s    r  c             C   s0   | rt d  ¡ tjj_|r,t d  ¡ tjj_dS )zB remove compile and AssertionError builtins from Python builtins. rQ   r  N)r  Úpopr   rB   r  rQ   r  )r  r  r   r   r   Úunpatch_builtins  s    r  c             C   sŒ   y| j S  tk
r†   t| d| ƒ} t| d| ƒ} t| d| ƒ} t| d| ƒ} |r‚t| dƒs‚t| dƒr‚t| ƒs‚t| jdd}t|dƒr‚|S | S X d	S )
z( return code object for given function. Zim_funcÚ	func_coder9   Ú__code__r   Ú__call__F)ÚtrycallN)r	  r   rš   r   r   r   r
  )r¿   r  r]   r   r   r   r     s    
r   )TT)TT)T)&r   r˜   Úinspectr   r   r   r   Zbuiltin_reprrB   Z
_tryimportr   rê   rŸ   r   Zpy._code._py2tracebackrF   r	   r4   rL   rx   rs   r  rŽ   r•   r´   ré   r±   rá   r²   rø   rÚ   r©   rÖ   rÁ   r  r  r  r   r   r   r   r   Ú<module>   s<   ;=rZY +	%

