
    adk                     "   d dl Z d dlZd dlmZmZmZ eZe j                  j                  dd      Z
ej                  d    dk\  rd dlmZ nd dlmZ d dlZ G d de      Z G d	 d
e      Z G d de      Z G d de      Z eddd      Z G d de      Z G d de      Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d  d!e      Z G d" d#e      Z G d$ d%e      Z  G d& d'e      Z!i Z"d+d(Z#d+d)Z$d,d*Z%y)-    N)
CO_VARARGSCO_VARKEYWORDSisclassreprreprlib   )format_exception_onlyc                   P    e Zd ZdZd Zd Zd Zed        Zed        Z	d Z
d
dZy	)Codez$ wrapper around Python code objects c                    t        |d      st        j                  j                  |      }	 |j                  | _        |j                  dz
  | _        |j                  | _	        || _        y # t        $ r t        d|      w xY w)Nco_filename   znot a code object: )hasattrpycode
getrawcoder   filenameco_firstlinenofirstlinenoco_namenameAttributeError	TypeErrorraw)selfrawcodes     //usr/lib/python3/dist-packages/py/_code/code.py__init__zCode.__init__   s{    w.gg((1G	B#//DM&559DDI   	Bw@AA	Bs   6A+ +Bc                 4    | j                   |j                   k(  S N)r   r   others     r   __eq__zCode.__eq__   s    xx599$$    c                     | |k(   S r     r!   s     r   __ne__zCode.__ne__!   s    5=  r$   c                     t         j                  j                  | 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   ps     r   r)   z	Code.path$   s?     GGMM$((../wwy $$Ar$   c                 N    ddl m} |j                  | 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_s       r   
fullsourcezCode.fullsource0   s$     	$##DHH-ar$   c                 T    t         j                  j                  | j                        S )zJ return a py.code.Source object for the code object's source only
        )r   r   Sourcer   r   s    r   r.   zCode.source8   s     ww~~dhh''r$   c                     | j                   }|j                  }|r,||j                  t        z  z  }||j                  t        z  z  }|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   argcounts       r   getargszCode.getargs>   sP     hh??z11H~55Hy))r$   NF)__name__
__module____qualname____doc__r   r#   r'   propertyr)   r3   r.   r=   r&   r$   r   r   r      sF    .	%! 	 	  (*r$   r   c                   F    e Zd ZdZd Zed        Zd Zd Zd Z	d Z
d
dZy	)FramezgWrapper around a Python frame holding f_locals and f_globals
    in which expressions can be evaluated.c                     |j                   dz
  | _        |j                  | _        |j                  | _        || _        t
        j                  j                  |j                        | _        y Nr   )	f_linenolineno	f_globalsf_localsr   r   r   r   f_code)r   frames     r   r   zFrame.__init__P   sG    nnq(GGLL.	r$   c                     | j                   j                  t        j                   j                  d      S | j                   j                  j	                  | j
                        S )z statement this frame is at  )r   r3   r   r5   getstatementrI   r6   s    r   	statementzFrame.statementW   sF     99'77>>"%%yy##00==r$   c                     | j                   j                         }|j                  |       t        || j                  |      S )z evaluate 'code' in the frame

            'vars' are optional additional local variables

            returns the result of the evaluation
        )rK   copyupdateevalrJ   r   r   varsrK   s       r   rU   z
Frame.eval^   s5     ==%%'D$..(33r$   c                     | j                   j                         }|j                  |       t        j                  j                  || j                  |       y)z^ exec 'code' in the frame

            'vars' are optiona; additional local variables
        N)rK   rS   rT   r   builtinexec_rJ   rV   s       r   rZ   zFrame.exec_i   s<    
 ==%%'


t~~x8r$   c                 @    t         j                  j                  |      S )zL return a 'safe' (non-recursive, one-line) string repr for 'object'
        r   iosafereprr   objects     r   r   z
Frame.reprr   s     uu~~f%%r$   c                     |S r    r&   r_   s     r   is_truezFrame.is_truew   s    r$   c                     g }| j                   j                  |      D ]#  }	 |j                  || j                  |   f       % |S # t        $ r Y 3w xY w)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=   appendrK   KeyError)r   r;   retvalargs       r   r=   zFrame.getargsz   sa     99$$S) 	CsDMM#$678	
   s    A	AANr>   )r?   r@   rA   rB   r   rC   rQ   rU   rZ   r   rb   r=   r&   r$   r   rE   rE   L   s9    ./ > >	49&
r$   rE   c                       e Zd ZdZdZdZd Zd Zed        Z	ed        Z
d Zed        Zed	        Zd
 Z eeddd      Zd Zd ZddZ ee      Zd Zd Zd Z eeddd      Zy)TracebackEntryz a single entry in a traceback Nc                 :    || _         |j                  dz
  | _        y rG   )	_rawentry	tb_linenorI   )r   rawentrys     r   r   zTracebackEntry.__init__   s    !((1,r$   c                     |dv sJ || _         y )Nshortlong)_repr_style)r   modes     r   set_repr_stylezTracebackEntry.set_repr_style   s    ((((r$   c                 h    t         j                  j                  | j                  j                        S r    )r   r   rE   rk   tb_framer6   s    r   rM   zTracebackEntry.frame   s    ww}}T^^4455r$   c                 \    | j                   | j                  j                  j                  z
  S r    )rI   rM   r   r   r6   s    r   rellinezTracebackEntry.relline   s    {{TZZ__8888r$   c                 f    d| j                   j                  j                  | j                  dz   fz  S )Nz<TracebackEntry %s:%d>r   )rM   r   r)   rI   r6   s    r   __repr__zTracebackEntry.__repr__   s(    '4::??+?+?Q*OOOr$   c                 x    | j                   j                  j                  }|j                  | j                        S )z1 py.code.Source object for the current statement )rM   r   r3   rP   rI   )r   r.   s     r   rQ   zTracebackEntry.statement   s,     ++""4;;//r$   c                 B    | j                   j                  j                  S )z path to the source code )rM   r   r)   r6   s    r   r)   zTracebackEntry.path   s     zz###r$   c                 .    | j                   j                  S r    )rM   rK   r6   s    r   	getlocalszTracebackEntry.getlocals   s    zz"""r$   zlocals of underlaying framec                    | j                   tt        | j                        j                         }t        j
                  j                  || j                  d      }t        |t              st        d|      || _         | j                   S )ztReinterpret the failing statement and returns a detailed information
           about what operations are performed.T)should_failzinterpret returned non-string )
exprinfostrrQ   stripr   r   _reinterpretrM   
isinstancer   )r   r.   xs      r   reinterpretzTracebackEntry.reinterpret   sm     == (..0F$$VTZZT$JAa%a IJJDM}}r$   c                 V    t        | j                  j                  j                  d      S Nr   )maxrM   r   r   r6   s    r   getfirstlinesourcez!TracebackEntry.getfirstlinesource   s    4::??..22r$   c                 r   ddl m} | j                  j                  j                  }|ydx}}|4| j                  j                  j
                  }||j                  |d      }| j                         }	  || j                  ||      \  }}}||||<   	 ||| S # t        $ r | j                  dz   }Y w xY w)z return failing source code. r   )getstatementrange_astN)astnoder   )
py._code.sourcer   rM   r   r3   r)   getr   rI   SyntaxError)	r   astcacher   r.   keyr   startr2   ends	            r   	getsourcezTracebackEntry.getsource   s     	:++>g**//&&C",,sD1'')	(3DKK<CEOGQ
  'eC    	"++/C	"s   5B B65B6c                     	 | j                   j                  d   S # t        $ r- 	 | j                   j                  d   cY S # t        $ r Y Y yw xY ww xY w)z return True if the current frame has a var __tracebackhide__
            resolving to True

            mostly for internal use
        __tracebackhide__F)rM   rK   re   rJ   r6   s    r   ishiddenzTracebackEntry.ishidden   sY    	::&&':;; 	zz++,?@@ 	s+    	AA A 	A	AAAc                 P   	 t        | j                        }| j
                  j                  j                  }	 t        | j                        j                         }d|| j                  dz   ||fz  S # t        j                  j                  $ r d}Y {w xY w# t        $ r   d}Y JxY w)N???z  File %r:%d in %s
  %s
r   )r   r)   r   errorErrorrM   r   r   rQ   lstripKeyboardInterruptrI   )r   fnr   lines       r   __str__zTracebackEntry.__str__   s    	TYYB zz##	t~~&--/D
 ,r4;;q=$.MMM xx~~ 	B	
 ! 		Ds   A1 #B 1BBB%c                 V    | j                   j                  j                  j                  S r    )rM   r   r   r   r6   s    r   r   zTracebackEntry.name   s    zz""***r$   zco_name of underlaying coder    )r?   r@   rA   rB   rr   r   r   rt   rC   rM   rx   rz   rQ   r)   r~   localsr   r   r   r.   r   r   r   r&   r$   r   ri   ri      s    )KH-  6 6 9 9P 0 0
 $ $#it-JKF	3!0 i FN+D$&CDDr$   ri   c                   L     e Zd ZdZeZd Zd	dZ fdZd fdZ	d Z
d Z xZS )
	Tracebackz_ Traceback objects encapsulate and offer higher level
        access to Traceback entries.
    c                      t        |d      r" fd}t        j                    ||             yt        j                   |       y)z0 initialize from given python traceback object. tb_nextc              3   X   K   | #j                  |        | j                  } | "y y wr    )Entryr   )curr   s    r   fzTraceback.__init__.<locals>.f  s*     o**S/)++C os   $**N)r   listr   )r   tbr   s   `  r   r   zTraceback.__init__  s4    2y!& MM$"&MM$#r$   c                 D   | D ]  }|j                   j                  }|j                  }|||k(  s-|t        |d      r|j	                  |      rM||j
                  |k(  s_|$|j                   j                  j                  |k(  st        |j                        c S  | 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)
        relto)	rM   r   r)   r   r   rI   r   r   rk   )r   r)   rI   r   excludepathr   r   codepaths           r   cutzTraceback.cut  s      	.A77<<DyyHT!1$GHg,F^^K0188v#5$(@(@K(O --	. r$   c                     t         t        |   |      }t        |t	        t        d                  r| j                  |      }|S r   )superr   __getitem__r   typeslice	__class__)r   r   valr   s      r   r   zTraceback.__getitem__!  s9    It05c4a>*..%C
r$   c                 $    | j                          S r    )r   )r   s    r   <lambda>zTraceback.<lambda>'  s    ajjl"2 r$   c                 ,    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)
        )r   filter)r   r   s     r   r   zTraceback.filter'  s     D)**r$   c                 |    t        dt        |        dz
  d      D ]  }| |   }|j                         r|c S  | d   S )zc return last non-hidden traceback entry that lead
        to the exception of a traceback.
        r   )rangelenr   )r   ientrys      r   getcrashentryzTraceback.getcrashentry3  sI     rCI:a<, 	AGE>>#	 Bxr$   c           	         i }t        |       D ]  \  }}|j                  j                  j                  t	        |j                  j                  j
                        |j                  f}|j                  |g       }|rL|j                  }|j                  }|D ]/  }|j                  |j                  t        ||            s+|c c S  |j                  |j                  j                          y)z return the index of the frame/TracebackItem where recursion
            originates if appropriate, None if no recursion occurred
        )__recursioncache_locals_1__recursioncache_locals_2N)	enumeraterM   r   r)   idr   rI   
setdefaultrK   rb   rU   co_equalrd   )	r   cacher   r   r   lr   locotherlocs	            r   recursionindexzTraceback.recursionindex=  s     !$ 	+HAu
 ++""''EKK,<,<,@,@)A5<<OC  b)AKKjj ! !Hyy252: "( "< =  !	!
 HHU[[))*!	+" r$   )NNNN)r?   r@   rA   rB   ri   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s2     E	$* 3 
+r$   r   z6__recursioncache_locals_1 == __recursioncache_locals_2?rU   c                   N    e Zd ZdZdZddZd ZddZd Zd Z		 	 dd	Z
d
 Zd Zy)ExceptionInfozX wraps sys.exc_info() objects and offers
        help for navigating the traceback.
    rO   Nc                    |ct        j                         }|Mt        |d   t              r:t	        |d   dd       }|t        |d         }|r|j                  d      rd| _        || _        |d   | _	        |d   | _
        |d   | _        | j                  j                  | _        t        j                  j!                  | j                        | _        y )Nr   msgzassert zAssertionError: r      )sysexc_infor   AssertionErrorgetattrr   
startswith
_striptext_excinfor   valuer   r?   typenamer   r   r   	traceback)r   tupr   s      r   r   zExceptionInfo.__init__]  s    ;,,.CJs1v~$F"3q65$7#"3q6{H 3 3I >&8DOF	V
a&		****4773r$   c                 J    d| j                   t        | j                        fz  S )Nz<ExceptionInfo %s tblen=%d>)r   r   r   r6   s    r   rz   zExceptionInfo.__repr__r  s&    ,MM3t~~.00 0 	0r$   c                     t        | j                  | j                        }dj                  |      }|j	                         }|r3|j                  | j                        r|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)
        rO   N)r	   r   r   joinrstripr   r   r   )r   tryshortlinestexts       r   exconlyzExceptionInfo.exconlyv  s^     &dii<wwu~{{}t/C012r$   c                 .    t        | j                  |      S )z4 return True if the exception is an instance of exc )r   r   )r   excs     r   errisinstancezExceptionInfo.errisinstance  s    $**c**r$   c                     | j                  d      }| j                  j                         }|j                  j                  j
                  j                  |j                  }}t        ||dz   |      S )NTr   r   )	r   r   r   rM   r   r   r   rI   ReprFileLocation)r   r   r   r)   rI   s        r   _getreprcrashzExceptionInfo._getreprcrash  sZ    ,,,-,,.{{''++77ffQh88r$   c           
         |dk(  rct        t        t        j                  | j                  | j
                  | j                  d   j                              | j                               S t        |||||      }|j                  |       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   rk   r   FormattedExcinforepr_excinfo)r   r   r   r   r   r   fmts          r   getreprzExceptionInfo.getrepr  s     H$%8**IIJJNN1%//&
 &&(* * !hC %%r$   c                     | j                   d   }t        |j                  |j                  dz   | j	                               }t        |      S Nr   r   )r   r   r)   rI   r   r   r   r   r   s      r   r   zExceptionInfo.__str__  s:    r"uzz5<<!+;T\\^L3xr$   c                     | j                   d   }t        |j                  |j                  dz   | j	                               }|j                         S r  )r   r   r)   rI   r   __unicode__r  s      r   r  zExceptionInfo.__unicode__  s>    r"uzz5<<!+;T\\^L  r$   )NNr>   )Frq   FTF)r?   r@   rA   rB   r   r   rz   r   r   r   r   r   r  r&   r$   r   r   r   X  s>     J4*0 +9 /57<&,
!r$   r   c                   l    e Zd ZdZdZdZ	 	 ddZd Zd Zd Z	d Z
dd
ZddZd ZddZd Zd Zd Zy	)r   z@ presenting information about failing Functions and Generators. >Ec                 X    || _         || _        || _        || _        || _        i | _        y r    )r   r   r   r   r   r   )r   r   r   r   r   r   s         r   r   zFormattedExcinfo.__init__  s,    $
  r$   c                    	 t        |j                  t        |      dz
              }dt        |      t        |j	                               z
  z   S # t        $ r   	 t        |d         }n# t        $ r   Y Y yxY wY VxY w)Nr   r   r      )r   rP   r   r   r   )r   r.   ss      r   
_getindentzFormattedExcinfo._getindent  s    
	F''FA67A CFS_,-- ! 		r
O$ 	 s)   &A A>A+*A>+A96A>9A>c                 `    |j                  | j                        }||j                         }|S r    )r   r   deindent)r   r   r.   s      r   _getentrysourcez FormattedExcinfo._getentrysource  s+    /__&Fr$   c                 @    t         j                  j                  |      S r    r\   )r   objs     r   	_safereprzFormattedExcinfo._saferepr  s    uu~~c""r$   c                     | j                   rSg }|j                  j                  d      D ]'  \  }}|j                  || j	                  |      f       ) t        |      S y )NT)r;   )r   rM   r=   rd   r  ReprFuncArgs)r   r   argsargnameargvalues        r   	repr_argszFormattedExcinfo.repr_args  s`    ==D%*[[%8%8T%8%B A!WdnnX&>?@A%%	 r$   Nc                    g }||t        |j                        k\  r!t        j                  j	                  d      }d}|dk  r|t        |      z  }d}|r0|j                  ||j                  |   j                         z          n|j                  d| D ]  }|j                  ||z           |j                  | j                  dz   |j                  |   z          |j                  |dz   d D ]  }|j                  ||z           |8|rdn| j                  |      }|j                  | j                  ||d	             |S )
z. return formatted and marked up source lines. Nr   r   z    z   r   r  T)indentmarkall)r   r   r   r   r5   rd   r   flow_markerr  extendget_exconly)	r   r.   
line_indexexcinforp   r   space_prefixr   r  s	            r   
get_sourcezFormattedExcinfo.get_source  s-   >Z3v||+<<WW^^E*FJ>#f+%JLLZ(@(F(F(HHI[j1 2\D012LL))E1FLL4LLMZ\]3 2\D012QT__V%<FLL))'&$)OPr$   c                     g }d|z  }|j                  d      j                  d      }| j                  |dd  z   }|D ]  }|j                  ||z          |r|} |S )N Tr   
r   )r   splitfail_markerrd   )r   r!  r  r  r   exlines
failindentr   s           r   r  zFormattedExcinfo.get_exconly  sp    v//4/066t<%%qr
2
 	$DLLd*+#
	$ r$   c                 &   | j                   rg }|D cg c]  }|d   dk7  s| }}|j                          |D ]F  }||   }|dk(  r|j                  d       | j                  |      }|j                  |dd|       H t	        |      S y c c}w )Nr   @__builtins__z__builtins__ = <builtins>10 = )r   sortrd   r  
ReprLocals)r   r   r   r   keysr   r   str_reprs           r   repr_localszFormattedExcinfo.repr_locals  s    ??E#);CSVs]C;D;IIK At>)LL!<=
  $~~e4H LLh!?@A  e$$) ;s
   BBc                    | j                  |      }|"t        j                  j                  d      }d}n'|j                  t        |j                         d      z
  }g }|j                  }|| j                  }|dv r|dk(  }|s| j                  |      nd }| j                  ||||      }	|j                  |	       |rd|j                  z  }
n|xr |j                  xs d}
| j                  |j                        }t!        ||j                  dz   |
      }d }|s| j#                  |j$                        }t'        |||||      S |r"|j                  | j)                  |d	
             t'        |d d d |      S )Nr   r   ro   rp   )rp   zin %srO   r   r  )r  )r  r   r   r5   rI   r   r   rr   r   r  r#  r  r   r   	_makepathr)   r   r4  r   	ReprEntryr  )r   r   r!  r.   r   r   r   rp   reprargsr  messager)   filelocrepr
localsreprs                 r   repr_traceback_entryz%FormattedExcinfo.repr_traceback_entry  sa   %%e,>WW^^E*FJ E,D,D,F(JJJ!!=JJE%%W$E49t~~e,tH
G5IALLO!EJJ/!6g&6&6<">>%**-D*4aIKJ"..u||<
UHj+uMMLL))'!)<=dD%88r$   c                     | j                   sP	 t        j                  j                         j	                  |      }t        |      t        t        |            k  r|}|S # t
        $ r |cY S w xY wr    )r   r   r)   r*   bestrelpathOSErrorr   r   )r   r)   nps      r   r6  zFormattedExcinfo._makepath8  s^    ||WW]]_006 2wSY'	  s   -A A-,A-c                    |j                   }| j                  r |j                         }d }|j                  t              r(dt        |j                        v r |j                         }|d   }g }d }t        |      D ]>  \  }}||k(  xr |xs d }	| j                  ||	      }
|j                  |
       ||k(  s<d} n t        ||| j                        S )Nz maximum recursion depth exceededr   z/!!! Recursion detected (same locals & position))r   )r   r   r   r   RuntimeErrorr   r   r   r   r<  rd   ReprTracebackr   )r   r!  r   r   lastentries	extralineindexr   einfo	reprentrys              r   repr_tracebackzFormattedExcinfo.repr_tracebackB  s    %%	==(	((*I  .1S5GG!9!9!9!;}	%i0 	LE5U]/74E11%?INN9%&M		 WitzzBBr$   c                 \    | j                  |      }|j                         }t        ||      S r    )rJ  r   r   )r   r!  reprtraceback	reprcrashs       r   r   zFormattedExcinfo.repr_excinfoV  s-    ++G4))+	 	::r$   )Frq   TTF)r   NF)r  Fr    )r?   r@   rA   rB   r  r(  r   r  r  r  r  r#  r  r4  r<  r6  rJ  r   r&   r$   r   r   r     sS    JKK/57<.#&,
%.9@C(;r$   r   c                       e Zd Zd Zd Zd Zy)TerminalReprc                 t    | j                         }t        j                  d   dk  r|j                  d      }|S )Nr   r   zutf-8)r  r   version_infoencode)r   r  s     r   r   zTerminalRepr.__str__\  s6    A"!Ar$   c                     t         j                  j                         }t         j                  j                  |      }| j	                  |       |j                         j                         S )N)file)r   r]   TextIOTerminalWriter
toterminalgetvaluer   )r   r]   tws      r   r  zTerminalRepr.__unicode__b  sK     UU\\^UU!!r!*{{}""$$r$   c                 6    d| j                   t        |       fz  S )Nz<%s instance at %0x>)r   r   r6   s    r   rz   zTerminalRepr.__repr__j  s    %4'AAAr$   N)r?   r@   rA   r   r  rz   r&   r$   r   rO  rO  [  s    %Br$   rO  c                        e Zd Zd ZddZd Zy)r   c                 .    || _         || _        g | _        y r    )rL  rM  sections)r   rL  rM  s      r   r   zReprExceptionInfo.__init__o  s    *"r$   c                 @    | j                   j                  |||f       y r    )r]  rd   )r   r   contentseps       r   
addsectionzReprExceptionInfo.addsectiont  s    dGS12r$   c                     | j                   j                  |       | j                  D ])  \  }}}|j                  ||       |j	                  |       + y r    )rL  rW  r]  r`  r   )r   rY  r   r_  r`  s        r   rW  zReprExceptionInfo.toterminalw  sJ    %%b)"&-- 	D'3FF3GGG	r$   N)-)r?   r@   rA   r   ra  rW  r&   r$   r   r   r   n  s    
3r$   r   c                       e Zd ZdZd Zd Zy)rC  _ c                 .    || _         || _        || _        y r    )reprentriesrF  r   )r   rg  rF  r   s       r   r   zReprTraceback.__init__  s    &"
r$   c                    d }t        | j                        D ]  \  }}|j                  dk(  r|j                  d       |j	                  |       |t        | j                        dz
  k  sS| j                  |dz      }|j                  dk(  s |j                  dk(  s|j                  dk(  s|j                  | j                          | j                  r|j                  | j                         y y )Nrq   rO   r   rp   )	r   rg  r   r   rW  r   r`  entryseprF  )r   rY  
last_styler   r   
next_entrys         r   rW  zReprTraceback.toterminal  s    
!$"2"23 	*HAu{{f$R 3t''(1,,!--ac2
;;&(;;')j.>.>&.HFF4==)	* >>GGDNN# r$   N)r?   r@   rA   ri  r   rW  r&   r$   r   rC  rC  }  s    H
$r$   rC  c                       e Zd Zd Zy)r   c                 B    d| _         t        |      g| _        d | _        y )Nr   )r   ReprEntryNativerg  rF  r   tbliness     r   r   zReprTracebackNative.__init__  s     
+G45r$   N)r?   r@   rA   r   r&   r$   r   r   r     s    r$   r   c                       e Zd ZdZd Zd Zy)rn  r   c                     || _         y r    r   ro  s     r   r   zReprEntryNative.__init__  s	    
r$   c                 X    |j                  dj                  | j                               y )NrO   )writer   r   )r   rY  s     r   rW  zReprEntryNative.toterminal  s    
$%r$   N)r?   r@   rA   r   r   rW  r&   r$   r   rn  rn    s    E&r$   rn  c                   "    e Zd ZdZd Zd Zd Zy)r7  re  c                 J    || _         || _        || _        || _        || _        y r    )r   reprfuncargs
reprlocalsreprfilelocr   )r   r   rx  ry  r:  r   s         r   r   zReprEntry.__init__  s'    
($&
r$   c                 z   | j                   dk(  rR| j                  j                  |       | j                  D ]'  }|j	                  d      }|j                  |d|       ) y | j                  r| j                  j                  |       | j                  D ]'  }|j	                  d      }|j                  |d|       ) | j                  r,|j                  d       | j                  j                  |       | j                  r9| j                  r|j                  d       | j                  j                  |       y y )Nrp   zE   T)boldredrO   )r   rz  rW  r   r   r   rx  ry  )r   rY  r   r}  s       r   rW  zReprEntry.toterminal  s   :: ''+

 2oof-4S12 ((,JJ 	.D//&)CGGDtG-	. ??GGBKOO&&r*zz''+ r$   c                 p    dj                  | j                        d| j                  d| j                  S )Nr&  )r   r   ry  rz  r6   s    r   r   zReprEntry.__str__  s,    #yy4##//1 	1r$   N)r?   r@   rA   	localssepr   rW  r   r&   r$   r   r7  r7    s    I,,1r$   r7  c                       e Zd Zd Zd Zy)r   c                 @    t        |      | _        || _        || _        y r    )r   r)   rI   r9  )r   r)   rI   r9  s       r   r   zReprFileLocation.__init__  s    I	r$   c                     | j                   }|j                  d      }|dk7  r|d | }|j                  | j                  d| j                  d|       y )Nr&  r   :z: )r9  findr   r)   rI   )r   rY  r   r   s       r   rW  zReprFileLocation.toterminal  sG     llHHTN7bq'C
diic:;r$   Nr?   r@   rA   r   rW  r&   r$   r   r   r     s    
<r$   r   c                       e Zd Zd Zd Zy)r1  c                     || _         y r    rs  )r   r   s     r   r   zReprLocals.__init__  s	    
r$   c                 H    | j                   D ]  }|j                  |        y r    )r   r   )r   rY  r   s      r   rW  zReprLocals.toterminal  s     JJ 	DGGDM	r$   Nr  r&   r$   r   r1  r1    s    r$   r1  c                       e Zd Zd Zd Zy)r  c                     || _         y r    )r  )r   r  s     r   r   zReprFuncArgs.__init__  s	    	r$   c                 4   | j                   rd}| j                   D ]V  \  }}|d|}t        |      t        |      z   dz   |j                  kD  r|r|j                  |       |}J|r	|d|z   z  }U|}X |r|j                  |       |j                  d       y y )NrO   r/  r   z, )r  r   	fullwidthr   )r   rY  	linesofarr   r   nss         r   rW  zReprFuncArgs.toterminal  s    99I#yy 
'e!%u-r7S^+a/",,> 	*!#I !TBY.	$&	
' 	"GGBK r$   Nr  r&   r$   r   r  r    s    r$   r  c                    | rxddl m}  t        j                  dg       }|j	                  t
        j                  j                  j                         | j                  t
        j                  j                  _        |rt        j                  dg       }|j	                  t
        j                  j                  j                         t
        j                  j                  t
        j                  j                  _	        yy)z? put compile and AssertionError builtins to Python's builtins. r   )	assertionr   compileN)r/   r  oldbuiltinsr   rd   r   rY   builtinsr   r  r   )r  r  r   s      r   patch_builtinsr    s    &""#3R8	$$334-6-E-E

*""9b1	$$,,-&(ggoo

# r$   c                     | r4t         d   j                         t        j                  j                  _        |r5t         d   j                         t        j                  j                  _        yy)zB remove compile and AssertionError builtins from Python builtins. r   r  N)r  popr   rY   r  r   r  )r  r  s     r   unpatch_builtinsr    sN    -89I-J-N-N-P

*&1)&<&@&@&B

# r$   c                 >   	 | j                   S # t        $ r t        | d|       } t        | d|       } t        | d|       } t        | d|       } |rJt        | d      s>t        | d      r2t	        |       s't        | j                  d      }t        |d      r|cY S | cY S w xY w)	z( return code object for given function. im_func	func_coderL   __code__r   __call__F)trycall)r  r   r   r   r   r   r  )r  r  r   s      r   r   r     s    || 
c9c*c;,c8S)c:s+73(89sJ's||U;1./H

s    BBBB)TT)T)&r   r   inspectr   r   r   r   builtin_reprrY   
_tryimportr   rQ  r   r	   py._code._py2tracebackr`   r   rE   ri   r   r   r  r   r   r   rO  r   rC  r   rn  r7  r   r1  r  r  r  r  r   r&   r$   r   <module>r     s8   	 
 7 7
**

	
2A!/< 9*6 9*v:F :zoEV oEdX Xt K V!F V!rh;v h;TB B& $L $0- &l &#1 #1J<| < < 0 
6Cr$   