a
    ܌xdo                     @   st  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Zd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dl%m&Z& d dl'Z'd dl(Z(d dl)m*Z* d dl)m+Z+ d dl)m,Z, d d l)m-Z- d d!l.m/Z/ d d"l0m1Z1 d d#l0m2Z2 d d$l3m4Z4 d d%l3m5Z5 d d&l6m7Z7 d d'l8m9Z9 d d(l8m:Z: e"rNd d)l;m<Z< d d*l;m=Z= d d+l%m>Z> e<d, Z?ej@dd- d.k rnd d/lAmBZB G d0d1 d1ZCG d2d3 d3ZDG d4d5 d5ZEG d6d7 d7eeE ZFe#d8eGd9d:ZHe4ejIG d;d< d<eeH ZJejIG d=d> d>ZKejId?d@G dAdB dBZLejId?d@G dCdD dDeLZMejId?d@G dEdF dFeMZNejId?d@G dGdH dHeMZOejId?d@G dIdJ dJeLZPG dKdL dLePZQejId?d@G dMdN dNeLZRejId?d@G dOdP dPeLZSejId?d@G dQdR dReLZTejId?d@G dSdT dTeLZUejId?d@G dUdV dVeLZVeWe e$eXef eYf dWdXdYZZee'j[\dZZ]e]j^d[krTe]j_Z]ee(j[j_Z`eEead\d]d^ZbdS )_    N)
CO_VARARGS)CO_VARKEYWORDS)StringIO)Path)format_exception_only)CodeType)	FrameType)TracebackType)Any)Callable)ClassVar)Dict)Generic)Iterable)List)Mapping)Optional)overload)Pattern)Sequence)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union)ref)
findsource
getrawcode)getstatementrange_ast)Source)TerminalWriter)
safeformatsaferepr)final)get_real_func)check_ispytest)absolutepath)bestrelpath)Literal)SupportsIndex)ReferenceType)longshortlinenonativevalueauto   )      )BaseExceptionGroupc                   @   s   e Zd ZdZdZeddddZeed dddZ	d	d
 Z
dZeedddZeedddZeeeef dddZeed dddZddddZdeeedf dddZdS )Codez#Wrapper around Python code objects.rawNobjreturnc                 C   s
   || _ d S Nr:   )selfr=    rA   J/var/www/html/Ranjet/env/lib/python3.9/site-packages/_pytest/_code/code.py__init__D   s    zCode.__init__c                 C   s   | t |S r?   r   )clsr=   rA   rA   rB   from_functionG   s    zCode.from_functionc                 C   s   | j |j kS r?   r:   )r@   otherrA   rA   rB   __eq__K   s    zCode.__eq__r>   c                 C   s   | j jd S N   )r;   co_firstlinenor@   rA   rA   rB   firstlinenoQ   s    zCode.firstlinenoc                 C   s   | j jS r?   )r;   co_namerL   rA   rA   rB   nameU   s    z	Code.namec                 C   sN   | j jsdS z"t| j j}| s*td|W S  tyH   | j j Y S 0 dS )zoReturn a path object pointing to source code, or an ``str`` in
        case of ``OSError`` / non-existing file. zpath check failed.N)r;   co_filenamer)   existsOSError)r@   prA   rA   rB   pathY   s    z	Code.pathr!   c                 C   s   t | j\}}|S )zJReturn a _pytest._code.Source object for the full source file of the code.)r   r;   )r@   full_rA   rA   rB   
fullsourcej   s    zCode.fullsourcec                 C   s
   t | jS )zGReturn a _pytest._code.Source object for the code object's source only.)r!   r;   rL   rA   rA   rB   sourcep   s    zCode.sourceF.)varr>   c                 C   s:   | j }|j}|r,||jt@ 7 }||jt@ 7 }|jd| S )zReturn 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@   rZ   r;   ZargcountrA   rA   rB   getargsu   s    zCode.getargs)F)__name__
__module____qualname____doc__	__slots__r   rC   classmethodobjectrE   rG   __hash__propertyintrM   strrO   r   r   rU   r   rX   rY   boolr   r^   rA   rA   rA   rB   r9   ?   s"   r9   c                   @   s   e Zd ZdZdZeddddZeeddd	Z	ee
eef dd
dZee
eef dddZeedddZeddddZdd ZeedddZdedddZdS )FramezgWrapper around a Python frame holding f_locals and f_globals
    in which expressions can be evaluated.r:   N)framer>   c                 C   s
   || _ d S r?   r:   )r@   rl   rA   rA   rB   rC      s    zFrame.__init__rH   c                 C   s   | j jd S rI   )r;   f_linenorL   rA   rA   rB   lineno   s    zFrame.linenoc                 C   s   | j jS r?   )r;   	f_globalsrL   rA   rA   rB   ro      s    zFrame.f_globalsc                 C   s   | j jS r?   )r;   f_localsrL   rA   rA   rB   rp      s    zFrame.f_localsc                 C   s   t | jjS r?   )r9   r;   f_coderL   rA   rA   rB   code   s    z
Frame.coder!   c                 C   s$   | j jdu rtdS | j j| jS )zStatement this frame is at.NrP   )rr   rX   r!   getstatementrn   rL   rA   rA   rB   	statement   s    zFrame.statementc                 K   s"   | j  }|| t|| j|S )zEvaluate 'code' in the frame.

        'vars' are optional additional local variables.

        Returns the result of the evaluation.
        )rp   copyupdateevalro   )r@   rr   varsrp   rA   rA   rB   rw      s    

z
Frame.eval)re   r>   c                 C   s   t |S )zCReturn a 'safe' (non-recursive, one-line) string repr for 'object'.r$   )r@   re   rA   rA   rB   repr   s    z
Frame.reprFrZ   c              	   C   sF   g }| j |D ]0}z||| j| f W q ty>   Y q0 q|S )zReturn a list of tuples (name, value) for all arguments.

        If 'var' is set True, also include the variable and keyword arguments
        when present.
        )rr   r^   appendrp   KeyError)r@   rZ   retvalargrA   rA   rB   r^      s    zFrame.getargs)F)r_   r`   ra   rb   rc   r   rC   rg   rh   rn   r   ri   r
   ro   rp   r9   rr   rt   rw   re   ry   rj   r^   rA   rA   rA   rB   rk      s    rk   c                   @   s6  e Zd ZdZdZd'eed ddddZee	dd	d
Z
dddddZeedddZee	dddZedddZeddddZeeeef dddZeeeef dddZe	dddZd(eeeeef ejf  ed ddd ZeeZedd!d"Zedd#d$Zeedd%d&Z dS ))TracebackEntryzA single entry in a Traceback.	_rawentry_excinfo_repr_styleN+ReferenceType[ExceptionInfo[BaseException]])rawentryexcinfor>   c                 C   s   || _ || _d | _d S r?   r   )r@   r   r   rA   rA   rB   rC      s    zTracebackEntry.__init__rH   c                 C   s   | j jd S rI   )r   	tb_linenorL   rA   rA   rB   rn      s    zTracebackEntry.linenozLiteral['short', 'long'])moder>   c                 C   s   |dv sJ || _ d S )Nr/   r.   )r   )r@   r   rA   rA   rB   set_repr_style   s    zTracebackEntry.set_repr_stylec                 C   s   t | jjS r?   )rk   r   tb_framerL   rA   rA   rB   rl      s    zTracebackEntry.framec                 C   s   | j | jjj S r?   )rn   rl   rr   rM   rL   rA   rA   rB   relline   s    zTracebackEntry.rellinec                 C   s   d| j jj| jd f S )Nz<TracebackEntry %s:%d>rJ   )rl   rr   rU   rn   rL   rA   rA   rB   __repr__   s    zTracebackEntry.__repr__r!   c                 C   s"   | j jj}|dusJ || jS )z6_pytest._code.Source object for the current statement.N)rl   rr   rX   rs   rn   )r@   rY   rA   rA   rB   rt      s    
zTracebackEntry.statementc                 C   s
   | j jjS )zPath to the source code.)rl   rr   rU   rL   rA   rA   rB   rU      s    zTracebackEntry.pathc                 C   s   | j jS )zLocals of underlying frame.)rl   rp   rL   rA   rA   rB   locals   s    zTracebackEntry.localsc                 C   s
   | j jjS r?   )rl   rr   rM   rL   rA   rA   rB   getfirstlinesource   s    z!TracebackEntry.getfirstlinesource)astcacher>   c                 C   s   | j jj}|du rdS d }}|durD| j jj}|durD||d}|  }zt| j||d\}}}W n ty   | jd }Y n0 |dur|dur|||< ||| S )zReturn failing source code.N)astnoderJ   )	rl   rr   rX   rU   getr   r    rn   SyntaxError)r@   r   rY   keyr   startrW   endrA   rA   rB   	getsource   s$    

zTracebackEntry.getsourcec              	   C   sh   d}| j j| j jfD ](}z|d }W n ty6   Y q0  q>q|rdt|rd|| jdu rZdn|  S |S )a  Return True if the current frame has a var __tracebackhide__
        resolving to True.

        If __tracebackhide__ is a callable, it gets called with the
        ExceptionInfo instance and can decide whether to hide the traceback.

        Mostly for internal use.
        F__tracebackhide__N)rl   rp   ro   	Exceptioncallabler   )r@   ZtbhZmaybe_ns_dctrA   rA   rB   ishidden  s    zTracebackEntry.ishiddenc                 C   sb   | j jj}zt| j }W n( ty0    Y n tyD   d}Y n0 dt| j| j	d ||f S )N???z  File %r:%d in %s
  %s
rJ   )
rl   rr   rO   ri   rt   lstripKeyboardInterruptBaseExceptionrU   rn   )r@   rO   r0   rA   rA   rB   __str__.  s    

zTracebackEntry.__str__c                 C   s   | j jjjS )zco_name of underlying code.)rl   rr   r;   rN   rL   rA   rA   rB   rO   @  s    zTracebackEntry.name)N)N)!r_   r`   ra   rb   rc   r	   r   rC   rg   rh   rn   r   rk   rl   r   ri   r   rt   r   r   rU   r   r
   r   r   astASTr   rY   rj   r   r   rO   rA   rA   rA   rB   r      sB    	 r   c                       s   e Zd ZdZdeeee f ed dd fddZ	deede
f  ee ee ed d dd	d
ZededddZeed dddZedef eed f d fddZdd feegef d dddZedddZee dddZ  ZS )	TracebackzQTraceback objects encapsulate and offer higher level access to Traceback entries.Nr   )tbr   r>   c                    sJ    | _ t|tr:ttt d fdd}t || nt | dS )z@Initialize from given python traceback object and ExceptionInfo.)curr>   c                 3   s&   | }|d ur"t | dV  |j}qd S )Nr   )r   tb_next)r   cur_r   rA   rB   fR  s    zTraceback.__init__.<locals>.fN)r   
isinstancer	   r   r   superrC   )r@   r   r   r   	__class__r   rB   rC   I  s
    
zTraceback.__init__zos.PathLike[str])rU   rn   rM   excludepathr>   c           
      C   s   |du rdnt |}|du r"dnt |}| D ]}|jj}|j}	|durXt|	|krXq0|durt|	tr|dd |	jD v rq0|dur|j	|krq0|dur|jjj
|krq0t|j| j  S | S )a  Return a Traceback instance wrapping part of this Traceback.

        By providing 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).
        Nc                 s   s   | ]}t |V  qd S r?   )ri   ).0rT   rA   rA   rB   	<genexpr>v      z Traceback.cut.<locals>.<genexpr>)osfspathrl   rr   rU   ri   r   r   parentsrn   rM   r   r   r   )
r@   rU   rn   rM   r   Zpath_Zexcludepath_xrr   ZcodepathrA   rA   rB   cut\  s(    zTraceback.cutr,   )r   r>   c                 C   s   d S r?   rA   r@   r   rA   rA   rB   __getitem__  s    zTraceback.__getitem__c                 C   s   d S r?   rA   r   rA   rA   rB   r     s    c                    s,   t |tr| t |S t |S d S r?   )r   slicer   r   r   r   r   rA   rB   r     s    
c                 C   s
   |    S r?   )r   )r   rA   rA   rB   <lambda>  r   zTraceback.<lambda>)fnr>   c                 C   s   t t|| | jS )ac  Return a Traceback instance with certain items removed

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

        By default this removes all the TracebackEntries which are hidden
        (see ishidden() above).
        )r   filterr   )r@   r   rA   rA   rB   r     s    zTraceback.filterrH   c                 C   s<   t dt|  d dD ]}| | }| s|  S q| d S )zQReturn last non-hidden traceback entry that lead to the exception of a traceback.rJ   )rangelenr   )r@   ientryrA   rA   rB   getcrashentry  s
    
zTraceback.getcrashentryc           	      C   s~   i }t | D ]l\}}|jjjt|jjj|jf}||g }|rj|j}|j}|D ]}||krP|    S qP|	|jj qdS )z~Return the index of the frame/TracebackEntry where recursion originates if
        appropriate, None if no recursion occurred.N)
	enumeraterl   rr   rU   idr;   rn   
setdefaultrp   r{   )	r@   cacher   r   r   valuesr   locZotherlocrA   rA   rB   recursionindex  s    zTraceback.recursionindex)N)NNNN)r_   r`   ra   rb   r   r	   r   r   r   rC   ri   rh   r   r   r   r   r   rj   r   r   r   __classcell__rA   rA   r   rB   r   F  s@        $

	r   ET)bound	covariantc                
   @   s  e Zd ZU dZdZeed< eee	d de
f  ed< eed< ee ed< d@d
deee	d de
f  eee ed	dddZedAee	e ee
f ee ddddZedBee ddddZeddddZee	e ee
f d	dddZee	e dddZeeddd Zee
dd!d"Zeedd#d$Zeedd%d&Zejed	d'd(d&Zedd)d*ZdCeed+d,d-Zee	e ee	e d.f f ed/d0d1Z d2dd3d4Z!dDed7eeeeeed8 d9d:d;Z"eee#e f d<d=d>d?Z$d	S )EExceptionInfozJWraps sys.exc_info() objects and offers help for navigating the traceback.zAssertionError('assert _assert_start_reprr   r   
_striptext
_tracebackrP   NF	_ispytest)r   	striptext	tracebackr   r>   c                C   s   t | || _|| _|| _d S r?   )r(   r   r   r   )r@   r   r   r   r   rA   rA   rB   rC     s    zExceptionInfo.__init__zExceptionInfo[E])exc_infoexprinfor>   c                 C   s`   d}|du rRt |d trRt|d dd}|du r>t|d }|rR|| jrRd}| ||ddS )a=  Return an ExceptionInfo for an existing exc_info tuple.

        .. warning::

            Experimental API

        :param exprinfo:
            A text string helping to determine if we should strip
            ``AssertionError`` from the output. Defaults to the exception
            message/``__str__()``.
        rP   NrJ   msgzAssertionError: Tr   )r   AssertionErrorgetattrr%   
startswithr   )rD   r   r   r   rA   rA   rB   from_exc_info  s    zExceptionInfo.from_exc_infozExceptionInfo[BaseException])r   r>   c                 C   sf   t  }|d dusJ d|d dus0J d|d dusDJ d|d |d |d f}t||S )a=  Return an ExceptionInfo matching the current traceback.

        .. warning::

            Experimental API

        :param exprinfo:
            A text string helping to determine if we should strip
            ``AssertionError`` from the output. Defaults to the exception
            message/``__str__()``.
        r   Nzno current exceptionrJ   r5   )sysr   r   r   )rD   r   tupr   rA   rA   rB   from_current  s    zExceptionInfo.from_currentrH   c                 C   s   | dddS )z!Return an unfilled ExceptionInfo.NTr   rA   )rD   rA   rA   rB   	for_later  s    zExceptionInfo.for_later)r   r>   c                 C   s   | j du sJ d|| _ dS )z<Fill an unfilled ExceptionInfo created with ``for_later()``.Nz ExceptionInfo was already filledr   )r@   r   rA   rA   rB   fill_unfilled  s    zExceptionInfo.fill_unfilledc                 C   s   | j dusJ d| j d S )zThe exception class.Nz6.type can only be used after the context manager exitsr   r   rL   rA   rA   rB   type  s
    zExceptionInfo.typec                 C   s   | j dusJ d| j d S )zThe exception value.Nz7.value can only be used after the context manager exitsrJ   r   rL   rA   rA   rB   r3     s
    zExceptionInfo.valuec                 C   s   | j dusJ d| j d S )zThe exception raw traceback.Nz4.tb can only be used after the context manager exitsr5   r   rL   rA   rA   rB   r   "  s
    zExceptionInfo.tbc                 C   s   | j dusJ d| jjS )zThe type name of the exception.Nz:.typename can only be used after the context manager exits)r   r   r_   rL   rA   rA   rB   typename*  s
    zExceptionInfo.typenamec                 C   s$   | j du rt| jt| d| _ | j S )zThe traceback.Nr   )r   r   r   r   rL   rA   rA   rB   r   2  s    
zExceptionInfo.traceback)r3   r>   c                 C   s
   || _ d S r?   )r   )r@   r3   rA   rA   rB   r   9  s    c                 C   s0   | j d u rdS d| jjt| j d t| jS )Nz)<ExceptionInfo for raises contextmanager>z<{} {} tblen={}>rJ   )r   formatr   r_   r%   r   r   rL   rA   rA   rB   r   =  s
    
zExceptionInfo.__repr__)tryshortr>   c                 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 an
        AssertionError, only the actual exception part of the exception
        representation is returned (so 'AssertionError: ' is removed from
        the beginning).
        rP   N)r   r   r3   joinrstripr   r   r   )r@   r   linestextrA   rA   rB   exconlyD  s    
zExceptionInfo.exconly.)excr>   c                 C   s   t | j|S )zReturn True if the exception is an instance of exc.

        Consider using ``isinstance(excinfo.value, exc)`` instead.
        )r   r3   )r@   r   rA   rA   rB   errisinstanceT  s    zExceptionInfo.errisinstanceReprFileLocationc                 C   s:   | j dd}| j }|jjjj|j }}t||d |S )NTr   rJ   )	r   r   r   rl   rr   r;   rQ   rn   r   )r@   r   r   rU   rn   rA   rA   rB   _getreprcrash]  s    
zExceptionInfo._getreprcrashr.   T_TracebackStyle)ReprExceptionInfoExceptionChainRepr)
showlocalsstyleabspathtbfilterfuncargstruncate_localschainr>   c           	   	   C   sR   |dkr2t tt| j| j| jd j|  dS t|||||||d}|	| S )a  Return str()able representation of this exception info.

        :param bool showlocals:
            Show locals per traceback entry.
            Ignored if ``style=="native"``.

        :param str style:
            long|short|no|native|value traceback style.

        :param bool abspath:
            If paths should be changed to absolute or left unchanged.

        :param bool tbfilter:
            Hide entries that contain a local variable ``__tracebackhide__==True``.
            Ignored if ``style=="native"``.

        :param bool funcargs:
            Show fixtures ("funcargs" for legacy purposes) per traceback entry.

        :param bool truncate_locals:
            With ``showlocals==True``, make sure locals can be safely represented as strings.

        :param bool chain:
            If chained exceptions in Python 3 should be shown.

        .. versionchanged:: 3.9

            Added the ``chain`` parameter.
        r2   r   reprtraceback	reprcrash)r   r   r   r   r   r   r   )
r   ReprTracebackNativer   format_exceptionr   r3   r   r   FormattedExcinforepr_excinfo)	r@   r   r   r   r   r   r   r   fmtrA   rA   rB   getreprc  s&    '		zExceptionInfo.getreprzLiteral[True])regexpr>   c                 C   sF   d}t | j}d|d|}||kr.|d7 }t||sBJ |dS )zCheck whether the regular expression `regexp` matches the string
        representation of the exception using :func:`python:re.search`.

        If it matches `True` is returned, otherwise an `AssertionError` is raised.
        Tz%Regex pattern did not match.
 Regex: z	
 Input: z*
 Did you mean to `re.escape()` the regex?)ri   r3   research)r@   r  r   r3   r   rA   rA   rB   match  s    
zExceptionInfo.match)rP   N)N)N)F)Fr.   FTFTT)%r_   r`   ra   rb   r   r   __annotations__r   r   r   r	   ri   r   rj   rC   rd   r   r   r   r   r   rg   r   r3   r   r   r   setterr   r   r   r   r   r   r  r   r  rA   rA   rA   rB   r     s   
    	       <r   c                   @   s  e Zd ZU dZdZeed< dZeed< dZe	ed< dZ
d	ed
< dZe	ed< dZe	ed< dZe	ed< dZe	ed< dZe	ed< ejedddZeeeef ejf ed< dedddZeed dddZeed dddZd;ed eee e!  e	e"e dd d!Z#d<e e! ee	e"e d#d$d%Z$e%ee&f ed& d'd(d)Z'd=eee e!  d*d+d,d-Z(eeef ed.d/d0Z)e e! d1d2d3d4Z*e+e,e+ee f d5d6d7Z-e e! d8d2d9d:Z.dS )>r   z>Presenting information about failing Functions and Generators.>flow_markerr   fail_markerFr   r.   r   r   Tr   r   r   r   r   )default_factoryinitry   r   r!   )rY   r>   c                 C   s   zt |t|d }W n^ ty.    Y nL tyx   zt |d }W n( ty^    Y n tyr   Y Y dS 0 Y n0 dt|t|   S )NrJ   r   r      )ri   rs   r   r   r   r   )r@   rY   srA   rA   rB   
_getindent  s    zFormattedExcinfo._getindentr   r>   c                 C   s    | | j}|d ur| }|S r?   )r   r   Zdeindent)r@   r   rY   rA   rA   rB   _getentrysource  s    z FormattedExcinfo._getentrysourceReprFuncArgsc                 C   s@   | j r<g }|jjddD ]\}}||t|f qt|S d S )NTrz   )r   rl   r^   r{   r%   r  )r@   r   argsargnameZargvaluerA   rA   rB   	repr_args  s    zFormattedExcinfo.repr_argsr   N)rY   
line_indexr   r/   r>   c           	      C   s  g }|dur |dk r |t |7 }|du s>|t |jks>|dk rJtd}d}d}|rl|||j|    nb|jd| D ]}|||  qz|| jd |j|   |j|d d D ]}|||  q|dur|rdn| |}|| j||dd	 |S )
z,Return formatted and marked up source lines.Nr   r   z       rJ   r  T)indentmarkall)	r   r   r!   r{   stripr  r  extendget_exconly)	r@   rY   r  r   r/   r   Zspace_prefixr0   r  rA   rA   rB   
get_source  s$    zFormattedExcinfo.get_sourcer  )r   r  r  r>   c           	      C   sT   g }d| }|j ddd}| j|dd   }|D ]}|||  |s4|}q4|S )N Tr   
rJ   )r   splitr  r{   )	r@   r   r  r  r   Z	indentstrZexlinesZ
failindentr0   rA   rA   rB   r    s    zFormattedExcinfo.get_exconly
ReprLocals)r   r>   c                 C   s   | j r|g }dd |D }|  |D ]N}|| }|dkrD|d q$| jrTt|}nt|}||dd|  q$t|S d S )Nc                 S   s   g | ]}|d  dkr|qS )r   @rA   )r   r   rA   rA   rB   
<listcomp>  r   z0FormattedExcinfo.repr_locals.<locals>.<listcomp>__builtins__z__builtins__ = <builtins>z<10 = )r   sortr{   r   r%   r#   r#  )r@   r   r   keysrO   r3   Zstr_reprrA   rA   rB   repr_locals  s    
zFormattedExcinfo.repr_locals	ReprEntry)r   r   r>   c                 C   sF  g }|j d ur|j n| j}|dv r| |}|d u rBtd}d}n|j|  }|dk}|sf| |nd }| j||||d}	||	 |rd|j	 }
n|r|j
pd}
|j}| |}t||jd |
}| |j}t|||||S |d	kr|r|t|jd
 t|d d d |S |r2|| j|dd t|d d d |S d S )Nr   r   r   r/   )r/   zin %srP   rJ   r3   r!  r  r  )r   r   r  r!   rn   r   r  r  r  rO   r   rU   	_makepathr   r*  r   r+  ri   r3   r"  r  )r@   r   r   r   r   rY   r  r/   Zreprargsr  message
entry_pathrU   reprfilelocZ
localsreprrA   rA   rB   repr_traceback_entry(  s6    



z%FormattedExcinfo.repr_traceback_entry)rU   r>   c                 C   s^   | j sVt|trVztt |}W n ty<   t| Y S 0 t|tt|k rV|S t|S r?   )r   r   r   r*   cwdrS   ri   r   )r@   rU   nprA   rA   rB   r-  L  s    zFormattedExcinfo._makepathReprTraceback)r   r>   c           
      C   s   |j }| jr| }t|jtr0| |\}}nd }|d }g }| jdkrp| ||}|	| t
|d | jdS t|D ].\}}||kr|pd }	| ||	}|	| qxt
||| jdS )Nr   r3   )r   )r   r   r   r   r3   RecursionError_truncate_recursive_tracebackr   r1  r{   r4  r   )
r@   r   r   	extralinelastentriesZ	reprentryindexr   ZeinforA   rA   rB   repr_tracebackV  s"    

zFormattedExcinfo.repr_traceback)r   r>   c              
   C   s   z|  }W nb tyn } zJd}djt|jt||t|d}|d| || d  }W Y d}~n,d}~0 0 |durd}|d|d  }nd}||fS )aK  Truncate the given recursive traceback trying to find the starting
        point of the recursion.

        The detection is done by going through each traceback entry and
        finding the point in which the locals of the frame are equal to the
        locals of a previous frame (see ``recursionindex()``).

        Handle the situation where the recursion process might raise an
        exception (for example comparing numpy arrays using equality raises a
        TypeError), in which case we do our best to warn the user of the
        error and show a limited traceback.
        
   a  !!! Recursion error detected, but an error occurred locating the origin of recursion.
  The following exception happened when comparing locals in the stack frame:
    {exc_type}: {exc_msg}
  Displaying first and last {max_frames} stack frames out of {total}.)exc_typeZexc_msg
max_framestotalNz/!!! Recursion detected (same locals & position)rJ   )r   r   r   r   r_   ri   r   )r@   r   r   er>  r7  rA   rA   rB   r6  m  s"    0z.FormattedExcinfo._truncate_recursive_tracebackr   c           	      C   sX  g }|j }|}d }t }|d urHt||vrH|t| |rt|trpttt	|j |j |jd j
}n
| |}| jdkr| nd }nttt	||d }d }||||fg7 }|jd ur| jr|j}|jrtt	|||jfnd }d}q|jd urB|jsB| jrB|j}|jr8tt	|||jfnd }d}qd }q|  t|S )Nr   r3   zDThe above exception was the direct cause of the following exception:zCDuring handling of the above exception, another exception occurred:)r3   setr   addr   r8   r   r   r   r   r   r;  r   r   	__cause__r   __traceback__r   r   __context____suppress_context__reverser   )	r@   r   Z
repr_chainr@  Zexcinfo_descrseenr   r   rA   rA   rB   r    s`    



zFormattedExcinfo.repr_excinfo)r   NF)r  F)N)/r_   r`   ra   rb   r  r   r  r  r   rj   r   r   r   r   r   r   dataclassesfielddictr   r   r   ri   r   r   r   rh   r  r   r   r  r  r   r   r   r  r  r   re   r*  r1  r-  r;  r   r   r6  r  rA   rA   rA   rB   r     sb   
    
!   
$
+r   F)eqc                   @   s8   e Zd ZedddZedddZedddd	ZdS )
TerminalReprrH   c                 C   s&   t  }t|d}| | |  S )N)file)r   r"   
toterminalgetvaluer  )r@   iotwrA   rA   rB   r     s    

zTerminalRepr.__str__c                 C   s   d| j  dt| ddS )N<z instance at 0xr
  )r   r   rL   rA   rA   rB   r     s    zTerminalRepr.__repr__NrS  r>   c                 C   s
   t  d S r?   )NotImplementedErrorr@   rS  rA   rA   rB   rP    s    zTerminalRepr.toterminal)r_   r`   ra   ri   r   r   r"   rP  rA   rA   rA   rB   rN    s   rN  c                   @   sl   e Zd ZU ded< ed ed< ejdedZe	e
eeef  ed< deeed	d
ddZed	dddZd	S )ExceptionReprr4  r   r   r   F)r  r  sections-N)rO   contentsepr>   c                 C   s   | j |||f d S r?   )rZ  r{   )r@   rO   r\  r]  rA   rA   rB   
addsection  s    zExceptionRepr.addsectionrV  c                 C   s,   | j D ] \}}}||| || qd S r?   )rZ  r]  r0   )r@   rS  rO   r\  r]  rA   rA   rB   rP    s    zExceptionRepr.toterminal)r[  )r_   r`   ra   r  r   rJ  rK  listrZ  r   r   ri   r^  r"   rP  rA   rA   rA   rB   rY    s   
rY  c                       sn   e Zd ZU eeded ee f  ed< eeded ee f  dd fddZe	dd fd	d
Z
  ZS )r   r4  r   r   N)r   r>   c                    s*   t  j|d d |d d d || _d S )Nr   r   rJ   r   )r   rC   r   )r@   r   r   rA   rB   rC     s
    

zExceptionChainRepr.__init__rV  c                    sR   | j D ]:}|d | |d d ur|d |j|d dd qt | d S )Nr   r5   rP   T)yellow)r   rP  r0   r   )r@   rS  elementr   rA   rB   rP    s    

zExceptionChainRepr.toterminal)r_   r`   ra   r   r   r   ri   r  rC   r"   rP  r   rA   rA   r   rB   r     s   
r   c                       s6   e Zd ZU ded< ded< edd fddZ  ZS )	r   r4  r   r   r   NrV  c                    s   | j | t | d S r?   )r   rP  r   rX  r   rA   rB   rP    s    zReprExceptionInfo.toterminal)r_   r`   ra   r  r"   rP  r   rA   rA   r   rB   r     s   
r   c                   @   sN   e Zd ZU eed  ed< ee ed< ded< dZe	ed< e
dd	d
dZdS )r4  )r+  ReprEntryNativereprentriesr7  r   r   z_ entrysepNrV  c                 C   s   t | jD ]p\}}|jdkr&|d || |t| jd k r
| j|d  }|jdksn|jdkr
|jdkr
|| j q
| jr|| j d S )Nr.   rP   rJ   r/   )	r   rc  r   r0   rP  r   r]  rd  r7  )r@   rS  r   r   Z
next_entryrA   rA   rB   rP  (  s    


zReprTraceback.toterminal)r_   r`   ra   r   r   r  r   ri   rd  r   r"   rP  rA   rA   rA   rB   r4     s
   
r4  c                   @   s    e Zd Zee ddddZdS )r   N)tblinesr>   c                 C   s   t |g| _d | _d| _d S )Nr2   )rb  rc  r7  r   )r@   re  rA   rA   rB   rC   <  s    zReprTracebackNative.__init__)r_   r`   ra   r   ri   rC   rA   rA   rA   rB   r   ;  s   r   c                   @   s:   e Zd ZU ee ed< dZed ed< eddddZ	dS )	rb  r   r2   r   r   NrV  c                 C   s   | d| j d S )NrP   )writer   r   rX  rA   rA   rB   rP  H  s    zReprEntryNative.toterminal)
r_   r`   ra   r   ri   r  r   r   r"   rP  rA   rA   rA   rB   rb  B  s   
rb  c                   @   st   e Zd ZU ee ed< ed ed< ed ed< ed ed< ded	< ed
dddZed
dddZ	edddZ
d
S )r+  r   r  reprfuncargsr#  
reprlocalsr   r0  r   r   NrV  c           
      C   s   | j s
dS tj d}t|}g }g }g }t| j D ]j\}}||}	|	rd|| j |d   qq4| jdkrz|| q4||d|  |||d  q4|	|| |D ]}|j
|ddd qdS )a  Write the source code portions of a list of traceback entries with syntax highlighting.

        Usually entries are lines like these:

            "     x = 1"
            ">    assert x == 2"
            "E    assert 1 == 2"

        This function takes care of rendering the "source" portions of it (the lines without
        the "E" prefix) using syntax highlighting, taking care to not highlighting the ">"
        character, as doing so might break line continuations.
        Nr  r3   Tboldred)r   r   r  r   r   r   r  r   r{   Z_write_sourcer0   )
r@   rS  r  indent_sizeindentsZsource_linesZfailure_linesr:  r0   Zis_failure_linerA   rA   rB   _write_entry_linesT  s&    

zReprEntry._write_entry_linesc                 C   s   | j dkrH| jd usJ | j| | | | jrD| jj|dd d S | jrZ| j| | | | jr|d | j| | jr| jr|d | j| d S )Nr/   z        r,  rP   )r   r0  rP  rn  rh  rg  r0   r   rX  rA   rA   rB   rP    s"    




zReprEntry.toterminalrH   c                 C   s   d d| j| j| jS )Nz{}
{}
{}r!  )r   r   r   rh  r0  rL   rA   rA   rB   r     s    zReprEntry.__str__)r_   r`   ra   r   ri   r  r   r"   rn  rP  r   rA   rA   rA   rB   r+  L  s   
,r+  c                   @   sD   e Zd ZU eed< eed< eed< ddddZeddd	d
ZdS )r   rU   rn   r.  NrH   c                 C   s   t | j| _d S r?   )ri   rU   rL   rA   rA   rB   __post_init__  s    zReprFileLocation.__post_init__rV  c                 C   sR   | j }|d}|dkr$|d | }|j| jddd |d| j d|  d S )Nr!  r   Tri  :z: )r.  findrf  rU   r0   rn   )r@   rS  r   r   rA   rA   rB   rP    s    
zReprFileLocation.toterminal)	r_   r`   ra   ri   r  rh   ro  r"   rP  rA   rA   rA   rB   r     s
   
r   c                   @   s,   e Zd ZU ee ed< deddddZdS )r#  r   rP   NrV  c                 C   s   | j D ]}|||  qd S r?   )r   r0   )r@   rS  r  r0   rA   rA   rB   rP    s    
zReprLocals.toterminal)rP   )r_   r`   ra   r   ri   r  r"   rP  rA   rA   rA   rB   r#    s   
r#  c                   @   s2   e Zd ZU eeeef  ed< eddddZ	dS )r  r  NrV  c                 C   s   | j rd}| j D ]Z\}}| d| }t|t| d |jkrT|rN|| |}q|rf|d| 7 }q|}q|rz|| |d d S )NrP   r'  r5   z, )r  r   Z	fullwidthr0   )r@   rS  Z	linesofarrO   r3   nsrA   rA   rB   rP    s    

zReprFuncArgs.toterminal)
r_   r`   ra   r   r   ri   re   r  r"   rP  rA   rA   rA   rB   r    s   
r  r<   c                 C   s   t | } t| dr| j} zt| }W n ty   zt| pHt| }W n tyb   Y Y dS 0 |rpt	|prd}d}|rzt
| \}}W n ty   Y n0 ||f Y S 0 |j|jfS )zReturn source location (path, lineno) for the given object.

    If the source cannot be determined return ("", -1).

    The line number is 0-based.
    place_as)rP   r   rP   r   )r'   hasattrrs  r9   rE   	TypeErrorinspectgetsourcefilegetfiler)   r   rS   rU   rM   )r=   rr   r   r   rn   rW   rA   rA   rB   getfslineno  s&    


ry  ocz__init__.pyr  c                 C   sP   | j jjj}d|v od|v }|r$dS t| j}|j}t|v r@dS t|v rLdS dS )a   Return True if a TracebackEntry instance should be included in tracebacks.

    We hide traceback entries of:

    * dynamically generated code (no code to show up for it);
    * internal traceback from pytest or its internal libraries, py and pluggy.
    rT  r
  FT)	rl   rr   r;   rQ   r   rU   r   _PLUGGY_DIR_PYTEST_DIR)r   Zraw_filenameZis_generatedrT   r   rA   rA   rB   filter_traceback  s    
r}  )cr   rJ  rv  r   r  r   r   r   r   rR  r   pathlibr   r   typesr   r   r	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   weakrefr   ZpluggyZ_pytestZ_pytest._code.sourcer   r   r    r!   Z_pytest._ior"   Z_pytest._io.safereprr#   r%   Z_pytest.compatr&   r'   Z_pytest.deprecatedr(   Z_pytest.pathlibr)   r*   Ztyping_extensionsr+   r,   r-   r   version_infoZexceptiongroupr8   r9   rk   r   r   r   r   	dataclassr   r   rN  rY  r   r   r4  r   rb  r+  r   r#  r  re   ri   rh   ry  __file__r   r{  rO   parentr|  rj   r}  rA   rA   rA   rB   <module>   s   E> v o  )



	

	
O


 '