
    [Ogx              	         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.SSS  jr/STS! jr0SUS" jr1\ " S#S$9SVS% j5       r2 " S& S'\Rf                  5      r4 " S( S)\Rf                  5      r5 " S* S+\55      r6 " S, S-\5      r7 " S. S/\Rp                  \\   5      r9S0S1S2S3.r: " S4 S5\9\;   5      r< " S6 S7\9\   5      r= " S8 S9\=\>   5      r? " S: S;\=\;   5      r@ " S< S=\9\   5      rA " S> S?\A\>   5      rB " S@ SA\A\;   5      rC\	R                  SB:  d  \(       a  \ " SC SD\\\   5      5       rEO" " SE SD\R                  " SDSFSG/5      \\   5      rE " SH SI\\   5      rGSWSJ jrH " SK SL5      rI " SM SN\\   5      rJ\&SXSO j5       rK\&SYSP j5       rL\&SXSQ j5       rM\&SYSR j5       rNg)Zz+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     T/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-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                $  ^  [         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      $ )NrC   r   w)hasattrrB   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingstreams      r6   _reopen_stdio3_windowsconsoleio_workaround.<locals>._reopen_stdiov   sr    v}}e,,aCII
#T5JJHHJJ
 	
r8   rbwb)r"   r;   r<   rG   rB   rC   
isinstancerH   _WindowsConsoleIOstdinstdoutstderr)rU   
raw_stdoutrV   s   `  r6   _windowsconsoleio_workaroundr`   R   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              #  Z  #    U R                   nUR                  S:X  a  [        [        R                  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/   r`   r"   r]   r?   pluginmanagerCaptureManagerregisteradd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureBaseExceptionread_global_capturewriter^   )early_confignsrf   capmanouterrs         r6   pytest_load_initial_conftestsru      s     		*	*B	zzT$SZZ0 ..MBJJ'F6#34 V99: !!#		,))+F))+ --/



	s1   BD+"B7 &C 6D+7C		C AD((D+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)reprrB   selfs    r6   nameEncodedFile.name   s     DKK  r8   c                N    U R                   R                  R                  SS5      $ )Nb )rB   rS   replacer}   s    r6   rS   EncodedFile.mode   s!     {{''R00r8   Nreturnstr)	__name__
__module____qualname____firstlineno__	__slots__propertyr   rS   __static_attributes__ry   r8   r6   rw   rw      s-    I! !
 1 1r8   rw   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)rN   newlinewrite_through)super__init__rH   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   )rZ   rB   rH   r   getvaluedecoder}   s    r6   r   CaptureIO.getvalue   s;    $++rzz2222{{##%,,W55r8   ry   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   ro   r   )r~   sr   s     r6   ro   TeeCaptureIO.write   s$    a{{  ##r8   )r   )r   r   r   r   )r   r   r   int)r   r   r   r   r   ro   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__rN   r}   s    r6   rN   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{   )readliner}   s    r6   __next__DontReadFromInput.__next__   s    }}r8   c                    [        S5      er   r   )r~   hints     r6   	readlinesDontReadFromInput.readlines   r   r8   c                    U $ r{   ry   r}   s    r6   __iter__DontReadFromInput.__iter__       r8   c                    [        S5      e)Nz/redirected stdin is pseudofile, has no fileno()r   r}   s    r6   rM   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NFry   r}   s    r6   isattyDontReadFromInput.isatty       r8   c                    g r{   ry   r}   s    r6   closeDontReadFromInput.close       r8   c                    gr   ry   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   ry   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   ro   DontReadFromInput.write   r   r8   c                    [        S5      e)NzCannot write to stdinr   )r~   liness     r6   
writelinesDontReadFromInput.writelines   r   r8   c                    gr   ry   r}   s    r6   writableDontReadFromInput.writable  r   r8   c                    U $ r{   ry   r}   s    r6   	__enter__DontReadFromInput.__enter__  r   r8   c                    g r{   ry   )r~   typevalue	tracebacks       r6   __exit__DontReadFromInput.__exit__	  s     	r8   c                    U $ r{   ry   r}   s    r6   rB   DontReadFromInput.buffer  s	     r8   ry   r   )rF   )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   rN   r   r   r   r   r   rM   r   r   r   r   r   r   r   r   ro   r   r   r   r   rB   r   ry   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.start!  r  r8   c                    [        5       er{   r  r}   s    r6   doneCaptureBase.done%  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.writeorg1  r  r8   c                    [        5       er{   r  r}   s    r6   snapCaptureBase.snap5  r  r8   ry   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   ry   r8   r6   r  r    s    $ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $r8   r  r\   r]   r^   )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)	NoCapturei=  r   c                    g r{   ry   r	  s     r6   r   NoCapture.__init__@  r   r8   c                    g r{   ry   r}   s    r6   r  NoCapture.startC  r   r8   c                    g r{   ry   r}   s    r6   r  NoCapture.doneF  r   r8   c                    g r{   ry   r}   s    r6   r  NoCapture.suspendI  r   r8   c                    g r{   ry   r}   s    r6   r  NoCapture.resumeL  r   r8   c                    gNr   ry   r}   s    r6   r  NoCapture.snapO  s    r8   c                    g r{   ry   r   s     r6   r  NoCapture.writeorgR  r   r8   ry   Nr  r   r   r   r   r   r   )r   r   r   r   r  r   r  r  r  r  r  r  r   ry   r8   r6   r%  r%  =  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)SysCaptureBaseiV  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!   r?  r9  r   s        r6   r   SysCaptureBase.__init__W  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}>r>  z<UNSET>)formatr   rG   r|   r>  r@  r?  )r~   
class_names     r6   r|   SysCaptureBase.repre  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      $ rC  )	rD  r   r   r   rG   r|   r>  r@  r?  r}   s    r6   __repr__SysCaptureBase.__repr__n  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, r@  rD  joinr~   opstatess      r6   _assert_stateSysCaptureBase._assert_statew  ;    KK6!	
8??TYYv.
	
!r8   c                    U R                  SS5        [        [        U R                  U R                  5        SU l        g )Nr  r;  started)rQ  setattrr"   r   r?  r@  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;  rV  	suspendedr  )rQ  r@  rW  r"   r   r>  r?  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  rV  r[  r[  )rQ  rW  r"   r   r>  r@  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  r_  rV  )rQ  r@  rW  r"   r   r?  r}   s    r6   r  SysCaptureBase.resume  s=    8%=>;;)#TYY-r8   )r>  r@  r   r?  r{   )r!   r   r?  zTextIO | Noner9  r  r   r   )rE  r   r   r   r   rO  r   rP  ztuple[str, ...]r   r   r   )r   r   r   r   r   r|   rH  rQ  r  r  r  r  r   ry   r8   r6   r7  r7  V  sU    04$EJ$$ -$>B$	$


 
"
 r8   r7  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  r_  r   rQ  r?  r   rB   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  r_  )rQ  r>  r   rB   ro   r   s     r6   r  SysCaptureBinary.writeorg  sO    :'?@				t$		 r8   ry   Nr   bytesr   rr  r   r   r   r   r   r   r  r  r  r   ry   r8   r6   rf  rf    s    L!r8   rf  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$ rh  )rQ  rZ   r?  r   r   r   r   rj  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 ro  )rQ  r>  ro   r   r   s     r6   r  SysCapture.writeorg  s1    :'?@				r8   ry   Nr   r5  rt  ry   r8   r6   rv  rv    s    Lr8   rv  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)rN   )rT   r   r   T)rN   rO   r   r   r;  )targetfdrK   fstattargetfd_invalidr   rJ   devnullO_RDWRdup2rL   targetfd_saver?  rv  
syscapturerw   r   r<  r%  r@  )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  r@  r?  r}   s    r6   rH  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 rK  rL  rN  s      r6   rQ  FDCaptureBase._assert_state  rS  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  rU  rV  N)	rQ  rK   r  r?  rM   r  r  r  r@  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  rZ  N)rQ  r@  rK   r  r  r  r   r  r  r  r?  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 r^  )rQ  r@  r  r  rK   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 rb  )	rQ  r@  r  r  rK   r  r?  rM   r  r}   s    r6   r  FDCaptureBase.resume  sX    8%=>;;)# 
##%t}}5r8   )r@  r  r  r  r  r?  N)r  r   r   r   r   rd  r   )r   r   r   r   r   rH  rQ  r  r  r  r  r   ry   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$ rh  ri  rj  s     r6   r  FDCaptureBinary.snap#  rm  r8   c                j    U R                  SS5        [        R                  " U R                  U5        g)"Write to original file descriptor.r  r_  N)rQ  rK   ro   r  r   s     r6   r  FDCaptureBinary.writeorg+  s'    :'?@
##T*r8   ry   Nrq  rs  	r   r   r   r   __doc__r  r  r  r   ry   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)
	FDCapturei1  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$ rh  )rQ  r?  r   r   r   rj  s     r6   r  FDCapture.snap9  s^    6#;<!ll!!
r8   c                    U R                  SS5        [        R                  " U R                  UR	                  S5      5        g)r  r  r_  r~  N)rQ  rK   ro   r  encoder   s     r6   r  FDCapture.writeorgA  s0    :'?@
##T[[%9:r8   ry   Nr   r5  r  ry   r8   r6   r  r  1  s    
 L;r8   r  )      c                  .    \ rS rSr% SrS\S'   S\S'   Srg)CaptureResultiN  OThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.r	   rs   rt   ry   N)r   r   r   r   r  r  r   ry   r8   r6   r  r  N  s    ]r8   r  c                      \ rS rSrSrSrSrg)r  iW  r  ry   N)r   r   r   r   r  r   r   ry   r8   r6   r  r  W  s     	^	r8   rs   rt   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)MultiCapturei`  NFc                (    Xl         X l        X0l        g r{   in_rs   rt   )r~   r  rs   rt   s       r6   r   MultiCapture.__init__d  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  )rs   rt   r  r@  _in_suspendedr}   s    r6   rH  MultiCapture.__repr__n  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 )NrV  )r@  r  r  rs   rt   r}   s    r6   start_capturingMultiCapture.start_capturingt  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.)
readouterrrs   r  rt   r~   rs   rt   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)r@  rs   r  rt   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 )NrV  F)r@  rs   r  rt   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)r@  
ValueErrorrs   r  rt   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.rV  )r@  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      $ r1  )rs   r  rt   r  r  s      r6   r  MultiCapture.readouterr  s;    !%dhhmmor!%dhhmmorS&&r8   )r  r@  rt   r  rs   )r  CaptureBase[AnyStr] | Noners   r  rt   r  r   r   r   r   )r   ztuple[AnyStr, AnyStr]Fr  r  r   r   r  r   zCaptureResult[AnyStr])r   r   r   r   r@  r  r   rH  r  r  r  r  r  r  r  r   ry   r8   r6   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$   Tr8  zunknown capturing method: )r  r  rv  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 ).rg   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   rH  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   rk   %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   rj   $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   rl   %CaptureManager.suspend_global_capture   s*    !!-""444= .r8   c                F    U R                  5         U R                  U5        g r{   )suspend_fixturerl   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   rn   "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_fixture  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_fixture%  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  rl   r  r  )r~   
do_fixture	do_globals      r6   global_and_fixture_disabled*CaptureManager.global_and_fixture_disabled4  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  r]   r^   )r  r  r	  rl   rn   add_report_section)r~   whenitemrs   rt   s        r6   item_captureCaptureManager.item_captureE  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Tra   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)rZ   r   r  rl   rn   sectionsappend)r~   	collectorreprs   rt   s        r6   pytest_make_collect_report)CaptureManager.pytest_make_collect_reportU  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_setuph  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_callm  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_teardownr  s#     z40 100r*  )tryfirstc                $    U R                  5         g r{   rj   r}   s    r6   pytest_keyboard_interrupt(CaptureManager.pytest_keyboard_interruptw      ""$r8   c                $    U R                  5         g r{   r5  r}   s    r6   pytest_internalerror#CaptureManager.pytest_internalerror{  r8  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   r>  )r   r   r   z-Generator[None, CollectReport, CollectReport])r  r   r   r>  )"r   r   r   r   r  r   rH  r  r  rk   rj   r  rl   r  r  rn   r  r  r  r	  r  r  
contextlibcontextmanagerr  r  r   r"  r(  r-  r1  r6  r:  r   ry   r8   r6   rg   rg     s7   $A

$1
*6>)
30%+*
-, & &  9 9 d"	6 $ d  d  d  t% % t% %r8   rg   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~   rF  r  rD  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  )rG  r  rF  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{   )rG  r  rH  rI  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.
)rH  rI  rG  r  rF  r  r  )r~   captured_outcaptured_errrs   rt   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)rG  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)rG  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)rG  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.rd   N)r  configrf   	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!)rG  rI  rH  rF  r  N)rF  ztype[CaptureBase[AnyStr]]r  r   rD  r  r   r   r   r  r  r=  )r   r   r   r   r  r   r  r   r  r  r  r  r?  r@  r]  r   ry   r8   r6   rB  rB    st    =  D/D D
 D 
D,!9".
-
  r8   rB  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"
rd   TrC  N)	rZ  rf   r[  rB  rv  r  r  r   r  r  rr   r  s      r6   capsysra    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"
rd   TrC  N)	rZ  rf   r[  rB  rf  r  r  r   r  r`  s      r6   capsysbinaryrd    si     & %^^99CCDTUF$%5w$OO
'

rb  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"
rd   TrC  N)	rZ  rf   r[  rB  r  r  r  r   r  r`  s      r6   capfdrf  	  sh     & %^^99CCDTUF$Y4HO
'

rb  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"

rd   TrC  N)	rZ  rf   r[  rB  r  r  r  r   r  r`  s      r6   capfdbinaryrh  %  sh     ( %^^99CCDTUF$_gNO
'

rb  )r4   r   r   r   r   )rU   r   r   r   )rp   r   r   r>  )r(   r<  r   zMultiCapture[str])r  r   r   zGenerator[CaptureFixture[str]])r  r   r   z Generator[CaptureFixture[bytes]])Or  
__future__r   r   collectionsr?  rH   r   rK   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?   r`   ru   rI   rw   r   r   r   ABCr  r<  r   r%  r7  rr  rf  rv  r|  r  r  version_infor  
namedtupler  r  rg   rB  ra  rd  rf  rh  ry   r8   r6   <module>rx     sh   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   