
    iݏ              	         S 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	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  \(       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    r0SVS! jr1SWS" jr2SWS# jr3SXS$ jr4\"" S%S&9SYS' j5       r5 " S( S)\
Rl                  5      r7 " S* S+\
Rl                  5      r8 " S, S-\85      r9 " S. S/\5      r: " S0 S1\Rv                  \\   5      r<S2S3S4S5.r= " S6 S7\<\>   5      r? " S8 S9\<\   5      r@ " S: S;\@\A   5      rB " S< S=\@\>   5      rC " S> S?\<\   5      rD " S@ SA\D\A   5      rE " SB SC\D\>   5      rF\R                  SD:  d  \(       a  \ " SE SF\\\   5      5       rHO" " SG SF\R                  " SFSHSI/5      \\   5      rH " SJ SK\\   5      rJSZSL jrK " SM SN5      rL " SO SP\\   5      rM\(S[SQ j5       rN\(S[SR j5       rO\(S\SS j5       rP\(S[ST j5       rQ\(S\SU j5       rRg)]z+Per-test stdout/stderr capturing mechanism.    )annotationsN)	Generator)Iterable)IteratorUnsupportedOperation)TemporaryFile)TracebackType)Any)AnyStr)BinaryIO)cast)Final)final)Generic)Literal)
NamedTuple)TextIO)TYPE_CHECKING)Self)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)	Collector)File)Item)CollectReportfdsysnotee-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
_addoption)parsergroups     N/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/_pytest/capture.pypytest_addoptionr9   1   sW    OOI&E	OO.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    r8   _colorama_workaroundrA   D   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@   rC   s    r8   _readline_workaroundrE   S   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      $ )NrI   r   w)hasattrrH   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingstreams      r8   _reopen_stdio3_windowsconsoleio_workaround.<locals>._reopen_stdio   sr    v}}e,,aCII
#T5JJHHJJ
 	
r:   rbwb)r#   r=   r>   rM   rH   rI   
isinstancerN   _WindowsConsoleIOstdinstdoutstderr)r[   
raw_stdoutr\   s   `  r8   _windowsconsoleio_workaroundrf   d   s    0 <<""7++ws<O/P/P 68$$&-fmmU&C&C""Jj""6"677
 cii.CIszz40CJszz40CJr:   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_namespacer0   rf   r#   rc   rA   rE   pluginmanagerCaptureManagerregisteradd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureBaseExceptionread_global_capturewriterd   )early_confignsrl   capmanouterrs         r8   pytest_load_initial_conftestsr{      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)reprrH   selfs    r8   nameEncodedFile.name   s     DKK  r:   c                    [        U R                  S5      (       d   e[        [        U R                  R                  R                  SS5      5      $ )NrY   b )rM   rH   r   strrY   replacer   s    r8   rY   EncodedFile.mode   s?     t{{F++++C))11#r:;;r:   Nreturnr   )	__name__
__module____qualname____firstlineno__	__slots__propertyr   rY   __static_attributes__r   r:   r8   r}   r}      s-    I! !
 < <r:   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)rT   newlinewrite_through)super__init__rN   BytesIO)r   	__class__s    r8   r   CaptureIO.__init__   s     SWXr:   c                    [        U R                  [        R                  5      (       d   eU R                  R	                  5       R                  S5      $ )Nr   )r`   rH   rN   r   getvaluedecoder   s    r8   r   CaptureIO.getvalue   s;    $++rzz2222{{##%,,W55r:   r   r   Noner   )r   r   r   r   r   r   r   __classcell__r   s   @r8   r   r      s    Y6 6r:   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     r8   r   TeeCaptureIO.__init__   s    r:   c                X   > [         TU ]  U5        U R                  R                  U5      $ r   )r   ru   r   )r   sr   s     r8   ru   TeeCaptureIO.write   s$    a{{  ##r:   )r   )r   r   r   r   )r   r   r   int)r   r   r   r   r   ru   r   r   r   s   @r8   r   r      s    $ $r:   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__rT   r   s    r8   rT   DontReadFromInput.encoding   s"    }}(((}}%%%r:   c                    [        S5      eNzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorr   sizes     r8   readDontReadFromInput.read       X
 	
r:   c                "    U R                  5       $ r   rD   r   s    r8   __next__DontReadFromInput.__next__   s    }}r:   c                    [        S5      er   r   )r   hints     r8   	readlinesDontReadFromInput.readlines   r   r:   c                    U $ r   r   r   s    r8   __iter__DontReadFromInput.__iter__       r:   c                    [        S5      e)Nz/redirected stdin is pseudofile, has no fileno()r   r   s    r8   rS   DontReadFromInput.fileno   s    "#TUUr:   c                    [        S5      e)Nz.redirected stdin is pseudofile, has no flush()r   r   s    r8   flushDontReadFromInput.flush   s    "#STTr:   c                    gNFr   r   s    r8   isattyDontReadFromInput.isatty       r:   c                    g r   r   r   s    r8   closeDontReadFromInput.close       r:   c                    gr   r   r   s    r8   readableDontReadFromInput.readable  r   r:   c                    [        S5      e)Nz0redirected stdin is pseudofile, has no seek(int)r   )r   offsetwhences      r8   seekDontReadFromInput.seek  s    "#UVVr:   c                    gr   r   r   s    r8   seekableDontReadFromInput.seekable  r   r:   c                    [        S5      e)Nz-redirected stdin is pseudofile, has no tell()r   r   s    r8   tellDontReadFromInput.tell  s    "#RSSr:   Nc                    [        S5      e)Nzcannot truncate stdinr   r   s     r8   truncateDontReadFromInput.truncate      "#:;;r:   c                    [        S5      e)Nzcannot write to stdinr   r   datas     r8   ru   DontReadFromInput.write  r   r:   c                    [        S5      e)NzCannot write to stdinr   )r   liness     r8   
writelinesDontReadFromInput.writelines  r   r:   c                    gr   r   r   s    r8   writableDontReadFromInput.writable  r   r:   c                    U $ r   r   r   s    r8   	__enter__DontReadFromInput.__enter__  r   r:   c                    g r   r   )r   typevalue	tracebacks       r8   __exit__DontReadFromInput.__exit__  s     	r:   c                    U $ r   r   r   s    r8   rH   DontReadFromInput.buffer%  s	     r:   r   r   )rL   )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   rT   r   rC   r   r   r   rS   r   r   r   r   r   r   r   r   ru   r   r   r   r  rH   r   r   r:   r8   r   r      s    & &

 H

VUWT<<<( $ (	
 
  r:   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     r8   r   CaptureBase.__init__1      !##r:   c                    [        5       er   r  r   s    r8   startCaptureBase.start5  r  r:   c                    [        5       er   r  r   s    r8   doneCaptureBase.done9  r  r:   c                    [        5       er   r  r   s    r8   suspendCaptureBase.suspend=  r  r:   c                    [        5       er   r  r   s    r8   resumeCaptureBase.resumeA  r  r:   c                    [        5       er   r  r   s     r8   writeorgCaptureBase.writeorgE  r  r:   c                    [        5       er   r  r   s    r8   snapCaptureBase.snapI  r  r:   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   r:   r8   r	  r	  .  s    $ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $r:   r	  rb   rc   rd   )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)	NoCaptureiQ  r   c                    g r   r   r  s     r8   r   NoCapture.__init__T  r   r:   c                    g r   r   r   s    r8   r  NoCapture.startW  r   r:   c                    g r   r   r   s    r8   r  NoCapture.doneZ  r   r:   c                    g r   r   r   s    r8   r  NoCapture.suspend]  r   r:   c                    g r   r   r   s    r8   r  NoCapture.resume`  r   r:   c                    gNr   r   r   s    r8   r!  NoCapture.snapc  s    r:   c                    g r   r   r   s     r8   r  NoCapture.writeorgf  r   r:   r   Nr#  r   r   r   r   r   r   )r   r   r   r   r
  r   r  r  r  r  r!  r  r   r   r:   r8   r*  r*  Q  s*    Lr:   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)SysCaptureBaseij  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 )Nrb   initialized)
patchsysdictgetattrr#   _oldr   r   r   r   tmpfile_state)r   r"   rD  r>  r   s        r8   r   SysCaptureBase.__init__k  sU     B#C.		?w+--0)+l4996M#r:   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}>rC  z<UNSET>)formatr   rM   r   rC  rE  rD  )r   
class_names     r8   r   SysCaptureBase.repry  sI    9@@IIT6"6tDIID9KKLL
 	
r:   c                    SR                  U R                  R                  U R                  [	        U S5      =(       a    [        U R                  5      =(       d    SU R                  U R                  5      $ rH  )	rI  r   r   r   rM   r   rC  rE  rD  r   s    r8   __repr__SysCaptureBase.__repr__  sS    9@@NN##IIT6"6tDIID9KKLL
 	
r:   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, rE  rI  joinr   opstatess      r8   _assert_stateSysCaptureBase._assert_state  ;    {{f$ 	
9@@KK6!2	
$r:   c                    U R                  SS5        [        [        U R                  U R                  5        SU l        g )Nr  r@  started)rV  setattrr#   r   rD  rE  r   s    r8   r  SysCaptureBase.start  s.    7$45TYY-r:   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@  r[  	suspendedr  )rV  rE  r\  r#   r   rC  rD  r   r   s    r8   r  SysCaptureBase.done  sR    6#RS;;& TYY		*Ir:   c                    U R                  SS5        [        [        U R                  U R                  5        SU l        g Nr  r[  r`  r`  )rV  r\  r#   r   rC  rE  r   s    r8   r  SysCaptureBase.suspend  s.    9&>?TYY		*!r:   c                    U R                  SS5        U R                  S:X  a  g [        [        U R                  U R
                  5        SU l        g Nr  rd  r[  )rV  rE  r\  r#   r   rD  r   s    r8   r  SysCaptureBase.resume  s=    8%=>;;)#TYY-r:   )rC  rE  r   rD  r   )r"   r   rD  zTextIO | Noner>  r  r   r   )rJ  r   r   r   r   rT  r   rU  ztuple[str, ...]r   r   r   )r   r   r   r   r   r   rM  rV  r  r  r  r  r   r   r:   r8   r<  r<  j  sU    04$EJ$$ -$>B$	$


 
"
 r:   r<  c                  ,    \ rS rSrSrSS jrSS jrSrg)	SysCaptureBinaryi  r:   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!  rd  r   rV  rD  r   rH   r   r   r   ress     r8   r!  SysCaptureBinary.snap  d    6#;<!ll!!&&(!
r:   c                    U R                  SS5        U R                  R                  5         U R                  R                  R	                  U5        U R                  R                  R                  5         g Nr  rd  )rV  rC  r   rH   ru   r   s     r8   r  SysCaptureBinary.writeorg  sO    :'?@				t$		 r:   r   Nr   bytesr   rw  r   r   r   r   r   r   r
  r!  r  r   r   r:   r8   rk  rk    s    L!r:   rk  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$ rm  )rV  r`   rD  r   r   r   r   ro  s     r8   r!  SysCapture.snap  sc    6#;<$,,	2222ll##%!
r:   c                    U R                  SS5        U R                  R                  U5        U R                  R                  5         g rt  )rV  rC  ru   r   r   s     r8   r  SysCapture.writeorg  s1    :'?@				r:   r   Nr   r:  ry  r   r:   r8   r{  r{    s    Lr:   r{  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)rT   )rZ   r   r   T)rT   rU   r   r   r@  )targetfdrQ   fstattargetfd_invalidr   rP   devnullO_RDWRdup2rR   targetfd_saverD  r{  
syscapturer}   r	   rA  r*  rE  )r   r  s     r8   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  rE  rD  r   s    r8   rM  FDCaptureBase.__repr__  sR    ''($--@R@R?S Tkk_Idll-=Q@	
r:   c                    U R                   U;   d0   SR                  XR                   SR                  U5      5      5       eg rP  rQ  rS  s      r8   rV  FDCaptureBase._assert_state   rX  r:   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  rZ  r[  N)	rV  rQ   r  rD  rS   r  r  r  rE  r   s    r8   r  FDCaptureBase.start  sI    7$45
##%t}}5r:   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)rV  rE  rQ   r  r  r  r   r  r  r  rD  r   s    r8   r  FDCaptureBase.done  s     	6#RS;;& 
""DMM2
##$  ,$$5'HHT**+r:   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 rc  )rV  rE  r  r  rQ   r  r  r  r   s    r8   r  FDCaptureBase.suspend  sQ    9&>?;;+%!
""DMM2!r:   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 rg  )	rV  rE  r  r  rQ   r  rD  rS   r  r   s    r8   r  FDCaptureBase.resume&  sX    8%=>;;)# 
##%t}}5r:   )rE  r  r  r  r  rD  N)r  r   r   r   r   ri  r   )r   r   r   r   r   rM  rV  r  r  r  r  r   r   r:   r8   r  r    s&    '$R

  " r:   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`.
r:   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$ rm  rn  ro  s     r8   r!  FDCaptureBinary.snap7  rr  r:   c                j    U R                  SS5        [        R                  " U R                  U5        g)"Write to original file descriptor.r  rd  N)rV  rQ   ru   r  r   s     r8   r  FDCaptureBinary.writeorg?  s'    :'?@
##T*r:   r   Nrv  rx  	r   r   r   r   __doc__r
  r!  r  r   r   r:   r8   r  r  /  s    
 L+r:   r  c                  0    \ rS rSrSrSrSS jrS	S jrSrg)
	FDCaptureiE  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$ rm  )rV  rD  r   r   r   ro  s     r8   r!  FDCapture.snapM  s^    6#;<!ll!!
r:   c                    U R                  SS5        [        R                  " U R                  UR	                  S5      5        g)r  r  rd  r  N)rV  rQ   ru   r  encoder   s     r8   r  FDCapture.writeorgU  s0    :'?@
##T[[%9:r:   r   Nr   r:  r  r   r:   r8   r  r  E  s    
 L;r:   r  )      c                  .    \ rS rSr% SrS\S'   S\S'   Srg)CaptureResultib  OThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.r   ry   rz   r   N)r   r   r   r   r  r$  r   r   r:   r8   r  r  b  s    ]r:   r  c                      \ rS rSrSrSrSrg)r  ik  r  r   N)r   r   r   r   r  r   r   r   r:   r8   r  r  k  s     	^	r:   ry   rz   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)MultiCaptureit  NFc                (    Xl         X l        X0l        g r   in_ry   rz   )r   r  ry   rz   s       r8   r   MultiCapture.__init__x  s     03/2/2r:   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  )ry   rz   r  rE  _in_suspendedr   s    r8   rM  MultiCapture.__repr__  sJ     E$((U488, Okk_OD4F4F3IL	
r:   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 )Nr[  )rE  r  r  ry   rz   r   s    r8   start_capturingMultiCapture.start_capturing  sM    88HHNN88HHNN88HHNN r:   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.)
readouterrry   r  rz   r   ry   rz   s      r8   pop_outerr_to_origMultiCapture.pop_outerr_to_orig  sa    ??$88'''HHc"88'''HHc"xr:   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)rE  ry   r  rz   r  r  r   r  s     r8   suspend_capturingMultiCapture.suspend_capturing  s_    !88HH88HH488HH!%D 3r:   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 )Nr[  F)rE  ry   r  rz   r  r  r   s    r8   resume_capturingMultiCapture.resume_capturing  sg    88HHOO88HHOO88'''HHOO!&D r:   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)rE  
ValueErrorry   r  rz   r  r   s    r8   stop_capturingMultiCapture.stop_capturing  sb    ;;)#23388HHMMO88HHMMO88HHMMO r:   c                     U R                   S:H  $ )z7Whether actively capturing -- not suspended or stopped.r[  )rE  r   s    r8   
is_startedMultiCapture.is_started  s    {{i''r:   c                    U R                   (       a  U R                   R                  5       OSnU R                  (       a  U R                  R                  5       OSn[        X5      $ r6  )ry   r!  rz   r  r  s      r8   r  MultiCapture.readouterr  s;    !%dhhmmor!%dhhmmorS&&r:   )r  rE  rz   r  ry   )r  CaptureBase[AnyStr] | Nonery   r  rz   r  r   r   r   r   )r   ztuple[AnyStr, AnyStr]Fr  r  r   r   r  r   zCaptureResult[AnyStr])r   r   r   r   rE  r  r   rM  r  r  r  r  r  r  r  r   r   r:   r8   r  r  t  s_    FM3'3 (3 (	3
 
3
	&	'
('r:   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  r{  r  )r)   s    r8   _get_multicapturer    s    ~	!)A,IaLQQ	5
1:a=jQRmTT	4$D99	9	*QD1z!7N
 	
 1&<
==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&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 ).rm   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     r8   r   CaptureManager.__init__  s    $;?<@r:   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    r8   rM  CaptureManager.__repr__  s:    &t||&66I$J`J`Ic d  $ 5 58;	
r:   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    r8   is_capturingCaptureManager.is_capturing  s@    %%''  d33;;GGHIIr:   c                     U R                   S:g  $ )Nr$   )r  r   s    r8   r  $CaptureManager.is_globally_capturing   s    ||t##r:   c                    U R                   b   e[        U R                  5      U l         U R                   R                  5         g r   )r  r  r  r  r   s    r8   rq   %CaptureManager.start_global_capturing  s7    %%---!24<<!@..0r:   c                    U R                   b<  U R                   R                  5         U R                   R                  5         S U l         g g r   )r  r  r  r   s    r8   rp   $CaptureManager.stop_global_capturing  s?    !!-""557""113%)D" .r:   c                T    U R                   b  U R                   R                  5         g g r   )r  r  r   s    r8   resume_global_capture$CaptureManager.resume_global_capture  s'     !!-""335 .r:   c                R    U R                   b  U R                   R                  US9  g g )Nr  )r  r  r  s     r8   rr   %CaptureManager.suspend_global_capture  s*    !!-""444= .r:   c                F    U R                  5         U R                  U5        g r   )suspend_fixturerr   r  s     r8   r  CaptureManager.suspend  s    ##C(r:   c                D    U R                  5         U R                  5         g r   )r  resume_fixturer   s    r8   r  CaptureManager.resume  s    ""$r:   c                T    U R                   c   eU R                   R                  5       $ r   )r  r  r   s    r8   rt   "CaptureManager.read_global_capture!  s)    %%111%%0022r:   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       r8   set_fixtureCaptureManager.set_fixture'  sf      "33;;GGO / 7 7 C C##../0o5FFWX !0r:   c                    S U l         g r   )r  r   s    r8   unset_fixtureCaptureManager.unset_fixture0  s
     $r:   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    r8   activate_fixtureCaptureManager.activate_fixture3  s$       !!((* !r:   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    r8   deactivate_fixture!CaptureManager.deactivate_fixture9  s"      !!'') !r:   c                \    U R                   (       a  U R                   R                  5         g g r   )r  _suspendr   s    r8   r  CaptureManager.suspend_fixture>  s"      !!**, !r:   c                \    U R                   (       a  U R                   R                  5         g g r   )r  _resumer   s    r8   r  CaptureManager.resume_fixtureB  s"      !!))+ !r:   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  rr   r  r  )r   
do_fixture	do_globals      r8   global_and_fixture_disabled*CaptureManager.global_and_fixture_disabledH  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  rc   rd   )r  r  r  rr   rt   add_report_section)r   whenitemry   rz   s        r8   item_captureCaptureManager.item_captureY  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Trg   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  rr   rt   sectionsappend)r   	collectorrepry   rz   s        r8   pytest_make_collect_report)CaptureManager.pytest_make_collect_reporti  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     r8   pytest_runtest_setup#CaptureManager.pytest_runtest_setup|  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     r8   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     r8   pytest_runtest_teardown&CaptureManager.pytest_runtest_teardown  s#     z40 100r/  )tryfirstc                $    U R                  5         g r   rp   r   s    r8   pytest_keyboard_interrupt(CaptureManager.pytest_keyboard_interrupt      ""$r:   c                $    U R                  5         g r   r:  r   s    r8   pytest_internalerror#CaptureManager.pytest_internalerror  r=  r:   )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   rC  )r%  r   r   z-Generator[None, CollectReport, CollectReport])r  r   r   rC  )"r   r   r   r   r  r   rM  r  r  rq   rp   r  rr   r  r  rt   r  r  r  r  r  r  
contextlibcontextmanagerr  r   r   r'  r-  r2  r6  r;  r?  r   r   r:   r8   rm   rm     s7   $A

$1
*6>)
30%+*
-, & &  9 9 d"	6 $ d  d  d  t% % t% %r:   rm   c                      \ rS rSrSrS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.NFconfig	_ispytestc                   [        U5        Xl        X l        U(       a  UO0 U l        S U l        U R                  R
                  U l        U R                  R
                  U l        g r   )r   captureclassr  _config_capturer
  _captured_out_captured_err)r   rL  r  rI  rJ  s        r8   r   CaptureFixture.__init__  sQ     	y!7C!'vR59%)%6%6%C%C%)%6%6%C%Cr:   c           	         U R                   c_  [        S U R                  " S0 U R                  D6U R                  " S0 U R                  D6S9U l         U R                   R	                  5         g g )Nr  )r'  )r(  )rN  r  rL  rM  r  r   s    r8   r
  CaptureFixture._start  s\    == (%%84<<8%%84<<8DM
 MM))+ !r:   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   )rN  r  rO  rP  r  r  s      r8   r   CaptureFixture.close  s^    ==$}}779HC#%#%MM((* DM %r:   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.
)rO  rP  rN  r  rL  r
  r  )r   captured_outcaptured_errry   rz   s        r8   r  CaptureFixture.readouterr  sx     &*%7%79K9Kl==$}}//1HCLL!..;;!..;;\88r:   c                T    U R                   b  U R                   R                  5         gg)z1Suspend this fixture's own capturing temporarily.N)rN  r  r   s    r8   r  CaptureFixture._suspend  s!    ==$MM++- %r:   c                T    U R                   b  U R                   R                  5         gg)z0Resume this fixture's own capturing temporarily.N)rN  r  r   s    r8   r  CaptureFixture._resume  s!    ==$MM**, %r:   c                R    U R                   b  U R                   R                  5       $ g)z5Whether actively capturing -- not disabled or closed.F)rN  r  r   s    r8   r  CaptureFixture._is_started  s"    ==$==++--r:   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.rj   N)r  rI  rl   	getpluginr  )r   
capmanagers     r8   disabledCaptureFixture.disabled  sF      &*\\%8%8%F%F%P%P&

 335 655s   A A!A	A!
AA!)rN  rP  rO  rM  rL  r  )
rL  ztype[CaptureBase[AnyStr]]r  r   rI  zdict[str, Any] | NonerJ  r  r   r   r   r  r  rB  )r   r   r   r   r  r   r
  r   r  r  r  r  rD  rE  rc  r   r   r:   r8   rG  rG    s    = )-D/D D
 &D D 
D ,!9".
-
  r:   rG  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"
rj   TrJ  N)	rI  rl   ra  rG  r{  r  r
  r   r  r  rx   r  s      r8   capsysrh    sh     & %^^99CCDTUF$ZDIO
'

   A;A=c              #    #    U R                   R                  R                  S5      n[        [        U [        SS9SS9nUR                  U5        UR                  5         Uv   UR                  5         UR                  5         g7f)a  Enable simultaneous text capturing and pass-through of writes
to ``sys.stdout`` and ``sys.stderr`` as defined by ``--capture=``.


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

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

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

Example:

.. code-block:: python

    def test_output(capteesys):
        print("hello")
        captured = capteesys.readouterr()
        assert captured.out == "hello\n"
rj   Tr=  rH  N)
rI  rl   ra  rG  r{  dictr  r
  r   r  rg  s      r8   	capteesysrl    ss     0 %^^99CCDTUF$GDTNdO '

s   BB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"
rj   Trf  N)	rI  rl   ra  rG  rk  r  r
  r   r  rg  s      r8   capsysbinaryrn  &  si     & %^^99CCDTUF$%5w$OO
'

ri  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"
rj   Trf  N)	rI  rl   ra  rG  r  r  r
  r   r  rg  s      r8   capfdrp  B  sh     & %^^99CCDTUF$Y4HO
'

ri  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"

rj   Trf  N)	rI  rl   ra  rG  r  r  r
  r   r  rg  s      r8   capfdbinaryrr  ^  sh     ( %^^99CCDTUF$_gNO
'

ri  )r6   r   r   r   r   )r[   r   r   r   )rv   r   r   rC  )r)   rA  r   zMultiCapture[str])r  r   r   zGenerator[CaptureFixture[str]])r  r   r   z Generator[CaptureFixture[bytes]])Sr  
__future__r   r%  collectionscollections.abcr   r   r   rD  rN   r   rQ   r#   tempfiler	   typesr
   typingr   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   _pytest.configr   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.nodesr   r   r   _pytest.reportsr    rA  r9   rA   rE   rf   r{   rO   r}   r   r   r   ABCr	  rA  r   r*  r<  rw  rk  r{  r  r  r  version_infor  
namedtupler  r  rm   rG  rh  rl  rn  rp  rr  r   r:   r8   <module>r     s   1 " 
  % $ $  	 # 	 
 "              & ! # , - $ ' #   ) 56&"41n 
$ <<""" <"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MWV_ Mf 	 	6 	 	D 	 	6 	 	6 	 	r:   