
    F-Phڏ              	      ^   d 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	Z	ddl
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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 er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/ ed          Z0dfd%Z1dgd&Z2dgd'Z3dhd*Z4 e"d+,          did0            Z5 G d1 d2e
j6                  Z7 G d3 d4e
j6                  Z8 G d5 d6e8          Z9 G d7 d8e          Z: G d9 d:ej;        ee                   Z<d;d<d=d>Z= G d? d@e<e>                   Z? G dA dBe<e                   Z@ G dC dDe@eA                   ZB G dE dFe@e>                   ZC G dG dHe<e                   ZD G dI dJeDeA                   ZE G dK dLeDe>                   ZFejG        dMk    sere G dN dOeee                               ZHn& G dP dO ejI        dOdQdRg          ee                   ZH G dS dTee                   ZJdjdXZK G dY dZ          ZL G d[ d\ee                   ZMe(dkd`            ZNe(dkda            ZOe(dldc            ZPe(dkdd            ZQe(dlde            ZRdS )mz+Per-test stdout/stderr capturing mechanism.    )annotationsN)	Generator)Iterable)IteratorUnsupportedOperation)TemporaryFile)TracebackType)Any)AnyStr)BinaryIO)cast)Final)final)Generic)Literal)
NamedTuple)TextIO)TYPE_CHECKING)Self)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)	Collector)File)Item)CollectReportfdsysnotee-sysparserr   returnNonec                    |                      d          }|                    ddddg dd           |                    d	d
ddd           d S )Ngeneralz	--capturestorer"   methodr!   z3Per-test capturing method: one of fd|sys|no|tee-sys)actiondefaultmetavarchoiceshelpz-sstore_constr$   capturezShortcut for --capture=no)r-   constdestr1   )getgroup	addoption
_addoption)r&   groups     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/_pytest/capture.pypytest_addoptionr;   1   s~    OOI&&E	OO...B     
(          c                 t    t           j                            d          r	 ddl} dS # t          $ r Y dS w xY wdS )a  Ensure colorama is imported so that it attaches to the correct stdio
    handles on Windows.

    colorama uses the terminal on import time. So if something does the
    first import of colorama while I/O capture is active, colorama will
    fail in various ways.
    win32r   N)r#   platform
startswithcoloramaImportError)rA   s    r:   _colorama_workaroundrC   D   sZ     |w'' 	OOOOO 	 	 	DD	 s   ' 
55c                 2    	 ddl } dS # t          $ r Y dS w xY w)a  Ensure readline is imported early so it attaches to the correct stdio handles.

    This isn't a problem with the default GNU readline implementation, but in
    some configurations, Python uses libedit instead (on macOS, and for prebuilt
    binaries such as used by uv).

    In theory this is only needed if readline.backend == "libedit", but the
    workaround consists of importing readline here, so we already worked around
    the issue by the time we could check if we need to.
    r   N)readlinerB   rE   s    r:   _readline_workaroundrG   S   s6       s    
streamr   c                    t           j                            d          rt          t           d          rdS t           d          sdS t           j        d          r j        j        n j        }t          |t          j                  sdS  fd} |t           j	        d          t           _	         |t           j
        d          t           _
         |t           j        d          t           _        dS )	a  Workaround for Windows Unicode console handling.

    Python 3.6 implemented Unicode console handling for Windows. This works
    by reading/writing to the raw console handle using
    ``{Read,Write}ConsoleW``.

    The problem is that we are going to ``dup2`` over the stdio file
    descriptors when doing ``FDCapture`` and this will ``CloseHandle`` the
    handles used by Python to write to the console. Though there is still some
    weirdness and the console handle seems to only be closed randomly and not
    on the first call to ``CloseHandle``, or maybe it gets reopened with the
    same handle value when we suspend capturing.

    The workaround in this case will reopen stdio with a different fd which
    also means a different handle by replicating the logic in
    "Py_lifecycle.c:initstdio/create_stdio".

    :param stream:
        In practice ``sys.stdout`` or ``sys.stderr``, but given
        here as parameter for unittesting purposes.

    See https://github.com/pytest-dev/py/issues/103.
    r>   pypy_version_infoNbufferrawc                   t          j        d          s|d         dk    rd}nd}t          j        t	          t          j        |                                           ||          | j        | j	        | j
        | j                  S )NrL   r   w)hasattrrK   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingrH   s      r:   _reopen_stdioz3_windowsconsoleio_workaround.<locals>._reopen_stdio   sz    v}e,, 	aCIII

##T955JHJ
 
 	
r<   rbwb)r#   r?   r@   rP   rK   rL   
isinstancerQ   _WindowsConsoleIOstdinstdoutstderr)rH   
raw_stdoutr^   s   `  r:   _windowsconsoleio_workaroundrg   d   s    0 <""7++ ws<O/P/P  68$$ &-fmU&C&CV""Jj""677 
 
 
 
 
 ci..CIsz400CJsz400CJJJr<   Twrapperearly_configr   Generator[None]c              #    K   | j         }|j        dk    rt          t          j                   t                       t                       | j        }t          |j                  }|	                    |d           | 
                    |j                   |                                 	 	 d V  |                                 d S # |                                 w xY w# t          $ rW |                                \  }}t          j                            |           t          j                            |            w xY w)Nr"   capturemanager)known_args_namespacer3   rg   r#   rd   rC   rG   pluginmanagerCaptureManagerregisteradd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureBaseExceptionread_global_capturewritere   )rj   nsro   capmanouterrs         r:   pytest_load_initial_conftestsr}      s@     		*B	zT$SZ000 .MBJ''F6#3444 V9::: !!###		,EEE))+++++F))++++   --//S

	s   +C /C CC A!D?c                  B    e Zd ZdZedd            Zedd            ZdS )EncodedFile r'   strc                *    t          | j                  S N)reprrK   selfs    r:   namezEncodedFile.name   s     DK   r<   c                    t          | j        d          sJ t          t          | j        j                            dd                    S )Nr\   b )rP   rK   r   r   r\   replacer   s    r:   r\   zEncodedFile.mode   sA     t{F+++++C)11#r::;;;r<   Nr'   r   )__name__
__module____qualname__	__slots__propertyr   r\   r   r<   r:   r   r      sW        I! ! ! X!
 < < < X< < <r<   r   c                  (     e Zd Zd fdZddZ xZS )	CaptureIOr'   r(   c                t    t                                          t          j                    ddd           d S )NUTF-8r   T)rW   newlinewrite_through)super__init__rQ   BytesIO)r   	__class__s    r:   r   zCaptureIO.__init__   s1    SWXXXXXr<   r   c                    t          | j        t          j                  sJ | j                                                            d          S )Nr   )ra   rK   rQ   r   getvaluedecoder   s    r:   r   zCaptureIO.getvalue   s>    $+rz22222{##%%,,W555r<   r'   r(   r   )r   r   r   r   r   __classcell__r   s   @r:   r   r      sW        Y Y Y Y Y Y6 6 6 6 6 6 6 6r<   r   c                  ,     e Zd Zd
 fdZd fd	Z xZS )TeeCaptureIOotherr   r'   r(   c                V    || _         t                                                       d S r   )_otherr   r   )r   r   r   s     r:   r   zTeeCaptureIO.__init__   s&    r<   sr   intc                z    t                                          |           | j                            |          S r   )r   rx   r   )r   r   r   s     r:   rx   zTeeCaptureIO.write   s/    a{  ###r<   )r   r   r'   r(   )r   r   r'   r   )r   r   r   r   rx   r   r   s   @r:   r   r      s[             $ $ $ $ $ $ $ $ $ $r<   r   c                      e Zd Zed/d            Zd0d1dZeZd/dZd0d2dZd3dZ	d4dZ
d5dZd6dZd5dZd6dZd7d8dZd6dZd4dZd9d:dZd;dZd<d"Zd6d#Zd=d%Zd>d,Zed?d.            ZdS )@DontReadFromInputr'   r   c                @    t           j        J t           j        j        S r   )r#   	__stdin__rW   r   s    r:   rW   zDontReadFromInput.encoding   s    }(((}%%r<   rO   sizer   c                     t          d          NzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorr   r   s     r:   readzDontReadFromInput.read       X
 
 	
r<   c                *    |                                  S r   rF   r   s    r:   __next__zDontReadFromInput.__next__   s    }}r<   hint
int | None	list[str]c                     t          d          r   r   )r   r   s     r:   	readlineszDontReadFromInput.readlines   r   r<   Iterator[str]c                    | S r   r   r   s    r:   __iter__zDontReadFromInput.__iter__       r<   c                     t          d          )Nz/redirected stdin is pseudofile, has no fileno()r   r   s    r:   rV   zDontReadFromInput.fileno   s    "#TUUUr<   r(   c                     t          d          )Nz.redirected stdin is pseudofile, has no flush()r   r   s    r:   flushzDontReadFromInput.flush   s    "#STTTr<   boolc                    dS NFr   r   s    r:   isattyzDontReadFromInput.isatty       ur<   c                    d S r   r   r   s    r:   closezDontReadFromInput.close       r<   c                    dS r   r   r   s    r:   readablezDontReadFromInput.readable  r   r<   r   offsetwhencec                     t          d          )Nz0redirected stdin is pseudofile, has no seek(int)r   )r   r   r   s      r:   seekzDontReadFromInput.seek  s    "#UVVVr<   c                    dS r   r   r   s    r:   seekablezDontReadFromInput.seekable  r   r<   c                     t          d          )Nz-redirected stdin is pseudofile, has no tell()r   r   s    r:   tellzDontReadFromInput.tell  s    "#RSSSr<   Nc                     t          d          )Nzcannot truncate stdinr   r   s     r:   truncatezDontReadFromInput.truncate      "#:;;;r<   datac                     t          d          )Nzcannot write to stdinr   r   r   s     r:   rx   zDontReadFromInput.write  r   r<   linesIterable[str]c                     t          d          )NzCannot write to stdinr   )r   r   s     r:   
writelineszDontReadFromInput.writelines  r   r<   c                    dS r   r   r   s    r:   writablezDontReadFromInput.writable  r   r<   r   c                    | S r   r   r   s    r:   	__enter__zDontReadFromInput.__enter__  r   r<   typetype[BaseException] | NonevalueBaseException | None	tracebackTracebackType | Nonec                    d S r   r   )r   r   r   r   s       r:   __exit__zDontReadFromInput.__exit__  s	     	r<   r   c                    | S r   r   r   s    r:   rK   zDontReadFromInput.buffer%  s	     r<   r   )rO   )r   r   r'   r   )r   r   r'   r   )r'   r   )r'   r   r   r'   r   )r   )r   r   r   r   r'   r   r   )r   r   r'   r   )r   r   r'   r   )r   r   r'   r(   )r'   r   )r   r   r   r   r   r   r'   r(   )r'   r   )r   r   r   r   rW   r   rE   r   r   r   rV   r   r   r   r   r   r   r   r   rx   r   r   r   r   rK   r   r<   r:   r   r      s       & & & X&
 
 
 
 

 H   
 
 
 
 

   V V V VU U U U         W W W W W   T T T T< < < < << < < << < < <             X  r<   r   c                     e Zd ZU ded<   ej        dd            Zej        dd            Zej        dd	            Zej        dd
            Z	ej        dd            Z
ej        dd            Zej        dd            ZdS )CaptureBaser   EMPTY_BUFFERr"   r   r'   r(   c                    t                      r   NotImplementedErrorr   r"   s     r:   r   zCaptureBase.__init__1      !###r<   c                    t                      r   r   r   s    r:   startzCaptureBase.start5  r   r<   c                    t                      r   r   r   s    r:   donezCaptureBase.done9  r   r<   c                    t                      r   r   r   s    r:   suspendzCaptureBase.suspend=  r   r<   c                    t                      r   r   r   s    r:   resumezCaptureBase.resumeA  r   r<   r   c                    t                      r   r   r   s     r:   writeorgzCaptureBase.writeorgE  r   r<   c                    t                      r   r   r   s    r:   snapzCaptureBase.snapI  r   r<   Nr"   r   r'   r(   r   )r   r   r'   r(   )r'   r   )r   r   r   __annotations__abcabstractmethodr   r   r   r   r   r   r  r   r<   r:   r   r   .  s        $ $ $ $ 	$ $ $ $ 	$ $ $ $ 	$ $ $ $ 	$ $ $ $ 	$ $ $ $ 	$ $ $ $ $ $r<   r   rc   rd   re   )r         c                  J    e Zd ZdZddZddZddZdd	Zdd
ZddZ	ddZ
dS )	NoCapturer   r"   r   r'   r(   c                    d S r   r   r   s     r:   r   zNoCapture.__init__T  r   r<   c                    d S r   r   r   s    r:   r   zNoCapture.startW  r   r<   c                    d S r   r   r   s    r:   r   zNoCapture.doneZ  r   r<   c                    d S r   r   r   s    r:   r   zNoCapture.suspend]  r   r<   c                    d S r   r   r   s    r:   r   zNoCapture.resume`  r   r<   r   c                    dS Nr   r   r   s    r:   r  zNoCapture.snapc  s    rr<   r   c                    d S r   r   r   s     r:   r   zNoCapture.writeorgf  r   r<   Nr  r   r   r   r   r'   r(   )r   r   r   r   r   r   r   r   r   r  r   r   r<   r:   r	  r	  Q  s        L                       r<   r	  c                  X    e Zd Z	 dddddZddZddZddZddZddZddZ	ddZ
dS )SysCaptureBaseNFteer"   r   tmpfileTextIO | Noner  r   r'   r(   c                   t           |         }t          t          |          | _        || _        |9|dk    rt                      }n$|st                      nt          | j                  }|| _        d| _	        d S )Nrc   initialized)
patchsysdictgetattrr#   _oldr   r   r   r   r  _state)r   r"   r  r  r   s        r:   r   zSysCaptureBase.__init__k  so     B#C..		?w+---0M)+++l496M6M#r<   
class_namer   c                    d                     || j        t          | d          rt          | j                  pd| j        | j                  S Nz(<{} {} _old={} _state={!r} tmpfile={!r}>r  z<UNSET>)formatr   rP   r   r  r  r  )r   r  s     r:   r   zSysCaptureBase.repry  sK    9@@IT6""6tDID9KL
 
 	
r<   c                    d                     | j        j        | j        t	          | d          rt          | j                  pd| j        | j                  S r!  )	r"  r   r   r   rP   r   r  r  r  r   s    r:   __repr__zSysCaptureBase.__repr__  sP    9@@N#IT6""6tDID9KL
 
 	
r<   opstatestuple[str, ...]c                    | j         |v s7J d                    || j         d                    |                                d S Nz+cannot {} in state {!r}: expected one of {}z, r  r"  joinr   r%  r&  s      r:   _assert_statezSysCaptureBase._assert_state  K    {f$$$9@@DK6!2!2  %$$$$r<   c                    |                      dd           t          t          | j        | j                   d| _        d S )Nr   r  started)r-  setattrr#   r   r  r  r   s    r:   r   zSysCaptureBase.start  s:    7$4555TY---r<   c                    |                      dd           | j        dk    rd S t          t          | j        | j                   | `| j                                         d| _        d S )Nr   r  r1  	suspendedr   )r-  r  r2  r#   r   r  r  r   r   s    r:   r   zSysCaptureBase.done  se    6#RSSS;&  FTY	***Ir<   c                    |                      dd           t          t          | j        | j                   d| _        d S Nr   r1  r5  r5  )r-  r2  r#   r   r  r  r   s    r:   r   zSysCaptureBase.suspend  s:    9&>???TY	***!r<   c                    |                      dd           | j        dk    rd S t          t          | j        | j                   d| _        d S Nr   r8  r1  )r-  r  r2  r#   r   r  r   s    r:   r   zSysCaptureBase.resume  sL    8%=>>>;)##FTY---r<   r   )r"   r   r  r  r  r   r'   r(   )r  r   r'   r   r   r%  r   r&  r'  r'   r(   r   )r   r   r   r   r   r$  r-  r   r   r   r   r   r<   r:   r  r  j  s        04$EJ$ $ $ $ $ $
 
 
 

 
 
 

 
 
 
       
   " " " "
           r<   r  c                  "    e Zd ZdZd	dZd
dZdS )SysCaptureBinaryr<   r'   bytesc                   |                      dd           | j                            d           | j        j                                        }| j                            d           | j                                         |S Nr  r8  r   r-  r  r   rK   r   r   r   ress     r:   r  zSysCaptureBinary.snap  t    6#;<<<!l!&&((!
r<   r   r(   c                    |                      dd           | j                                         | j        j                            |           | j        j                                         d S Nr   r8  )r-  r  r   rK   rx   r   s     r:   r   zSysCaptureBinary.writeorg  sa    :'?@@@		t$$$	     r<   Nr'   r>  r   r>  r'   r(   r   r   r   r   r  r   r   r<   r:   r=  r=    sA        L   ! ! ! ! ! !r<   r=  c                  "    e Zd ZdZd	dZd
dZdS )
SysCapturer   r'   r   c                   |                      dd           t          | j        t                    sJ | j                                        }| j                            d           | j                                         |S r@  )r-  ra   r  r   r   r   r   rB  s     r:   r  zSysCapture.snap  ss    6#;<<<$,	22222l##%%!
r<   r   r(   c                    |                      dd           | j                            |           | j                                         d S rF  )r-  r  rx   r   r   s     r:   r   zSysCapture.writeorg  sE    :'?@@@		r<   Nr   r  rI  r   r<   r:   rK  rK    sA        L        r<   rK  c                  F    e Zd ZddZddZddZddZddZddZddZ	dS )FDCaptureBasetargetfdr   r'   r(   c                r   || _         	 t          j        |           d | _        nX# t          $ rK t          j        t          j        t          j                  | _        t          j        | j        |           Y nw xY wt          j	        |          | _
        |dk    r5t          t          j        d          | _        t          |          | _        n_t          t          d          dddd          | _        |t           v rt          || j                  | _        nt#          |          | _        d	| _        d S )
Nr   utf-8)rW   )r]   r   r   T)rW   rX   r   r   r  )rP  rT   fstattargetfd_invalidr   rS   devnullO_RDWRdup2rU   targetfd_saver  rK  
syscapturer   r	   r  r	  r  )r   rP  s     r:   r   zFDCaptureBase.__init__  s-    	)HX  %)D!!  	5 	5 	5 13
BI0N0ND!GD)844444	5   VH--q==
W===DL0:80D0DDOO&***  "  DL <''",Xt|"D"D"+H"5"5#s   % AA:9A:r   c                b    d| j         j         d| j         d| j         d| j        d| j        dS )N< z oldfd= _state=z	 tmpfile=>)r   r   rP  rX  r  r  r   s    r:   r$  zFDCaptureBase.__repr__  si    @' @ @$- @ @@R @ @k@ @.2l@ @ @	
r<   r%  r&  r'  c                    | j         |v s7J d                    || j         d                    |                                d S r)  r*  r,  s      r:   r-  zFDCaptureBase._assert_state   r.  r<   c                    |                      dd           t          j        | j                                        | j                   | j                                         d| _        dS )z4Start capturing on targetfd using memorized tmpfile.r   r0  r1  N)	r-  rT   rW  r  rV   rP  rY  r   r  r   s    r:   r   zFDCaptureBase.start  sZ    7$4555
##%%t}555r<   c                   |                      dd           | j        dk    rdS t          j        | j        | j                   t          j        | j                   | j        B| j        | j        k    rt          j        | j                   t          j        | j                   | j        	                                 | j
                                         d| _        dS )z_Stop capturing, restore streams, return original capture file,
        seeked to position zero.r   r4  N)r-  r  rT   rW  rX  rP  r   rT  rY  r   r  r   s    r:   r   zFDCaptureBase.done  s     	6#RSSS;&  F
"DM222
#$$$ ,$55'''HT*+++r<   c                    |                      dd           | j        dk    rd S | j                                         t	          j        | j        | j                   d| _        d S r7  )r-  r  rY  r   rT   rW  rX  rP  r   s    r:   r   zFDCaptureBase.suspend  sa    9&>???;+%%F!!!
"DM222!r<   c                    |                      dd           | j        dk    rd S | j                                         t	          j        | j                                        | j                   d| _        d S r:  )	r-  r  rY  r   rT   rW  r  rV   rP  r   s    r:   r   zFDCaptureBase.resume&  sl    8%=>>>;)##F   
##%%t}555r<   N)rP  r   r'   r(   r   r;  r   )
r   r   r   r   r$  r-  r   r   r   r   r   r<   r:   rO  rO    s        '$ '$ '$ '$R
 
 
 

 
 
 
           " " " "           r<   rO  c                  &    e Zd ZdZdZd
dZddZd	S )FDCaptureBinaryzWCapture IO to/from a given OS-level file descriptor.

    snap() produces `bytes`.
    r<   r'   r>  c                   |                      dd           | j                            d           | j        j                                        }| j                            d           | j                                         |S r@  rA  rB  s     r:   r  zFDCaptureBinary.snap7  rD  r<   r   r(   c                f    |                      dd           t          j        | j        |           dS )"Write to original file descriptor.r   r8  N)r-  rT   rx   rX  r   s     r:   r   zFDCaptureBinary.writeorg?  s4    :'?@@@
#T*****r<   NrG  rH  r   r   r   __doc__r   r  r   r   r<   r:   re  re  /  sM         
 L   + + + + + +r<   re  c                  &    e Zd ZdZdZd
dZddZd	S )	FDCapturezTCapture IO to/from a given OS-level file descriptor.

    snap() produces text.
    r   r'   r   c                    |                      dd           | j                            d           | j                                        }| j                            d           | j                                         |S r@  )r-  r  r   r   r   rB  s     r:   r  zFDCapture.snapM  sq    6#;<<<!l!!!
r<   r   r(   c                    |                      dd           t          j        | j        |                    d                     dS )rh  r   r8  rR  N)r-  rT   rx   rX  encoder   s     r:   r   zFDCapture.writeorgU  s@    :'?@@@
#T[[%9%9:::::r<   Nr   r  ri  r   r<   r:   rl  rl  E  sM         
 L   ; ; ; ; ; ;r<   rl  )      c                  (    e Zd ZU dZded<   ded<   dS )CaptureResultOThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.r   r{   r|   N)r   r   r   rj  r  r   r<   r:   rs  rs  b  s(         ]]r<   rs  c                      e Zd ZdZdZdS )rs  rt  r   N)r   r   r   rj  r   r   r<   r:   rs  rs  k  s         	^]			r<   r{   r|   c                  `    e Zd ZdZdZdd	ZddZddZddZdddZ	ddZ
ddZddZddZdS )MultiCaptureNFin_CaptureBase[AnyStr] | Noner{   r|   r'   r(   c                0    || _         || _        || _        d S r   rx  r{   r|   )r   rx  r{   r|   s       r:   r   zMultiCapture.__init__x  s     03/2/2r<   r   c                X    d| j         d| j        d| j        d| j        d| j        dS )Nz<MultiCapture out=z err=z in_=r]  z _in_suspended=r^  )r{   r|   rx  r  _in_suspendedr   s    r:   r$  zMultiCapture.__repr__  sf    L L L$( L L48 L LkL L484FL L L	
r<   c                    d| _         | j        r| j                                         | j        r| j                                         | j        r| j                                         d S d S )Nr1  )r  rx  r   r{   r|   r   s    r:   start_capturingzMultiCapture.start_capturing  sm    8 	HNN8 	HNN8 	HNN	 	r<   tuple[AnyStr, AnyStr]c                    |                                  \  }}|r#| j        J | j                            |           |r#| j        J | j                            |           ||fS )z?Pop current snapshot out/err capture and flush to orig streams.)
readouterrr{   r   r|   r   r{   r|   s      r:   pop_outerr_to_origzMultiCapture.pop_outerr_to_orig  sv    ??$$S 	#8'''Hc""" 	#8'''Hc"""Cxr<   r   c                    d| _         | j        r| j                                         | j        r| j                                         |r)| j        r$| j                                         d| _        d S d S d S )Nr5  T)r  r{   r   r|   rx  r}  r   rx  s     r:   suspend_capturingzMultiCapture.suspend_capturing  s    !8 	H8 	H 	&48 	&H!%D	& 	& 	& 	&r<   c                    d| _         | j        r| j                                         | j        r| j                                         | j        r+| j        J | j                                         d| _        d S d S )Nr1  F)r  r{   r   r|   r}  rx  r   s    r:   resume_capturingzMultiCapture.resume_capturing  s    8 	HOO8 	HOO 	'8'''HOO!&D	' 	'r<   c                   | j         dk    rt          d          d| _         | j        r| j                                         | j        r| j                                         | j        r| j                                         dS dS )z+Stop capturing and reset capturing streams.stoppedzwas already stoppedN)r  
ValueErrorr{   r   r|   rx  r   s    r:   stop_capturingzMultiCapture.stop_capturing  s~    ;)##23338 	HMMOOO8 	HMMOOO8 	HMMOOOOO	 	r<   c                    | j         dk    S )z7Whether actively capturing -- not suspended or stopped.r1  )r  r   s    r:   
is_startedzMultiCapture.is_started  s    {i''r<   CaptureResult[AnyStr]c                    | j         r| j                                         nd}| j        r| j                                        nd}t          ||          S r  )r{   r  r|   rs  r  s      r:   r  zMultiCapture.readouterr  sF    !%1dhmmooor!%1dhmmooorS#&&&r<   )rx  ry  r{   ry  r|   ry  r'   r(   r   r   )r'   r  Frx  r   r'   r(   r   r'   r  )r   r   r   r  r}  r   r$  r  r  r  r  r  r  r  r   r<   r:   rw  rw  t  s        FM3 3 3 3
 
 
 
   	 	 	 	& & & & &	' 	' 	' 	'
 
 
 
( ( ( (' ' ' ' ' 'r<   rw  r,   _CaptureMethodMultiCapture[str]c                   | dk    r9t          t          d          t          d          t          d                    S | dk    r9t          t          d          t          d          t          d                    S | dk    rt          d d d           S | dk    r0t          d t          dd	
          t          dd	
                    S t          d|           )Nr"   r   r  r  r{  r#   r$   r%   Tr  zunknown capturing method: )rw  rl  rK  r  )r,   s    r:   _get_multicapturer    s    ~~	!)A,,IaLLQQQQ	5
1:a==jQRmmTTTT	4$D9999	9		*QD111z!7N7N7N
 
 
 	
 <&<<
=
==r<   c                     e Zd ZdZd2dZd3dZd4d
Zd5dZd6dZd6dZ	d6dZ
d7d8dZd7d8dZd6dZd9dZd:dZd6dZd6dZd6dZd6dZd6dZej        d;d             Zej        d<d$            Z ed%&          d=d*            Z ed%&          d>d+            Z ed%&          d>d,            Z ed%&          d>d-            Z ed%.          d6d/            Z ed%.          d6d0            Zd1S )?rp   a  The capture plugin.

    Manages that the appropriate capture method is enabled/disabled during
    collection and each test phase (setup, call, teardown). After each of
    those points, the captured output is obtained and attached to the
    collection/runtest report.

    There are two levels of capture:

    * global: enabled by default and can be suppressed by the ``-s``
      option. This is always enabled/disabled during collection and each test
      phase.

    * fixture: when a test function or one of its fixture depend on the
      ``capsys`` or ``capfd`` fixtures. In this case special handling is
      needed to ensure the fixtures take precedence over the global capture.
    r,   r  r'   r(   c                0    || _         d | _        d | _        d S r   _method_global_capturing_capture_fixture)r   r,   s     r:   r   zCaptureManager.__init__  s    $;?<@r<   r   c                8    d| j         d| j        d| j        dS )Nz<CaptureManager _method=z _global_capturing=z _capture_fixture=r^  r  r   s    r:   r$  zCaptureManager.__repr__  s>    ;t| ; ;$J` ; ; $ 5; ; ;	
r<   
str | boolc                h    |                                  rdS | j        rd| j        j        j         S dS )Nglobalzfixture F)is_globally_capturingr  requestfixturenamer   s    r:   is_capturingzCaptureManager.is_capturing  sC    %%'' 	8  	JId3;GIIIur<   r   c                    | j         dk    S )Nr$   )r  r   s    r:   r  z$CaptureManager.is_globally_capturing   s    |t##r<   c                |    | j         J t          | j                  | _         | j                                          d S r   )r  r  r  r  r   s    r:   rt   z%CaptureManager.start_global_capturing  s>    %---!24<!@!@..00000r<   c                    | j         ;| j                                          | j                                          d | _         d S d S r   )r  r  r  r   s    r:   rs   z$CaptureManager.stop_global_capturing  sK    !-"55777"11333%)D""" .-r<   c                J    | j         | j                                          d S d S r   )r  r  r   s    r:   resume_global_capturez$CaptureManager.resume_global_capture  s0     !-"3355555 .-r<   Frx  c                N    | j         | j                             |           d S d S )Nrx  )r  r  r  s     r:   ru   z%CaptureManager.suspend_global_capture  s3    !-"444===== .-r<   c                X    |                                   |                     |           d S r   )suspend_fixtureru   r  s     r:   r   zCaptureManager.suspend  s.    ##C(((((r<   c                V    |                                   |                                  d S r   )r  resume_fixturer   s    r:   r   zCaptureManager.resume  s,    ""$$$r<   CaptureResult[str]c                F    | j         J | j                                         S r   )r  r  r   s    r:   rw   z"CaptureManager.read_global_capture!  s&    %111%00222r<   capture_fixtureCaptureFixture[Any]c                    | j         r>| j         j        j        }|j        j        }|j                            d| d| d           || _         d S )Nzcannot use z and z at the same time)r  r  r  
raiseerror)r   r  current_fixturerequested_fixtures       r:   set_fixturezCaptureManager.set_fixture'  si      	"3;GO / 7 C#..X/XXoXXX   !0r<   c                    d | _         d S r   )r  r   s    r:   unset_fixturezCaptureManager.unset_fixture0  s     $r<   c                J    | j         r| j                                          dS dS )z|If the current item is using ``capsys`` or ``capfd``, activate
        them so they take precedence over the global capture.N)r  _startr   s    r:   activate_fixturezCaptureManager.activate_fixture3  s4       	+!((*****	+ 	+r<   c                J    | j         r| j                                          dS dS )zDDeactivate the ``capsys`` or ``capfd`` fixture of this item, if any.N)r  r   r   s    r:   deactivate_fixturez!CaptureManager.deactivate_fixture9  s2      	*!'')))))	* 	*r<   c                J    | j         r| j                                          d S d S r   )r  _suspendr   s    r:   r  zCaptureManager.suspend_fixture>  s2      	-!**,,,,,	- 	-r<   c                J    | j         r| j                                          d S d S r   )r  _resumer   s    r:   r  zCaptureManager.resume_fixtureB  s2      	,!))+++++	, 	,r<   rk   c              #    K   | j         o| j                                         }|r|                                  | j        o| j                                        }|r|                                  	 dV  |r|                                  |r|                                  dS dS # |r|                                  |r|                                  w w xY w)zLContext manager to temporarily disable global and current fixture capturing.N)r  _is_startedr  r  r  ru   r  r  )r   
do_fixture	do_globals      r:   global_and_fixture_disabledz*CaptureManager.global_and_fixture_disabledH  s      *Rt/D/P/P/R/R
 	#  """*Rt/E/P/P/R/R	 	*'')))	&EEE -**,,, &##%%%%%& &  -**,,, &##%%%%&s   0B$ $/Cwhenitemr   c              #  *  K   |                                   |                                  	 d V  |                                  |                     d           |                                 \  }}|                    |d|           |                    |d|           d S # |                                  |                     d           |                                 \  }}|                    |d|           |                    |d|           w xY w)NFr  rd   re   )r  r  r  ru   rw   add_report_section)r   r  r  r{   r|   s        r:   item_capturezCaptureManager.item_captureY  s#     ""$$$	9EEE##%%%''E'222//11HC##D(C888##D(C88888 ##%%%''E'222//11HC##D(C888##D(C8888s   B! !A1DTrh   	collectorr   -Generator[None, CollectReport, CollectReport]c              #  r  K   t          |t                    r|                                  	 d V }|                                  n# |                                  w xY w|                                 \  }}|r|j                            d|f           |r|j                            d|f           nd V }|S )NzCaptured stdoutzCaptured stderr)ra   r   r  ru   rw   sectionsappend)r   r  repr{   r|   s        r:   pytest_make_collect_reportz)CaptureManager.pytest_make_collect_reporti  s       i&& 	&&(((.ee++----++----//11HC >##%6$<=== >##%6$<===%%C
s   A Ac              #  n   K   |                      d|          5  d V cd d d            S # 1 swxY w Y   d S )Nsetupr  r   r  s     r:   pytest_runtest_setupz#CaptureManager.pytest_runtest_setup|  s      w-- 	 	EE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   *..c              #  n   K   |                      d|          5  d V cd d d            S # 1 swxY w Y   d S )Ncallr  r  s     r:   pytest_runtest_callz"CaptureManager.pytest_runtest_call  s      vt,, 	 	EE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  c              #  n   K   |                      d|          5  d V cd d d            S # 1 swxY w Y   d S )Nteardownr  r  s     r:   pytest_runtest_teardownz&CaptureManager.pytest_runtest_teardown  s      z400 	 	EE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  )tryfirstc                .    |                                   d S r   rs   r   s    r:   pytest_keyboard_interruptz(CaptureManager.pytest_keyboard_interrupt      ""$$$$$r<   c                .    |                                   d S r   r  r   s    r:   pytest_internalerrorz#CaptureManager.pytest_internalerror  r  r<   N)r,   r  r'   r(   r   )r'   r  r   r   r  r  )r'   r  )r  r  r'   r(   r'   rk   )r  r   r  r   r'   rk   )r  r   r'   r  )r  r   r'   rk   ) r   r   r   rj  r   r$  r  r  rt   rs   r  ru   r   r   rw   r  r  r  r  r  r  
contextlibcontextmanagerr  r  r   r  r  r  r  r  r  r   r<   r:   rp   rp     s        $A A A A

 
 
 
   $ $ $ $1 1 1 1
* * * *6 6 6 6> > > > >) ) ) ) )
   3 3 3 30 0 0 0% % % %+ + + +* * * *
- - - -, , , , & & & &  9 9 9 9 Xd   $ Xd    Xd    Xd    Xt% % % % Xt% % % % % %r<   rp   c                  t    e Zd ZdZdddddZddZddZddZddZddZ	ddZ
ej        dd            ZdS )CaptureFixturez|Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
    :fixture:`capfd` and :fixture:`capfdbinary` fixtures.NFconfig	_ispytestcaptureclasstype[CaptureBase[AnyStr]]r  r   r  dict[str, Any] | Noner  r   r'   r(   c                   t          |           || _        || _        |r|ni | _        d | _        | j        j        | _        | j        j        | _        d S r   )r   r  r  _config_capturer   _captured_out_captured_err)r   r  r  r  r  s        r:   r   zCaptureFixture.__init__  sZ     	y!!!7C!'/vvR59%)%6%C%)%6%Cr<   c           	         | j         Rt          d  | j        di | j         | j        di | j                  | _         | j                                          d S d S )Nr  r  r{  )r  )r  )r  rw  r  r  r  r   s    r:   r  zCaptureFixture._start  sw    = (%D%884<88%D%884<88  DM
 M))+++++ ! r<   c                    | j         ^| j                                         \  }}| xj        |z  c_        | xj        |z  c_        | j                                          d | _         d S d S r   )r  r  r  r  r  r  s      r:   r   zCaptureFixture.close  sp    =$}7799HC#%#%M((*** DMMM %$r<   r  c                    | j         | j        }}| j        &| j                                        \  }}||z  }||z  }| j        j        | _         | j        j        | _        t          ||          S )zRead and return the captured output so far, resetting the internal
        buffer.

        :returns:
            The captured content as a namedtuple with ``out`` and ``err``
            string attributes.
        )r  r  r  r  r  r   rs  )r   captured_outcaptured_errr{   r|   s        r:   r  zCaptureFixture.readouterr  sr     &*%79Kl=$}//11HCCLCL!.;!.;\<888r<   c                J    | j         | j                                          dS dS )z1Suspend this fixture's own capturing temporarily.N)r  r  r   s    r:   r  zCaptureFixture._suspend  s,    =$M++----- %$r<   c                J    | j         | j                                          dS dS )z0Resume this fixture's own capturing temporarily.N)r  r  r   s    r:   r  zCaptureFixture._resume  s,    =$M**,,,,, %$r<   c                F    | j         | j                                         S dS )z5Whether actively capturing -- not disabled or closed.NF)r  r  r   s    r:   r  zCaptureFixture._is_started  s#    =$=++---ur<   rk   c              #     K   | j         j        j                            d          }|                                5  dV  ddd           dS # 1 swxY w Y   dS )z>Temporarily disable capturing while inside the ``with`` block.rm   N)r  r  ro   	getpluginr  )r   
capmanagers     r:   disabledzCaptureFixture.disabled  s       &*\%8%F%P%P&
 &

 3355 	 	EEE	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAA)
r  r  r  r   r  r  r  r   r'   r(   r   r  r   r  )r   r   r   rj  r   r  r   r  r  r  r  r  r  r  r   r<   r:   r  r    s        = = )-D D D D D D , , , ,! ! ! !9 9 9 9". . . .
- - - -
         r<   r  r  r   Generator[CaptureFixture[str]]c              #     K   | j         j                            d          }t          t          | d          }|                    |           |                                 |V  |                                 |                                 dS )a  Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``.

    The captured output is made available via ``capsys.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.

    Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_output(capsys):
            print("hello")
            captured = capsys.readouterr()
            assert captured.out == "hello\n"
    rm   Tr  N)	r  ro   r  r  rK  r  r  r   r  r  rz   r  s      r:   capsysr
    s      & %^9CCDTUUF$ZDIIIO
'''

r<   c              #  >  K   | j         j                            d          }t          t          | t          d          d          }|                    |           |                                 |V  |                                 |	                                 dS )a  Enable simultaneous text capturing and pass-through of writes
    to ``sys.stdout`` and ``sys.stderr`` as defined by ``--capture=``.


    The captured output is made available via ``capteesys.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.

    The output is also passed-through, allowing it to be "live-printed",
    reported, or both as defined by ``--capture=``.

    Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_output(capsys):
            print("hello")
            captured = capteesys.readouterr()
            assert captured.out == "hello\n"
    rm   Tr  r  N)
r  ro   r  r  rK  dictr  r  r   r  r	  s      r:   	capteesysr    s      0 %^9CCDTUUF$GDTNNNd  O '''

r<    Generator[CaptureFixture[bytes]]c              #     K   | j         j                            d          }t          t          | d          }|                    |           |                                 |V  |                                 |                                 dS )a'  Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``.

    The captured output is made available via ``capsysbinary.readouterr()``
    method calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``bytes`` objects.

    Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_output(capsysbinary):
            print("hello")
            captured = capsysbinary.readouterr()
            assert captured.out == b"hello\n"
    rm   Tr  N)	r  ro   r  r  r=  r  r  r   r  r	  s      r:   capsysbinaryr  &  s      & %^9CCDTUUF$%5w$OOOO
'''

r<   c              #     K   | j         j                            d          }t          t          | d          }|                    |           |                                 |V  |                                 |                                 dS )a  Enable text capturing of writes to file descriptors ``1`` and ``2``.

    The captured output is made available via ``capfd.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``text`` objects.

    Returns an instance of :class:`CaptureFixture[str] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_system_echo(capfd):
            os.system('echo "hello"')
            captured = capfd.readouterr()
            assert captured.out == "hello\n"
    rm   Tr  N)	r  ro   r  r  rl  r  r  r   r  r	  s      r:   capfdr  B  s      & %^9CCDTUUF$Y4HHHO
'''

r<   c              #     K   | j         j                            d          }t          t          | d          }|                    |           |                                 |V  |                                 |                                 dS )a-  Enable bytes capturing of writes to file descriptors ``1`` and ``2``.

    The captured output is made available via ``capfd.readouterr()`` method
    calls, which return a ``(out, err)`` namedtuple.
    ``out`` and ``err`` will be ``byte`` objects.

    Returns an instance of :class:`CaptureFixture[bytes] <pytest.CaptureFixture>`.

    Example:

    .. code-block:: python

        def test_system_echo(capfdbinary):
            os.system('echo "hello"')
            captured = capfdbinary.readouterr()
            assert captured.out == b"hello\n"

    rm   Tr  N)	r  ro   r  r  re  r  r  r   r  r	  s      r:   capfdbinaryr  ^  s      ( %^9CCDTUUF$_gNNNO
'''

r<   )r&   r   r'   r(   r   )rH   r   r'   r(   )rj   r   r'   rk   )r,   r  r'   r  )r  r   r'   r  )r  r   r'   r  )Srj  
__future__r   r  collectionscollections.abcr   r   r   r  rQ   r   rT   r#   tempfiler	   typesr
   typingr   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   _pytest.configr   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.nodesr   r   r   _pytest.reportsr    r  r;   rC   rG   rg   r}   rR   r   r   r   r   ABCr   r  r   r	  r  r>  r=  rK  rO  re  rl  version_infors  
namedtuplerw  r  rp   r  r
  r  r  r  r  r   r<   r:   <module>r%     s4   1 1 " " " " " " 



     % % % % % % $ $ $ $ $ $ $ $ $ $ $ $     				 # # # # # # 				 



 " " " " " "                                                                                '&&&&&& ! ! ! ! ! ! # # # # # # , , , , , , - - - - - - $ $ $ $ $ $ ' ' ' ' ' ' # # # # # #             ) ) ) ) ) ) 56   &      "41 41 41 41n 
$   << < < < <"" < < <"6 6 6 6 6  6 6 6$ $ $ $ $9 $ $ $J J J J J J J J`$ $ $ $ $#'76? $ $ $@ xH55    C    2@  @  @  @  @ [( @  @  @ F! ! ! ! !~e, ! ! !$    $   "\  \  \  \  \ K' \  \  \ ~+ + + + +mE* + + +,; ; ; ; ;c" ; ; ;6 w-
    
GFO   U     ??  Q' Q' Q' Q' Q'76? Q' Q' Q'h> > > >"x% x% x% x% x% x% x% x%vM M M M MWV_ M M Mf 	   	6 	   	D 	   	6 	   	6 	   	  r<   