
    ?g              	         S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSKrSSK	r	SSK
Jr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \(       a  SSKJr  SSKJr  SSKJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  SSK%J'r'  SSK(J)r)  SSK(J*r*  SSK(J+r+  SSK,J-r-  \S   r.STS  jr/SUS! jr0SUS" jr1SVS# jr2\ " S$S%9SWS& j5       r3 " S' S(\Rh                  5      r5 " S) S*\Rh                  5      r6 " S+ S,\65      r7 " S- S.\5      r8 " S/ S0\Rr                  \\   5      r:S1S2S3S4.r; " S5 S6\:\<   5      r= " S7 S8\:\   5      r> " S9 S:\>\?   5      r@ " S; S<\>\<   5      rA " S= S>\:\   5      rB " S? S@\B\?   5      rC " SA SB\B\<   5      rD\	R                  SC:  d  \(       a  \ " SD SE\\\   5      5       rFO" " SF SE\R                  " SESGSH/5      \\   5      rF " SI SJ\\   5      rHSXSK jrI " SL SM5      rJ " SN SO\\   5      rK\&SYSP j5       rL\&SZSQ j5       rM\&SYSR j5       rN\&SZSS j5       rOg)[z+Per-test stdout/stderr capturing mechanism.    )annotationsNUnsupportedOperation)TemporaryFile)TracebackType)Any)AnyStr)BinaryIO)Final)final)	Generator)Generic)Iterable)Iterator)Literal)
NamedTuple)TextIO)TYPE_CHECKING)Self)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)	Collector)File)Item)CollectReportfdsysnotee-sysc           	     x    U R                  S5      nUR                  SSSS/ SQSS9  UR                  S	S
SSSS9  g )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destr-   )getgroup
_addoption)parsergroups     1/usr/lib/python3/dist-packages/_pytest/capture.pypytest_addoptionr7   0   sY    OOI&E	.B   
(      c                 x    [         R                  R                  S5      (       a   SSKn gg! [         a     gf = f)zEnsure 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)r=   s    r6   _colorama_workaroundr?   C   s:     ||w''	 (  		s   , 
99c                 .     SSK n g! [         a     gf = f)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)readliner>   rA   s    r6   _readline_workaroundrC   R   s     s    
c                $  ^  [         R                  R                  S5      (       a  [        [         S5      (       a  g[        T S5      (       d  g[        T R                  S5      (       a  T R                  R
                  OT R                  n[        U[        R                  5      (       d  gU 4S jnU" [         R                  S5      [         l	        U" [         R                  S5      [         l
        U" [         R                  S5      [         l        g)	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                2  > [        TR                  S5      (       d  US   S:X  a  SnOSn[        R                  " [	        [
        R                  " U R                  5       5      X5      U R                  U R                  U R                  U R                  5      $ )NrG   r   w)hasattrrF   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingstreams      r6   _reopen_stdio3_windowsconsoleio_workaround.<locals>._reopen_stdio   sr    v}}e,,aCII
#T5JJHHJJ
 	
r8   rbwb)r"   r;   r<   rK   rF   rG   
isinstancerL   _WindowsConsoleIOstdinstdoutstderr)rY   
raw_stdoutrZ   s   `  r6   _windowsconsoleio_workaroundrd   c   s    0 <<""7++ws<O/P/P 68$$&-fmmU&C&C""Jj""6"677
 cii.CIszz40CJszz40CJr8   Twrapperc              #  n  #    U R                   nUR                  S:X  a  [        [        R                  5        [        5         [        5         U R                  n[        UR                  5      nUR                  US5        U R                  UR                  5        UR                  5           S v   UR                  5         g ! UR                  5         f = f! [         aR    UR                  5       u  pE[        R                  R!                  U5        [        R"                  R!                  U5        e f = f7f)Nr!   capturemanager)known_args_namespacer/   rd   r"   ra   r?   rC   pluginmanagerCaptureManagerregisteradd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureBaseExceptionread_global_capturewriterb   )early_confignsrj   capmanouterrs         r6   pytest_load_initial_conftestsry      s     		*	*B	zzT$SZZ0 ..MBJJ'F6#34 V99: !!#		,))+F))+ --/



	s1   B(D5,C 0C  D5CC AD22D5c                  @    \ rS rSrSr\SS j5       r\SS j5       rSrg)EncodedFile    c                ,    [        U R                  5      $ N)reprrF   selfs    r6   nameEncodedFile.name   s     DKK  r8   c                N    U R                   R                  R                  SS5      $ )Nb )rF   rW   replacer   s    r6   rW   EncodedFile.mode   s!     {{''R00r8   Nreturnstr)	__name__
__module____qualname____firstlineno__	__slots__propertyr   rW   __static_attributes__r}   r8   r6   r{   r{      s-    I! !
 1 1r8   r{   c                  6   ^  \ rS rSrSU 4S jjrSS jrSrU =r$ )	CaptureIO   c                L   > [         TU ]  [        R                  " 5       SSSS9  g )NUTF-8r   T)rR   newlinewrite_through)super__init__rL   BytesIO)r   	__class__s    r6   r   CaptureIO.__init__   s     SWXr8   c                    [        U R                  [        R                  5      (       d   eU R                  R	                  5       R                  S5      $ )Nr   )r^   rF   rL   r   getvaluedecoder   s    r6   r   CaptureIO.getvalue   s;    $++rzz2222{{##%,,W55r8   r}   r   Noner   )r   r   r   r   r   r   r   __classcell__r   s   @r6   r   r      s    Y6 6r8   r   c                  <   ^  \ rS rSrSU 4S jjrSU 4S jjrSrU =r$ )TeeCaptureIO   c                .   > Xl         [        TU ]	  5         g r   )_otherr   r   )r   otherr   s     r6   r   TeeCaptureIO.__init__   s    r8   c                X   > [         TU ]  U5        U R                  R                  U5      $ r   )r   rs   r   )r   sr   s     r6   rs   TeeCaptureIO.write   s$    a{{  ##r8   )r   )r   r   r   r   )r   r   r   int)r   r   r   r   r   rs   r   r   r   s   @r6   r   r      s    $ $r8   r   c                     \ rS rSr\SS j5       rSSS jjr\rSS jrSSS jjr	SS jr
SS jrSS jrSS	 jrSS
 jrSS jrS S!S jjrSS jrSS jrS"S#S jjrS$S jrS%S jrSS jrS&S jr        S'S jr\S(S j5       rSrg))DontReadFromInput   c                \    [         R                  c   e[         R                  R                  $ r   )r"   	__stdin__rR   r   s    r6   rR   DontReadFromInput.encoding   s"    }}(((}}%%%r8   c                    [        S5      eNzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorr   sizes     r6   readDontReadFromInput.read       X
 	
r8   c                "    U R                  5       $ r   rB   r   s    r6   __next__DontReadFromInput.__next__   s    }}r8   c                    [        S5      er   r   )r   hints     r6   	readlinesDontReadFromInput.readlines   r   r8   c                    U $ r   r}   r   s    r6   __iter__DontReadFromInput.__iter__       r8   c                    [        S5      e)Nz/redirected stdin is pseudofile, has no fileno()r   r   s    r6   rQ   DontReadFromInput.fileno   s    "#TUUr8   c                    [        S5      e)Nz.redirected stdin is pseudofile, has no flush()r   r   s    r6   flushDontReadFromInput.flush   s    "#STTr8   c                    gNFr}   r   s    r6   isattyDontReadFromInput.isatty       r8   c                    g r   r}   r   s    r6   closeDontReadFromInput.close       r8   c                    gr   r}   r   s    r6   readableDontReadFromInput.readable   r   r8   c                    [        S5      e)Nz0redirected stdin is pseudofile, has no seek(int)r   )r   offsetwhences      r6   seekDontReadFromInput.seek  s    "#UVVr8   c                    gr   r}   r   s    r6   seekableDontReadFromInput.seekable  r   r8   c                    [        S5      e)Nz-redirected stdin is pseudofile, has no tell()r   r   s    r6   tellDontReadFromInput.tell	  s    "#RSSr8   Nc                    [        S5      e)Nzcannot truncate stdinr   r   s     r6   truncateDontReadFromInput.truncate      "#:;;r8   c                    [        S5      e)Nzcannot write to stdinr   r   datas     r6   rs   DontReadFromInput.write  r   r8   c                    [        S5      e)NzCannot write to stdinr   )r   liness     r6   
writelinesDontReadFromInput.writelines  r   r8   c                    gr   r}   r   s    r6   writableDontReadFromInput.writable  r   r8   c                    U $ r   r}   r   s    r6   	__enter__DontReadFromInput.__enter__  r   r8   c                    g r   r}   )r   typevalue	tracebacks       r6   __exit__DontReadFromInput.__exit__  s     	r8   c                    U $ r   r}   r   s    r6   rF   DontReadFromInput.buffer#  s	     r8   r}   r   )rJ   )r   r   r   r   )r   
int | Noner   z	list[str])r   zIterator[str])r   r   r   r   bool)r   )r   r   r   r   r   r   r   )r   r  r   r   )r   r   r   r   )r   zIterable[str]r   r   )r   r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner   r   )r   r
   )r   r   r   r   r   rR   r   rA   r   r   r   rQ   r   r   r   r   r   r   r   r   rs   r   r   r   r   rF   r   r}   r8   r6   r   r      s    & &

 H

VUWT<<<( $ (	
 
  r8   r   c                  8   \ rS rSr% S\S'   \R                  SS j5       r\R                  SS j5       r\R                  SS j5       r	\R                  SS j5       r
\R                  SS j5       r\R                  SS	 j5       r\R                  SS
 j5       rSrg)CaptureBasei,  r	   EMPTY_BUFFERc                    [        5       er   NotImplementedErrorr   r!   s     r6   r   CaptureBase.__init__/      !##r8   c                    [        5       er   r
  r   s    r6   startCaptureBase.start3  r  r8   c                    [        5       er   r
  r   s    r6   doneCaptureBase.done7  r  r8   c                    [        5       er   r
  r   s    r6   suspendCaptureBase.suspend;  r  r8   c                    [        5       er   r
  r   s    r6   resumeCaptureBase.resume?  r  r8   c                    [        5       er   r
  r   s     r6   writeorgCaptureBase.writeorgC  r  r8   c                    [        5       er   r
  r   s    r6   snapCaptureBase.snapG  r  r8   r}   Nr!   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}   r8   r6   r  r  ,  s    $ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $r8   r  r`   ra   rb   )r         c                  ^    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrS
rg)	NoCaptureiO  r   c                    g r   r}   r  s     r6   r   NoCapture.__init__R  r   r8   c                    g r   r}   r   s    r6   r  NoCapture.startU  r   r8   c                    g r   r}   r   s    r6   r  NoCapture.doneX  r   r8   c                    g r   r}   r   s    r6   r  NoCapture.suspend[  r   r8   c                    g r   r}   r   s    r6   r  NoCapture.resume^  r   r8   c                    gNr   r}   r   s    r6   r  NoCapture.snapa  s    r8   c                    g r   r}   r   s     r6   r  NoCapture.writeorgd  r   r8   r}   Nr!  r   r   r   r   r   r   )r   r   r   r   r  r   r  r  r  r  r  r  r   r}   r8   r6   r(  r(  O  s*    Lr8   r(  c                      \ rS rSr SSS.       SS jjjrSS jrSS jrSS jrSS	 jrSS
 jr	SS jr
SS jrSrg)SysCaptureBaseih  NFteec                   [         U   n[        [        U5      U l        X@l        Uc7  US:X  a  [        5       nO&U(       d
  [        5       O[        U R                  5      nX l        SU l	        g )Nr`   initialized)
patchsysdictgetattrr"   _oldr   r   r   r   tmpfile_state)r   r!   rB  r<  r   s        r6   r   SysCaptureBase.__init__i  sU     B#C.		?w+--0)+l4996M#r8   c                    SR                  UU R                  [        U S5      =(       a    [        U R                  5      =(       d    SU R
                  U R                  5      $ Nz(<{} {} _old={} _state={!r} tmpfile={!r}>rA  z<UNSET>)formatr   rK   r   rA  rC  rB  )r   
class_names     r6   r   SysCaptureBase.reprw  sI    9@@IID&!5d499oBKKLL
 	
r8   c                    SR                  U R                  R                  U R                  [	        U S5      =(       a    [        U R                  5      =(       d    SU R                  U R                  5      $ rF  )	rG  r   r   r   rK   r   rA  rC  rB  r   s    r6   __repr__SysCaptureBase.__repr__  sS    9@@NN##IID&!5d499oBKKLL
 	
r8   c                    U R                   U;   d0   SR                  XR                   SR                  U5      5      5       eg Nz+cannot {} in state {!r}: expected one of {}z, rC  rG  joinr   opstatess      r6   _assert_stateSysCaptureBase._assert_state  ;    KK6!	
8??TYYv.
	
!r8   c                    U R                  SS5        [        [        U R                  U R                  5        SU l        g )Nr  r>  started)rT  setattrr"   r   rB  rC  r   s    r6   r  SysCaptureBase.start  s.    7$45TYY-r8   c                    U R                  SS5        U R                  S:X  a  g [        [        U R                  U R
                  5        U ?U R                  R                  5         SU l        g )Nr  r>  rY  	suspendedr  )rT  rC  rZ  r"   r   rA  rB  r   r   s    r6   r  SysCaptureBase.done  sR    6#RS;;& TYY		*Ir8   c                    U R                  SS5        [        [        U R                  U R                  5        SU l        g Nr  rY  r^  r^  )rT  rZ  r"   r   rA  rC  r   s    r6   r  SysCaptureBase.suspend  s.    9&>?TYY		*!r8   c                    U R                  SS5        U R                  S:X  a  g [        [        U R                  U R
                  5        SU l        g Nr  rb  rY  )rT  rC  rZ  r"   r   rB  r   s    r6   r  SysCaptureBase.resume  s=    8%=>;;)#TYY-r8   )rA  rC  r   rB  r   )r!   r   rB  zTextIO | Noner<  r  r   r   )rH  r   r   r   r   rR  r   rS  ztuple[str, ...]r   r   r   )r   r   r   r   r   r   rK  rT  r  r  r  r  r   r}   r8   r6   r:  r:  h  sU    04$EJ$$ -$>B$	$


 
"
 r8   r:  c                  ,    \ rS rSrSrSS jrSS jrSrg)	SysCaptureBinaryi  r8   c                   U R                  SS5        U R                  R                  S5        U R                  R                  R	                  5       nU R                  R                  S5        U R                  R                  5         U$ Nr  rb  r   rT  rB  r   rF   r   r   r   ress     r6   r  SysCaptureBinary.snap  d    6#;<!ll!!&&(!
r8   c                    U R                  SS5        U R                  R                  5         U R                  R                  R	                  U5        U R                  R                  R                  5         g Nr  rb  )rT  rA  r   rF   rs   r   s     r6   r  SysCaptureBinary.writeorg  sO    :'?@				t$		 r8   r}   Nr   bytesr   ru  r   r   r   r   r   r   r  r  r  r   r}   r8   r6   ri  ri    s    L!r8   ri  c                  ,    \ rS rSrSrSS jrSS jrSrg)	
SysCapturei  r   c                
   U R                  SS5        [        U R                  [        5      (       d   eU R                  R	                  5       nU R                  R                  S5        U R                  R                  5         U$ rk  )rT  r^   rB  r   r   r   r   rm  s     r6   r  SysCapture.snap  sc    6#;<$,,	2222ll##%!
r8   c                    U R                  SS5        U R                  R                  U5        U R                  R                  5         g rr  )rT  rA  rs   r   r   s     r6   r  SysCapture.writeorg  s1    :'?@				r8   r}   Nr   r8  rw  r}   r8   r6   ry  ry    s    Lr8   ry  c                  Z    \ rS rSrSS jrSS jrSS jrSS jrSS jrSS jr	SS jr
S	rg
)FDCaptureBasei  c                h   Xl          [        R                  " U5        S U l        [        R                  " U5      U l
        US:X  a.  [        [        R                  SS9U l        [        U5      U l        ON[        [        SS9SSSSS9U l        U[         ;   a  [        XR                  5      U l        O[#        U5      U l        S	U l        g ! [         a]    [        R
                  " [        R                  [        R                  5      U l        [        R                  " U R                  U5         GNf = f)
Nr   utf-8)rR   )rX   r   r   T)rR   rS   r   r   r>  )targetfdrO   fstattargetfd_invalidr   rN   devnullO_RDWRdup2rP   targetfd_saverB  ry  
syscapturer{   r   r?  r(  rC  )r   r  s     r6   r   FDCaptureBase.__init__  s     	)HHX  %)D!VVH-q=

W=DL0:80DDO&*  "DL <'",X||"D"+H"5#E  	5 13

BII0ND!GGD))84	5s   C
 
A#D10D1c                    SU R                   R                   SU R                   SU R                   SU R                  < SU R
                  < S3$ )N< z oldfd= _state=z	 tmpfile=>)r   r   r  r  rC  rB  r   s    r6   rK  FDCaptureBase.__repr__  sR    ''($--@R@R?S Tkk_Idll-=Q@	
r8   c                    U R                   U;   d0   SR                  XR                   SR                  U5      5      5       eg rN  rO  rQ  s      r6   rT  FDCaptureBase._assert_state  rV  r8   c                    U R                  SS5        [        R                  " U R                  R	                  5       U R
                  5        U R                  R                  5         SU l        g)z4Start capturing on targetfd using memorized tmpfile.r  rX  rY  N)	rT  rO   r  rB  rQ   r  r  r  rC  r   s    r6   r  FDCaptureBase.start  sI    7$45
##%t}}5r8   c                $   U R                  SS5        U R                  S:X  a  g[        R                  " U R                  U R
                  5        [        R                  " U R                  5        U R                  bZ  U R                  U R
                  :w  a   [        R                  " U R
                  5        [        R                  " U R                  5        U R                  R                  5         U R                  R                  5         SU l        g)zWStop capturing, restore streams, return original capture file,
seeked to position zero.r  r]  N)rT  rC  rO   r  r  r  r   r  r  r  rB  r   s    r6   r  FDCaptureBase.done  s     	6#RS;;& 
""DMM2
##$  ,$$5'HHT**+r8   c                    U R                  SS5        U R                  S:X  a  g U R                  R                  5         [        R
                  " U R                  U R                  5        SU l        g ra  )rT  rC  r  r  rO   r  r  r  r   s    r6   r  FDCaptureBase.suspend  sQ    9&>?;;+%!
""DMM2!r8   c                    U R                  SS5        U R                  S:X  a  g U R                  R                  5         [        R
                  " U R                  R                  5       U R                  5        SU l        g re  )	rT  rC  r  r  rO   r  rB  rQ   r  r   s    r6   r  FDCaptureBase.resume$  sX    8%=>;;)# 
##%t}}5r8   )rC  r  r  r  r  rB  N)r  r   r   r   r   rg  r   )r   r   r   r   r   rK  rT  r  r  r  r  r   r}   r8   r6   r  r    s&    '$R

  " r8   r  c                  0    \ rS rSrSrSrSS jrS	S jrSrg)
FDCaptureBinaryi-  zOCapture IO to/from a given OS-level file descriptor.

snap() produces `bytes`.
r8   c                   U R                  SS5        U R                  R                  S5        U R                  R                  R	                  5       nU R                  R                  S5        U R                  R                  5         U$ rk  rl  rm  s     r6   r  FDCaptureBinary.snap5  rp  r8   c                j    U R                  SS5        [        R                  " U R                  U5        g)"Write to original file descriptor.r  rb  N)rT  rO   rs   r  r   s     r6   r  FDCaptureBinary.writeorg=  s'    :'?@
##T*r8   r}   Nrt  rv  	r   r   r   r   __doc__r  r  r  r   r}   r8   r6   r  r  -  s    
 L+r8   r  c                  0    \ rS rSrSrSrSS jrS	S jrSrg)
	FDCaptureiC  zLCapture IO to/from a given OS-level file descriptor.

snap() produces text.
r   c                    U R                  SS5        U R                  R                  S5        U R                  R                  5       nU R                  R                  S5        U R                  R	                  5         U$ rk  )rT  rB  r   r   r   rm  s     r6   r  FDCapture.snapK  s^    6#;<!ll!!
r8   c                    U R                  SS5        [        R                  " U R                  UR	                  S5      5        g)r  r  rb  r  N)rT  rO   rs   r  encoder   s     r6   r  FDCapture.writeorgS  s0    :'?@
##T[[%9:r8   r}   Nr   r8  r  r}   r8   r6   r  r  C  s    
 L;r8   r  )      c                  .    \ rS rSr% SrS\S'   S\S'   Srg)CaptureResulti`  OThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.r	   rw   rx   r}   N)r   r   r   r   r  r"  r   r}   r8   r6   r  r  `  s    ]r8   r  c                      \ rS rSrSrSrSrg)r  ii  r  r}   N)r   r   r   r   r  r   r   r}   r8   r6   r  r  i  s     	^	r8   rw   rx   c                      \ rS rSrSrSr        SS jrSS jrSS jrSS jr	SSS jjr
SS	 jrSS
 jrSS jrSS jrSrg)MultiCaptureir  NFc                (    Xl         X l        X0l        g r   in_rw   rx   )r   r  rw   rx   s       r6   r   MultiCapture.__init__v  s     03/2/2r8   c                    SU R                   < SU R                  < SU R                  < SU R                  < SU R                  < S3$ )Nz<MultiCapture out=z err=z in_=r  z _in_suspended=r  )rw   rx   r  rC  _in_suspendedr   s    r6   rK  MultiCapture.__repr__  sJ     E$((U488, Okk_OD4F4F3IL	
r8   c                   SU l         U R                  (       a  U R                  R                  5         U R                  (       a  U R                  R                  5         U R                  (       a  U R                  R                  5         g g )NrY  )rC  r  r  rw   rx   r   s    r6   start_capturingMultiCapture.start_capturing  sM    88HHNN88HHNN88HHNN r8   c                    U R                  5       u  pU(       a*  U R                  c   eU R                  R                  U5        U(       a*  U R                  c   eU R                  R                  U5        X4$ )z?Pop current snapshot out/err capture and flush to orig streams.)
readouterrrw   r  rx   r   rw   rx   s      r6   pop_outerr_to_origMultiCapture.pop_outerr_to_orig  sa    ??$88'''HHc"88'''HHc"xr8   c                4   SU l         U R                  (       a  U R                  R                  5         U R                  (       a  U R                  R                  5         U(       a4  U R                  (       a"  U R                  R                  5         SU l        g g g )Nr^  T)rC  rw   r  rx   r  r  r   r  s     r6   suspend_capturingMultiCapture.suspend_capturing  s_    !88HH88HH488HH!%D 3r8   c                B   SU l         U R                  (       a  U R                  R                  5         U R                  (       a  U R                  R                  5         U R                  (       a1  U R
                  c   eU R
                  R                  5         SU l        g g )NrY  F)rC  rw   r  rx   r  r  r   s    r6   resume_capturingMultiCapture.resume_capturing  sg    88HHOO88HHOO88'''HHOO!&D r8   c                L   U R                   S:X  a  [        S5      eSU l         U R                  (       a  U R                  R                  5         U R                  (       a  U R                  R                  5         U R
                  (       a  U R
                  R                  5         gg)z+Stop capturing and reset capturing streams.stoppedzwas already stoppedN)rC  
ValueErrorrw   r  rx   r  r   s    r6   stop_capturingMultiCapture.stop_capturing  sb    ;;)#23388HHMMO88HHMMO88HHMMO r8   c                     U R                   S:H  $ )z7Whether actively capturing -- not suspended or stopped.rY  )rC  r   s    r6   
is_startedMultiCapture.is_started  s    {{i''r8   c                    U R                   (       a  U R                   R                  5       OSnU R                  (       a  U R                  R                  5       OSn[        X5      $ r4  )rw   r  rx   r  r  s      r6   r  MultiCapture.readouterr  s;    !%dhhmmor!%dhhmmorS&&r8   )r  rC  rx   r  rw   )r  CaptureBase[AnyStr] | Nonerw   r  rx   r  r   r   r   r   )r   ztuple[AnyStr, AnyStr]Fr  r  r   r   r  r   zCaptureResult[AnyStr])r   r   r   r   rC  r  r   rK  r  r  r  r  r  r  r  r   r}   r8   r6   r  r  r  s_    FM3'3 (3 (	3
 
3
	&	'
('r8   r  c           	     4   U S:X  a&  [        [        S5      [        S5      [        S5      S9$ U S:X  a&  [        [        S5      [        S5      [        S5      S9$ U S:X  a  [        S S S S9$ U S:X  a  [        S [        SS	S
9[        SS	S
9S9$ [        SU < 35      e)Nr!   r   r%  r&  r  r"   r#   r$   Tr;  zunknown capturing method: )r  r  ry  r  )r(   s    r6   _get_multicapturer    s    ~	!)A,IaLQQ	5
1:a=jQRmTT	4$D99	9	*QD1z!7N
 	
 1&<
==r8   c                     \ rS rSrSrS!S jrS"S jrS#S jrS$S jrS%S jr	S%S jr
S%S	 jrS&S'S
 jjrS&S'S jjrS%S jrS(S jrS)S jrS%S jrS%S jrS%S jrS%S jrS%S jr\R.                  S*S j5       r\R.                  S+S j5       r\" SS9    S,S j5       r\" SS9S-S j5       r\" SS9S-S j5       r\" SS9S-S j5       r\" SS9S%S j5       r\" SS9S%S j5       r Sr!g ).rk   i  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.
c                ,    Xl         S U l        S U l        g r   _method_global_capturing_capture_fixture)r   r(   s     r6   r   CaptureManager.__init__  s    $;?<@r8   c                \    SU R                   < SU R                  < SU R                  < S3$ )Nz<CaptureManager _method=z _global_capturing=z _capture_fixture=r  r  r   s    r6   rK  CaptureManager.__repr__  s:    &t||&66I$J`J`Ic d  $ 5 58;	
r8   c                    U R                  5       (       a  gU R                  (       a#  SU R                  R                  R                   3$ g)Nglobalzfixture F)is_globally_capturingr  requestfixturenamer   s    r6   is_capturingCaptureManager.is_capturing  s@    %%''  d33;;GGHIIr8   c                     U R                   S:g  $ )Nr#   )r  r   s    r6   r  $CaptureManager.is_globally_capturing  s    ||t##r8   c                    U R                   b   e[        U R                  5      U l         U R                   R                  5         g r   )r  r  r  r  r   s    r6   ro   %CaptureManager.start_global_capturing  s7    %%---!24<<!@..0r8   c                    U R                   b<  U R                   R                  5         U R                   R                  5         S U l         g g r   )r  r  r  r   s    r6   rn   $CaptureManager.stop_global_capturing  s?    !!-""557""113%)D" .r8   c                T    U R                   b  U R                   R                  5         g g r   )r  r  r   s    r6   resume_global_capture$CaptureManager.resume_global_capture  s'     !!-""335 .r8   c                R    U R                   b  U R                   R                  US9  g g )Nr  )r  r  r  s     r6   rp   %CaptureManager.suspend_global_capture  s*    !!-""444= .r8   c                F    U R                  5         U R                  U5        g r   )suspend_fixturerp   r  s     r6   r  CaptureManager.suspend  s    ##C(r8   c                D    U R                  5         U R                  5         g r   )r  resume_fixturer   s    r6   r  CaptureManager.resume  s    ""$r8   c                T    U R                   c   eU R                   R                  5       $ r   )r  r  r   s    r6   rr   "CaptureManager.read_global_capture  s)    %%111%%0022r8   c                    U R                   (       aX  U R                   R                  R                  nUR                  R                  nUR                  R                  SU SU S35        Xl         g )Nzcannot use z and z at the same time)r  r  r  
raiseerror)r   capture_fixturecurrent_fixturerequested_fixtures       r6   set_fixtureCaptureManager.set_fixture%  sf      "33;;GGO / 7 7 C C##../0o5FFWX !0r8   c                    S U l         g r   )r  r   s    r6   unset_fixtureCaptureManager.unset_fixture.  s
     $r8   c                \    U R                   (       a  U R                   R                  5         gg)ztIf the current item is using ``capsys`` or ``capfd``, activate
them so they take precedence over the global capture.N)r  _startr   s    r6   activate_fixtureCaptureManager.activate_fixture1  s$       !!((* !r8   c                \    U R                   (       a  U R                   R                  5         gg)zDDeactivate the ``capsys`` or ``capfd`` fixture of this item, if any.N)r  r   r   s    r6   deactivate_fixture!CaptureManager.deactivate_fixture7  s"      !!'') !r8   c                \    U R                   (       a  U R                   R                  5         g g r   )r  _suspendr   s    r6   r  CaptureManager.suspend_fixture<  s"      !!**, !r8   c                \    U R                   (       a  U R                   R                  5         g g r   )r  _resumer   s    r6   r  CaptureManager.resume_fixture@  s"      !!))+ !r8   c              #    #    U R                   =(       a    U R                   R                  5       nU(       a  U R                  5         U R                  =(       a    U R                  R	                  5       nU(       a  U R                  5          Sv   U(       a  U R                  5         U(       a  U R                  5         gg! U(       a  U R                  5         U(       a  U R                  5         f f = f7f)zLContext manager to temporarily disable global and current fixture capturing.N)r  _is_startedr  r  r  rp   r  r  )r   
do_fixture	do_globals      r6   global_and_fixture_disabled*CaptureManager.global_and_fixture_disabledF  s      **Rt/D/D/P/P/R
  "**Rt/E/E/P/P/R	'')	&**,##%  **,##% s   B	C4C  0C4 1C11C4c              #    #    U R                  5         U R                  5          S v   U R                  5         U R                  SS9  U R	                  5       u  p4UR                  USU5        UR                  USU5        g ! U R                  5         U R                  SS9  U R	                  5       u  p4UR                  USU5        UR                  USU5        f = f7f)NFr  ra   rb   )r  r	  r  rp   rr   add_report_section)r   whenitemrw   rx   s        r6   item_captureCaptureManager.item_captureW  s     ""$	9##%''E'2//1HC##D(C8##D(C8 ##%''E'2//1HC##D(C8##D(C8s   !CB  AC ACCTre   c              #  l  #    [        U[        5      (       a  U R                  5          S v nU R                  5         U R	                  5       u  p4U(       a  UR
                  R                  SU45        U(       a  UR
                  R                  SU45        U$ S v nU$ ! U R                  5         f = f7f)NzCaptured stdoutzCaptured stderr)r^   r   r  rp   rr   sectionsappend)r   	collectorreprw   rx   s        r6   pytest_make_collect_report)CaptureManager.pytest_make_collect_reportg  s      i&&&&(.++-//1HC##%6$<=##%6$<= 
 C
 ++-s   &B4B A2B4B11B4c              #  l   #    U R                  SU5         S v sS S S 5        $ ! , (       d  f       g = f7f)Nsetupr  r   r  s     r6   pytest_runtest_setup#CaptureManager.pytest_runtest_setupz  s#     w- .--   4#
4
14c              #  l   #    U R                  SU5         S v sS S S 5        $ ! , (       d  f       g = f7f)Ncallr)  r*  s     r6   pytest_runtest_call"CaptureManager.pytest_runtest_call  s#     vt, -,,r-  c              #  l   #    U R                  SU5         S v sS S S 5        $ ! , (       d  f       g = f7f)Nteardownr)  r*  s     r6   pytest_runtest_teardown&CaptureManager.pytest_runtest_teardown  s#     z40 100r-  )tryfirstc                $    U R                  5         g r   rn   r   s    r6   pytest_keyboard_interrupt(CaptureManager.pytest_keyboard_interrupt      ""$r8   c                $    U R                  5         g r   r8  r   s    r6   pytest_internalerror#CaptureManager.pytest_internalerror  r;  r8   )r  r  r  N)r(   _CaptureMethodr   r   r   )r   z
str | boolr  r   r  r  )r   zCaptureResult[str])r  zCaptureFixture[Any]r   r   r   Generator[None])r  r   r  r   r   rA  )r#  r   r   z-Generator[None, CollectReport, CollectReport])r  r   r   rA  )"r   r   r   r   r  r   rK  r  r  ro   rn   r  rp   r  r  rr   r  r  r	  r  r  r  
contextlibcontextmanagerr  r  r   r%  r+  r0  r4  r9  r=  r   r}   r8   r6   rk   rk     s7   $A

$1
*6>)
30%+*
-, & &  9 9 d"	6 $ d  d  d  t% % t% %r8   rk   c                      \ rS rSrSrSS.       SS jjrSS jrSS jrSS jrSS	 jr	SS
 jr
SS jr\R                  SS j5       rSrg)CaptureFixturei  zxObject returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
:fixture:`capfd` and :fixture:`capfdbinary` fixtures.F	_ispytestc                   [        U5        Xl        X l        S U l        U R                  R                  U l        U R                  R                  U l        g r   )r   captureclassr  _capturer  _captured_out_captured_err)r   rI  r  rG  s       r6   r   CaptureFixture.__init__  sF     	y!7C59%)%6%6%C%C%)%6%6%C%Cr8   c                    U R                   cI  [        S U R                  S5      U R                  S5      S9U l         U R                   R                  5         g g )Nr%  r&  r  )rJ  r  rI  r  r   s    r6   r  CaptureFixture._start  sN    == (%%a(%%a(DM
 MM))+ !r8   c                    U R                   bh  U R                   R                  5       u  pU =R                  U-  sl        U =R                  U-  sl        U R                   R	                  5         S U l         g g r   )rJ  r  rK  rL  r  r  s      r6   r   CaptureFixture.close  s^    ==$}}779HC#%#%MM((* DM %r8   c                   U R                   U R                  p!U R                  b$  U R                  R                  5       u  p4X-  nX$-  nU R                  R
                  U l         U R                  R
                  U l        [        X5      $ )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.
)rK  rL  rJ  r  rI  r  r  )r   captured_outcaptured_errrw   rx   s        r6   r  CaptureFixture.readouterr  sx     &*%7%79K9Kl==$}}//1HCLL!..;;!..;;\88r8   c                T    U R                   b  U R                   R                  5         gg)z1Suspend this fixture's own capturing temporarily.N)rJ  r  r   s    r6   r  CaptureFixture._suspend  s!    ==$MM++- %r8   c                T    U R                   b  U R                   R                  5         gg)z0Resume this fixture's own capturing temporarily.N)rJ  r  r   s    r6   r  CaptureFixture._resume  s!    ==$MM**, %r8   c                R    U R                   b  U R                   R                  5       $ g)z5Whether actively capturing -- not disabled or closed.F)rJ  r  r   s    r6   r  CaptureFixture._is_started  s"    ==$==++--r8   c              #     #    U R                   R                  R                  R                  S5      nUR	                  5          Sv   SSS5        g! , (       d  f       g= f7f)z>Temporarily disable capturing while inside the ``with`` block.rh   N)r  configrj   	getpluginr  )r   
capmanagers     r6   disabledCaptureFixture.disabled  sF      &*\\%8%8%F%F%P%P&

 335 655s   A A!A	A!
AA!)rJ  rL  rK  rI  r  N)rI  ztype[CaptureBase[AnyStr]]r  r   rG  r  r   r   r   r  r  r@  )r   r   r   r   r  r   r  r   r  r  r  r  rB  rC  r`  r   r}   r8   r6   rE  rE    st    =  D/D D
 D 
D,!9".
-
  r8   rE  c              #     #    U R                   R                  R                  S5      n[        [        U SS9nUR                  U5        UR                  5         Uv   UR                  5         UR                  5         g7f)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"
rh   TrF  N)	r]  rj   r^  rE  ry  r  r  r   r  r  rv   r  s      r6   capsysrd    sh     & %^^99CCDTUF$ZDIO
'

   A;A=c              #     #    U R                   R                  R                  S5      n[        [        U SS9nUR                  U5        UR                  5         Uv   UR                  5         UR                  5         g7f)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"
rh   TrF  N)	r]  rj   r^  rE  ri  r  r  r   r  rc  s      r6   capsysbinaryrg    si     & %^^99CCDTUF$%5w$OO
'

re  c              #     #    U R                   R                  R                  S5      n[        [        U SS9nUR                  U5        UR                  5         Uv   UR                  5         UR                  5         g7f)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"
rh   TrF  N)	r]  rj   r^  rE  r  r  r  r   r  rc  s      r6   capfdri    sh     & %^^99CCDTUF$Y4HO
'

re  c              #     #    U R                   R                  R                  S5      n[        [        U SS9nUR                  U5        UR                  5         Uv   UR                  5         UR                  5         g7f)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"

rh   TrF  N)	r]  rj   r^  rE  r  r  r  r   r  rc  s      r6   capfdbinaryrk  7  sh     ( %^^99CCDTUF$_gNO
'

re  )r4   r   r   r   r   )rY   r   r   r   )rt   r   r   rA  )r(   r?  r   zMultiCapture[str])r  r   r   zGenerator[CaptureFixture[str]])r  r   r   z Generator[CaptureFixture[bytes]])Pr  
__future__r   r#  collectionsrB  rL   r   rO   r"   tempfiler   typesr   typingr   r	   r
   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?  r7   r?   rC   rd   ry   rM   r{   r   r   r   ABCr  r?  r   r(  r:  ru  ri  ry  r  r  r  version_infor  
namedtupler  r  rk   rE  rd  rg  ri  rk  r}   r8   r6   <module>r{     sm   1 " 
   	 # 	 
 "                & ! # , - $ ' #   ) 56&"41n 
$ <1""" 1 6   6$9 $J J`$#''76? $@ xH5C  2@ [( @ F!~e, !$$ "\ K' \ ~+mE* +,;c" ;6 w-

GFO  ?Q'76? Q'h>"x% x%vKWV_ Kb 	 	6 	 	6 	 	6 	 	r8   