a
    !f                     @   sh  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%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.m0Z0 d d#l1m2Z2 d d$l1m3Z3 d d%l4m5Z5 d d&l6m7Z7 d d'l6m8Z8 e"rBd d(l9m:Z: d d)l9m;Z; d d*l9m<Z< e;d+ Z=ej>dd, d-k rbd d.l?m@Z@ G d/d0 d0ZAG d1d2 d2ZBG d3d4 d4ZCG d5d6 d6eeC ZDe#d7eEd8d9ZFe2ejGG d:d; d;eeF ZHejGG d<d= d=ZIejGd>d?G d@dA dAZJejGd>d?G dBdC dCeJZKejGd>d?G dDdE dEeKZLejGd>d?G dFdG dGeKZMejGd>d?G dHdI dIeJZNG dJdK dKeNZOejGd>d?G dLdM dMeJZPejGd>d?G dNdO dOeJZQejGd>d?G dPdQ dQeJZRejGd>d?G dRdS dSeJZSejGd>d?G dTdU dUeJZTeUe e$eVef eWf dVdWdXZXee%jYZdYZ[e[j\dZkrHe[j]Z[ee&jYj]Z^eCe_d[d\d]Z`d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)
findsource
getrawcode)getstatementrange_ast)Source)TerminalWriter)
safeformatsaferepr)final)get_real_func)check_ispytest)absolutepath)bestrelpath)Final)Literal)SupportsIndex)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 Nr9   )selfr<    r@   S/var/www/html/python-backend/venv/lib/python3.9/site-packages/_pytest/_code/code.py__init__C   s    zCode.__init__c                 C   s   | t |S r>   r   )clsr<   r@   r@   rA   from_functionF   s    zCode.from_functionc                 C   s   | j |j kS r>   r9   )r?   otherr@   r@   rA   __eq__J   s    zCode.__eq__r=   c                 C   s   | j jd S N   )r:   co_firstlinenor?   r@   r@   rA   firstlinenoP   s    zCode.firstlinenoc                 C   s   | j jS r>   )r:   co_namerK   r@   r@   rA   nameT   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?   pr@   r@   rA   pathX   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_r@   r@   rA   
fullsourcei   s    zCode.fullsourcec                 C   s
   t | jS )zGReturn a _pytest._code.Source object for the code object's source only.)r    r:   rK   r@   r@   rA   sourceo   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?   rY   r:   Zargcountr@   r@   rA   getargst   s    zCode.getargs)F)__name__
__module____qualname____doc__	__slots__r   rB   classmethodobjectrD   rF   __hash__propertyintrL   strrN   r   r   rT   r   rW   rX   boolr   r]   r@   r@   r@   rA   r8   >   s"   r8   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.r9   N)framer=   c                 C   s
   || _ d S r>   r9   )r?   rk   r@   r@   rA   rB      s    zFrame.__init__rG   c                 C   s   | j jd S rH   )r:   f_linenorK   r@   r@   rA   lineno   s    zFrame.linenoc                 C   s   | j jS r>   )r:   	f_globalsrK   r@   r@   rA   rn      s    zFrame.f_globalsc                 C   s   | j jS r>   )r:   f_localsrK   r@   r@   rA   ro      s    zFrame.f_localsc                 C   s   t | jjS r>   )r8   r:   f_coderK   r@   r@   rA   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.NrO   )rq   rW   r    getstatementrm   rK   r@   r@   rA   	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.
        )ro   copyupdateevalrn   )r?   rq   varsro   r@   r@   rA   rv      s    

z
Frame.eval)rd   r=   c                 C   s   t |S )zCReturn a 'safe' (non-recursive, one-line) string repr for 'object'.r#   )r?   rd   r@   r@   rA   repr   s    z
Frame.reprFrY   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.
        )rq   r]   appendro   KeyError)r?   rY   retvalargr@   r@   rA   r]      s    zFrame.getargs)F)r^   r_   r`   ra   rb   r   rB   rf   rg   rm   r   rh   r
   rn   ro   r8   rq   rs   rv   rd   rx   ri   r]   r@   r@   r@   rA   rj      s    rj   c                   @   s@  e Zd ZdZdZd(eed ddddZed d dd	d
Ze	e
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  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_repr_styleNzLiteral["short", "long"])rawentry
repr_styler=   c                 C   s   || _ || _d S r>   r   )r?   r   r   r@   r@   rA   rB      s    zTracebackEntry.__init__)r   r=   c                 C   s   t | j|S r>   )r~   r   )r?   r   r@   r@   rA   with_repr_style   s    zTracebackEntry.with_repr_stylerG   c                 C   s   | j jd S rH   )r   	tb_linenorK   r@   r@   rA   rm      s    zTracebackEntry.linenoc                 C   s   t | jjS r>   )rj   r   tb_framerK   r@   r@   rA   rk      s    zTracebackEntry.framec                 C   s   | j | jjj S r>   )rm   rk   rq   rL   rK   r@   r@   rA   relline   s    zTracebackEntry.rellinec                 C   s   d| j jj| jd f S )Nz<TracebackEntry %s:%d>rI   )rk   rq   rT   rm   rK   r@   r@   rA   __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)rk   rq   rW   rr   rm   )r?   rX   r@   r@   rA   rs      s    
zTracebackEntry.statementc                 C   s
   | j jjS )zPath to the source code.)rk   rq   rT   rK   r@   r@   rA   rT      s    zTracebackEntry.pathc                 C   s   | j jS )zLocals of underlying frame.)rk   ro   rK   r@   r@   rA   locals   s    zTracebackEntry.localsc                 C   s
   | j jjS r>   )rk   rq   rL   rK   r@   r@   rA   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)astnoderI   )	rk   rq   rW   rT   getr   r   rm   SyntaxError)r?   r   rX   keyr   startrV   endr@   r@   rA   	getsource   s$    

zTracebackEntry.getsourceExceptionInfo[BaseException]excinfor=   c              	   C   sV   d}| j j| j jfD ](}z|d }W n ty6   Y q0  q>q|rRt|rR||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__)rk   ro   rn   	Exceptioncallable)r?   r   ZtbhZmaybe_ns_dctr@   r@   rA   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
rI   )
rk   rq   rN   rh   rs   lstripKeyboardInterruptBaseExceptionrT   rm   )r?   rN   r/   r@   r@   rA   __str__-  s    

zTracebackEntry.__str__c                 C   s   | j jjjS )zco_name of underlying code.)rk   rq   r:   rM   rK   r@   r@   rA   rN   ?  s    zTracebackEntry.name)N)N)!r^   r_   r`   ra   rb   r	   r   rB   r   rf   rg   rm   rj   rk   r   rh   r   rs   r   r   rT   r   r
   r   r   astASTr   rX   ri   r   r   rN   r@   r@   r@   rA   r~      sF    	 r~   c                       s   e Zd ZdZeeee f 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edeegef f d dddZe	e dddZ  ZS )	TracebackzQTraceback objects encapsulate and offer higher level access to Traceback entries.N)tbr=   c                    s@   t |tr0ttt ddd}t || nt | dS )z@Initialize from given python traceback object and ExceptionInfo.)curr=   c                 s   s"   | }|d urt |V  |j}qd S r>   )r~   tb_next)r   cur_r@   r@   rA   fO  s    
zTraceback.__init__.<locals>.fN)
isinstancer	   r   r~   superrB   )r?   r   r   	__class__r@   rA   rB   H  s    
zTraceback.__init__zos.PathLike[str])rT   rm   rL   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  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>   )rh   ).0rS   r@   r@   rA   	<genexpr>s      z Traceback.cut.<locals>.<genexpr>)osfspathrk   rq   rT   rh   r   r   parentsrm   rL   r   r   )
r?   rT   rm   rL   r   Zpath_Zexcludepath_xrq   Zcodepathr@   r@   rA   cutY  s(    zTraceback.cutr,   )r   r=   c                 C   s   d S r>   r@   r?   r   r@   r@   rA   __getitem__}  s    zTraceback.__getitem__c                 C   s   d S r>   r@   r   r@   r@   rA   r     s    c                    s,   t |tr| t |S t |S d S r>   )r   slicer   r   r   r   r   r@   rA   r     s    
r   )_excinfo_or_fnr=   c                    s*   t  tr fdd}n }tt|| S )a  Return a Traceback instance with certain items removed.

        If the filter is an `ExceptionInfo`, removes all the ``TracebackEntry``s
        which are hidden (see ishidden() above).

        Otherwise, the filter 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.
        c                    s   |    S r>   )r   )r   r   r@   rA   <lambda>  r   z"Traceback.filter.<locals>.<lambda>)r   ExceptionInfor   filter)r?   r   fnr@   r   rA   r     s    
zTraceback.filterrG   c           	      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)
	enumeraterk   rq   rT   idr:   rm   
setdefaultro   rz   )	r?   cacheientryr   valuesr   locZotherlocr@   r@   rA   recursionindex  s    zTraceback.recursionindex)NNNN)r^   r_   r`   ra   r   r	   r   r~   rB   r   rh   rg   r   r   r   r   r   ri   r   r   __classcell__r@   r@   r   rA   r   E  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< dCd
deee	d de
f  eee ed	dddZedDeee ddddZedEee	e ee
f ee ddddZedFe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dGeed.d/d0Zee	e  ee	e  d1f f ed2d3d4Z!ed5 dd6d7Z"dHed:eeee#dgef f eeeed; d<d=d>Z$eee%e f d?d@dAdBZ&d	S )Ir   zJWraps sys.exc_info() objects and offers help for navigating the traceback.zAssertionError('assert _assert_start_reprr   _excinfo
_striptext
_tracebackrO   NF	_ispytest)r   	striptext	tracebackr   r=   c                C   s   t | || _|| _|| _d S r>   )r'   r   r   r   )r?   r   r   r   r   r@   r@   rA   rB     s    zExceptionInfo.__init__zExceptionInfo[E])	exceptionexprinfor=   c                 C   s*   |j sJ dt|||j f}| ||S )aE  Return an ExceptionInfo for an existing exception.

        The exception must have a non-``None`` ``__traceback__`` attribute,
        otherwise this function fails with an assertion error. This means that
        the exception must have been raised, or added a traceback with the
        :py:meth:`~BaseException.with_traceback()` method.

        :param exprinfo:
            A text string helping to determine if we should strip
            ``AssertionError`` from the output. Defaults to the exception
            message/``__str__()``.

        .. versionadded:: 7.4
        zTExceptions passed to ExcInfo.from_exception(...) must have a non-None __traceback__.)__traceback__typefrom_exc_info)rC   r   r   exc_infor@   r@   rA   from_exception  s    zExceptionInfo.from_exception)r   r   r=   c                 C   s`   d}|du rRt |d trRt|d dd}|du r>t|d }|rR|| jrRd}| ||ddS )z@Like :func:`from_exception`, but using old-style exc_info tuple.rO   NrI   msgzAssertionError: Tr   )r   AssertionErrorgetattrr$   
startswithr   )rC   r   r   r   r@   r@   rA   r     s    zExceptionInfo.from_exc_infor   )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 exceptionrI   r4   )sysr   r   r   )rC   r   tupr   r@   r@   rA   from_current  s    zExceptionInfo.from_currentrG   c                 C   s   | dddS )z!Return an unfilled ExceptionInfo.NTr   r@   )rC   r@   r@   rA   	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   r@   r@   rA   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   rK   r@   r@   rA   r   #  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 exitsrI   r   rK   r@   r@   rA   r2   +  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 exitsr4   r   rK   r@   r@   rA   r   3  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^   rK   r@   r@   rA   typename;  s
    zExceptionInfo.typenamec                 C   s   | j du rt| j| _ | j S )zThe traceback.N)r   r   r   rK   r@   r@   rA   r   C  s    
zExceptionInfo.traceback)r2   r=   c                 C   s
   || _ d S r>   )r   )r?   r2   r@   r@   rA   r   J  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={}>rI   )r   formatr   r^   r$   lenr   rK   r@   r@   rA   r   N  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).
        rO   N)r   r   r2   joinrstripr   r   r   )r?   r   linestextr@   r@   rA   exconlyU  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   r2   )r?   r   r@   r@   rA   errisinstancee  s    zExceptionInfo.errisinstanceReprFileLocationc                 C   sj   t dt| j d dD ]L}| j| }|| s|jjjj|j }}| j	dd}t
||d |  S qd S )NrI   Tr   )ranger   r   r   rk   rq   r:   rP   rm   r   r   )r?   r   r   rT   rm   r   r@   r@   rA   _getreprcrashn  s    

zExceptionInfo._getreprcrashr-   T_TracebackStyle)ReprExceptionInfoExceptionChainRepr)
showlocalsstyleabspathtbfilterfuncargstruncate_localschainr=   c           	   	   C   s\   |dkr<t tt| j| j| jr*| jd jnd|  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|line|no|native|value traceback style.

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

        :param tbfilter:
            A filter for traceback entries.

            * If false, don't hide any entries.
            * If true, hide internal entries and entries that contain a local
              variable ``__tracebackhide__ = True``.
            * If a callable, delegates the filtering to the callable.

            Ignored if ``style`` is ``"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.
        r1   r   Nreprtraceback	reprcrash)r   r   r   r   r   r   r   )
r   ReprTracebackNativer   format_exceptionr   r2   r   r   FormattedExcinforepr_excinfo)	r?   r   r   r   r   r   r   r   fmtr@   r@   rA   getrepry  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?)rh   r2   research)r?   r  r   r2   r   r@   r@   rA   match  s    
zExceptionInfo.match)rO   N)N)N)N)F)Fr-   FTFTT)'r^   r_   r`   ra   r   r   __annotations__r   r   r   r	   rh   r   ri   rB   rc   r   r   r   r   r   r   rf   r   r2   r   r   r   setterr   r   r   r   r   r   r   r  r   r	  r@   r@   r@   rA   r     s   
     	       Fr   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	eee gef f 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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initrx   r   r    )rX   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 )NrI   r   r      )rh   rr   r   r   r   r   )r?   rX   sr@   r@   rA   
_getindent  s    zFormattedExcinfo._getindentr   r=   c                 C   s    | | j}|d ur| }|S r>   )r   r   Zdeindent)r?   r   rX   r@   r@   rA   _getentrysource  s    z FormattedExcinfo._getentrysourceReprFuncArgsc                 C   s@   | j r<g }|jjddD ]\}}||t|f qt|S d S )NTry   )r   rk   r]   rz   r$   r  )r?   r   argsargnameZargvaluer@   r@   rA   	repr_args  s    zFormattedExcinfo.repr_argsr   N)rX   
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       rI   r  T)indentmarkall)	r   r   r    rz   stripr  r  extendget_exconly)	r?   rX   r  r   r.   r   Zspace_prefixr/   r  r@   r@   rA   
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   
rI   )r   splitr  rz   )	r?   r   r  r  r   Z	indentstrZexlinesZ
failindentr/   r@   r@   rA   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   @r@   )r   r   r@   r@   rA   
<listcomp>1  r   z0FormattedExcinfo.repr_locals.<locals>.<listcomp>__builtins__z__builtins__ = <builtins>z<10 = )r   sortrz   r   r$   r"   r%  )r?   r   r   keysrN   r2   Zstr_reprr@   r@   rA   repr_locals.  s    
zFormattedExcinfo.repr_locals	ReprEntry)r   r   r=   c                 C   sV  g }|d ur|j d ur|j n| j}|dv r|d ur| |}|d u rRtd}d}n|j|  }|dk}|sv| |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 |rB|| j|dd t|d d d |S d S )N)r.   r-   r   r   r.   )r.   zin %srO   rI   r2   r#  r  r  )r   r   r  r    rm   r   r  r!  r  rN   r   rT   	_makepathr   r,  r   r-  rh   r2   r$  r   )r?   r   r   r   r   rX   r  r.   Zreprargsr  message
entry_pathrT   reprfilelocZ
localsreprr@   r@   rA   repr_traceback_entryH  s@    



z%FormattedExcinfo.repr_traceback_entry)rT   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)   cwdrR   rh   r   )r?   rT   npr@   r@   rA   r/  p  s    zFormattedExcinfo._makepathReprTracebackr   c                    s    j }tjr }njr,| }t jtrH|\}}nd }|sz|d u r\d}d  g}t	||j
dS |d j
dkr g}t	|d j
dS  fdd|D }t	||j
dS )NzXAll traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames.)r   r   r2   c                    s$   g | ]} ||kr nd qS r>   )r3  )r   r   r   lastr?   r@   rA   r'    s   z3FormattedExcinfo.repr_traceback.<locals>.<listcomp>)r   r   r   r   r   r2   RecursionError_truncate_recursive_tracebackr3  r6  r   )r?   r   r   	extralineentriesr@   r7  rA   repr_tracebackz  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)rI   )r   r   r   r   r^   rh   r   )r?   r   r   er@  r;  r@   r@   rA   r:    s"    0z.FormattedExcinfo._truncate_recursive_tracebackr   c           	      C   s2  g }|j }|}d }t }|d ur"t||vr"|t| |rt|trpttt	|j |j |jd j
}n
| |}| }nttt	||d }d }||||fg7 }|jd ur| jr|j}|jrt|nd }d}q|jd ur|js| jr|j}|jrt|nd }d}qd }q|  t|S )Nr   zDThe above exception was the direct cause of the following exception:zCDuring handling of the above exception, another exception occurred:)r2   setr   addr   r7   r   r   r  r   r   r=  r   	__cause__r   r   r   r   __context____suppress_context__reverser   )	r?   r   Z
repr_chainrB  Zexcinfo_descrseenr   r   r@   r@   rA   r    sR    




zFormattedExcinfo.repr_excinfo)r   NF)r  F)N)0r^   r_   r`   ra   r  r   r
  r  r   ri   r   r   r   r   r   r   r   r   r   r   r   dataclassesfielddictr   r   rh   r   r   r   rg   r  r~   r   r  r  r   r!  r   r   rd   r,  r3  r/  r=  r   r:  r  r@   r@   r@   rA   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 )
TerminalReprrG   c                 C   s&   t  }t|d}| | |  S )N)file)r   r!   
toterminalgetvaluer  )r?   iotwr@   r@   rA   r     s    

zTerminalRepr.__str__c                 C   s   d| j  dt| ddS )N<z instance at 0xr  )r   r   rK   r@   r@   rA   r     s    zTerminalRepr.__repr__NrT  r=   c                 C   s
   t  d S r>   )NotImplementedErrorr?   rT  r@   r@   rA   rQ    s    zTerminalRepr.toterminal)r^   r_   r`   rh   r   r   r!   rQ  r@   r@   r@   rA   rO    s   rO  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 )ExceptionReprr6  r   r   r   F)r  r  sections-N)rN   contentsepr=   c                 C   s   | j |||f d S r>   )r[  rz   )r?   rN   r]  r^  r@   r@   rA   
addsection  s    zExceptionRepr.addsectionrW  c                 C   s,   | j D ] \}}}||| || qd S r>   )r[  r^  r/   )r?   rT  rN   r]  r^  r@   r@   rA   rQ    s    zExceptionRepr.toterminal)r\  )r^   r_   r`   r
  r   rK  rL  listr[  r   r   rh   r_  r!   rQ  r@   r@   r@   rA   rZ  
  s   
rZ  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   r6  r   r   N)r   r=   c                    s*   t  j|d d |d d d || _d S )Nr   r   rI   r   )r   rB   r   )r?   r   r   r@   rA   rB      s
    

zExceptionChainRepr.__init__rW  c                    sR   | j D ]:}|d | |d d ur|d |j|d dd qt | d S )Nr   r4   rO   T)yellow)r   rQ  r/   r   )r?   rT  elementr   r@   rA   rQ  .  s    

zExceptionChainRepr.toterminal)r^   r_   r`   r   r   r   rh   r
  rB   r!   rQ  r   r@   r@   r   rA   r     s   
r   c                       s:   e Zd ZU ded< ed ed< edd fddZ  ZS )	r   r6  r   r   r   NrW  c                    s   | j | t | d S r>   )r   rQ  r   rY  r   r@   rA   rQ  <  s    zReprExceptionInfo.toterminal)r^   r_   r`   r
  r   r!   rQ  r   r@   r@   r   rA   r   7  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 )r6  )r-  ReprEntryNativereprentriesr;  r   r   z_ entrysepNrW  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-   rO   rI   r.   )	r   rd  r   r/   rQ  r   r^  re  r;  )r?   rT  r   r   Z
next_entryr@   r@   rA   rQ  I  s    


zReprTraceback.toterminal)r^   r_   r`   r   r   r
  r   rh   re  r   r!   rQ  r@   r@   r@   rA   r6  A  s
   
r6  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 )Nr1   )rc  rd  r;  r   )r?   rf  r@   r@   rA   rB   ]  s    zReprTracebackNative.__init__)r^   r_   r`   r   rh   rB   r@   r@   r@   rA   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 )	rc  r   r1   r   r   NrW  c                 C   s   | d| j d S )NrO   )writer   r   rY  r@   r@   rA   rQ  i  s    zReprEntryNative.toterminal)
r^   r_   r`   r   rh   r
  r   r   r!   rQ  r@   r@   r@   rA   rc  c  s   
rc  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   r2  r   r   NrW  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  r2   Tboldred)r   r  r  r   r   r   r  r   rz   Z_write_sourcer/   )
r?   rT  r  indent_sizeindentsZsource_linesZfailure_linesindexr/   Zis_failure_liner@   r@   rA   _write_entry_linesu  s&    

zReprEntry._write_entry_linesc                 C   s   | j dkr@| jr| j| | | | jr<| jj|dd d S | jrR| j| | | | jrx|d | j| | jr| jr|d | j| d S )Nr.   z        r.  rO   )r   r2  rQ  rp  ri  rh  r/   r   rY  r@   r@   rA   rQ    s"    




zReprEntry.toterminalrG   c                 C   s   d d| j| j| jS )Nz{}
{}
{}r#  )r   r   r   ri  r2  rK   r@   r@   rA   r     s    zReprEntry.__str__)r^   r_   r`   r   rh   r
  r   r!   rp  rQ  r   r@   r@   r@   rA   r-  m  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   rT   rm   r0  NrG   c                 C   s   t | j| _d S r>   )rh   rT   rK   r@   r@   rA   __post_init__  s    zReprFileLocation.__post_init__rW  c                 C   sR   | j }|d}|dkr$|d | }|j| jddd |d| j d|  d S )Nr#  r   Trj  :z: )r0  findrg  rT   r/   rm   )r?   rT  r   r   r@   r@   rA   rQ    s    
zReprFileLocation.toterminal)	r^   r_   r`   rh   r
  rg   rq  r!   rQ  r@   r@   r@   rA   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   rO   NrW  c                 C   s   | j D ]}|||  qd S r>   )r   r/   )r?   rT  r  r/   r@   r@   rA   rQ    s    
zReprLocals.toterminal)rO   )r^   r_   r`   r   rh   r
  r!   rQ  r@   r@   r@   rA   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  NrW  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 )NrO   r)  r4   z, )r  r   Z	fullwidthr/   )r?   rT  Z	linesofarrN   r2   nsr@   r@   rA   rQ    s    

zReprFuncArgs.toterminal)
r^   r_   r`   r   r   rh   rd   r
  r!   rQ  r@   r@   r@   rA   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)rO   r   rO   r   )r&   hasattrru  r8   rD   	TypeErrorinspectgetsourcefilegetfiler(   r   rR   rT   rL   )r<   rq   r   r   rm   rV   r@   r@   rA   getfslineno  s&    


r{  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.
    rU  r  FT)	rk   rq   r:   rP   r   rT   r   _PLUGGY_DIR_PYTEST_DIR)r   Zraw_filenameZis_generatedrS   r   r@   r@   rA   filter_traceback  s    
r  )ar   rK  rx  r   r  r   r   r   r   rS  r   pathlibr   r   typesr   r   r	   typingr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   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exceptiongroupr7   r8   rj   r~   r   r   r   	dataclassr   r  rO  rZ  r   r   r6  r   rc  r-  r   r%  r  rd   rh   rg   r{  __file__r   r}  rN   parentr~  ri   r  r@   r@   r@   rA   <module>   s   E> u    *



	

	
O


 '