
    9[gx              	      |   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddlZddl	Z	ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ erddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl%m'Z' ddl(m)Z) ddl(m*Z* ddl(m+Z+ ddl,m-Z- ed   Z.dSd Z/dTd!Z0dUd"Z1 e d#$      dVd%       Z2 G d& d'ejf                        Z4 G d( d)ejf                        Z5 G d* d+e5      Z6 G d, d-e      Z7 G d. d/ejp                  ee         Z9d0d1d2d3Z: G d4 d5e9e;         Z< G d6 d7e9e         Z= G d8 d9e=e>         Z? G d: d;e=e;         Z@ G d< d=e9e         ZA G d> d?eAe>         ZB G d@ dAeAe;         ZCe	j                  dBk\  sere G dC dDeee                ZEn" G dE dD ej                  dDdFdGg      ee         ZE G dH dIee         ZGdWdJZH G dK dL      ZI G dM dNee         ZJe&dXdO       ZKe&dYdP       ZLe&dXdQ       ZMe&dYdR       ZNy)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                    | j                  d      }|j                  ddddg dd       |j                  d	d
ddd       y )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     J/var/www/html/bid-api/venv/lib/python3.12/site-packages/_pytest/capture.pypytest_addoptionr7   0   sY    OOI&E	.B   
(      c                 l    t         j                  j                  d      r	 ddl} yy# t        $ r Y yw xY w)a  Ensure colorama is imported so that it attaches to the correct stdio
    handles on Windows.

    colorama uses the terminal on import time. So if something does the
    first import of colorama while I/O capture is active, colorama will
    fail in various ways.
    win32r   N)r"   platform
startswithcoloramaImportError)r=   s    r6   _colorama_workaroundr?   C   s7     ||w'	 (  		s   ' 	33c                    t         j                  j                  d      rt        t         d      ryt         d      syt         j                  d      r j                  j
                  n j                  }t        |t        j                        sy fd} |t         j                  d      t         _	         |t         j                  d      t         _
         |t         j                  d      t         _        y)	a  Workaround for Windows Unicode console handling.

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

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

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

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

    See https://github.com/pytest-dev/py/issues/103.
    r:   pypy_version_infoNbufferrawc                $   t        j                  d      s|d   dk(  rd}nd}t        j                  t	        t        j                  | j                               ||      | j                  | j                  | j                  | j                        S )NrC   r   w)hasattrrB   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingstreams      r6   _reopen_stdioz3_windowsconsoleio_workaround.<locals>._reopen_stdiov   sq    v}}e,aCII
#T9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 68$&-fmmU&C""Jj""6"67
 cii.CIszz40CJszz40CJr8   Twrapperc              #  X  K   | j                   }|j                  dk(  rt        t        j                         t                | j                  }t        |j                        }|j                  |d       | j                  |j                         |j                          	 	 d  |j                          y # |j                          w xY w# t        $ rS |j                         \  }}t        j                  j                  |       t        j                   j                  |        w xY ww)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nsre   capmanouterrs         r6   pytest_load_initial_conftestsrt      s     		*	*B	zzT$SZZ0 ..MBJJ'F6#34 V99: !!#		,))+F))+ --/S



	s1   BD*!B6 %C 5D*6CC AD''D*c                  4    e Zd ZdZedd       Zedd       Zy)EncodedFile c                ,    t        | j                        S N)reprrB   selfs    r6   namezEncodedFile.name   s     DKK  r8   c                N    | j                   j                  j                  dd      S )Nb )rB   rS   replacer{   s    r6   rS   zEncodedFile.mode   s!     {{''R00r8   Nreturnstr)__name__
__module____qualname__	__slots__propertyr}   rS   rw   r8   r6   rv   rv      s-    I! !
 1 1r8   rv   c                  (     e Zd Zd fdZddZ xZS )	CaptureIOc                P    t         |   t        j                         ddd       y )NUTF-8r   T)rN   newlinewrite_through)super__init__rH   BytesIO)r|   	__class__s    r6   r   zCaptureIO.__init__   s     SWXr8   c                    t        | j                  t        j                        sJ | j                  j	                         j                  d      S )Nr   )rY   rB   rH   r   getvaluedecoder{   s    r6   r   zCaptureIO.getvalue   s8    $++rzz222{{##%,,W55r8   r   Noner   )r   r   r   r   r   __classcell__r   s   @r6   r   r      s    Y6r8   r   c                  ,     e Zd Zd fdZd fdZ xZS )TeeCaptureIOc                0    || _         t        | 	          y ry   )_otherr   r   )r|   otherr   s     r6   r   zTeeCaptureIO.__init__   s    r8   c                X    t         |   |       | j                  j                  |      S ry   )r   rn   r   )r|   sr   s     r6   rn   zTeeCaptureIO.write   s$    a{{  ##r8   )r   r   r   r   )r   r   r   int)r   r   r   r   rn   r   r   s   @r6   r   r      s    $ $r8   r   c                      e Zd Zedd       ZdddZeZddZdddZddZ	ddZ
ddZddZdd	Zdd
ZdddZddZddZd d!dZd"dZd#dZddZd$dZ	 	 	 	 	 	 	 	 d%dZed&d       Zy)'DontReadFromInputc                Z    t         j                  J t         j                  j                  S ry   )r"   	__stdin__rN   r{   s    r6   rN   zDontReadFromInput.encoding   s"    }}(((}}%%%r8   c                    t        d      NzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorr|   sizes     r6   readzDontReadFromInput.read       X
 	
r8   c                "    | j                         S ry   )readliner{   s    r6   __next__zDontReadFromInput.__next__   s    }}r8   c                    t        d      r   r   )r|   hints     r6   	readlineszDontReadFromInput.readlines   r   r8   c                    | S ry   rw   r{   s    r6   __iter__zDontReadFromInput.__iter__       r8   c                    t        d      )Nz/redirected stdin is pseudofile, has no fileno()r   r{   s    r6   rM   zDontReadFromInput.fileno   s    "#TUUr8   c                    t        d      )Nz.redirected stdin is pseudofile, has no flush()r   r{   s    r6   flushzDontReadFromInput.flush   s    "#STTr8   c                     yNFrw   r{   s    r6   isattyzDontReadFromInput.isatty       r8   c                     y ry   rw   r{   s    r6   closezDontReadFromInput.close       r8   c                     yr   rw   r{   s    r6   readablezDontReadFromInput.readable   r   r8   c                    t        d      )Nz0redirected stdin is pseudofile, has no seek(int)r   )r|   offsetwhences      r6   seekzDontReadFromInput.seek   s    "#UVVr8   c                     yr   rw   r{   s    r6   seekablezDontReadFromInput.seekable   r   r8   c                    t        d      )Nz-redirected stdin is pseudofile, has no tell()r   r{   s    r6   tellzDontReadFromInput.tell   s    "#RSSr8   Nc                    t        d      )Nzcannot truncate stdinr   r   s     r6   truncatezDontReadFromInput.truncate       "#:;;r8   c                    t        d      )Nzcannot write to stdinr   r|   datas     r6   rn   zDontReadFromInput.write   r   r8   c                    t        d      )NzCannot write to stdinr   )r|   liness     r6   
writelineszDontReadFromInput.writelines   r   r8   c                     yr   rw   r{   s    r6   writablezDontReadFromInput.writable  r   r8   c                    | S ry   rw   r{   s    r6   	__enter__zDontReadFromInput.__enter__  r   r8   c                     y ry   rw   )r|   typevalue	tracebacks       r6   __exit__zDontReadFromInput.__exit__	  s     	r8   c                    | S ry   rw   r{   s    r6   rB   zDontReadFromInput.buffer  s	     r8   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   ry   )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   rN   r   r   r   r   r   rM   r   r   r   r   r   r   r   r   rn   r   r   r   r   rB   rw   r8   r6   r   r      s    & &

 H

VUWT<<<( $ (	
 
  r8   r   c                  "   e Zd ZU ded<   ej
                  dd       Zej
                  dd       Zej
                  dd       Zej
                  dd       Z	ej
                  dd       Z
ej
                  dd       Zej
                  dd	       Zy
)CaptureBaser	   EMPTY_BUFFERc                    t               ry   NotImplementedErrorr|   r!   s     r6   r   zCaptureBase.__init__      !##r8   c                    t               ry   r   r{   s    r6   startzCaptureBase.start!  r   r8   c                    t               ry   r   r{   s    r6   donezCaptureBase.done%  r   r8   c                    t               ry   r   r{   s    r6   suspendzCaptureBase.suspend)  r   r8   c                    t               ry   r   r{   s    r6   resumezCaptureBase.resume-  r   r8   c                    t               ry   r   r   s     r6   writeorgzCaptureBase.writeorg1  r   r8   c                    t               ry   r   r{   s    r6   snapzCaptureBase.snap5  r   r8   Nr!   r   r   r   r   )r   r	   r   r   )r   r	   )r   r   r   __annotations__abcabstractmethodr   r   r   r   r   r   r   rw   r8   r6   r   r     s    $ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$ $r8   r   r[   r\   r]   )r         c                  H    e Zd ZdZd
dZddZddZddZddZddZ	ddZ
y	)	NoCapturer   c                     y ry   rw   r   s     r6   r   zNoCapture.__init__@  r   r8   c                     y ry   rw   r{   s    r6   r   zNoCapture.startC  r   r8   c                     y ry   rw   r{   s    r6   r   zNoCapture.doneF  r   r8   c                     y ry   rw   r{   s    r6   r   zNoCapture.suspendI  r   r8   c                     y ry   rw   r{   s    r6   r   zNoCapture.resumeL  r   r8   c                     yNr   rw   r{   s    r6   r   zNoCapture.snapO  s    r8   c                     y ry   rw   r   s     r6   r   zNoCapture.writeorgR  r   r8   Nr   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   rw   r8   r6   r   r   =  s*    Lr8   r   c                  d    e Zd Z	 ddd	 	 	 	 	 	 	 ddZddZddZddZddZdd	Zdd
Z	ddZ
y)SysCaptureBaseNFteec                   t         |   }t        t        |      | _        || _        |1|dk(  rt               }n!|s
t               nt        | j                        }|| _        d| _	        y )Nr[   initialized)
patchsysdictgetattrr"   _oldr}   r   r   r   tmpfile_state)r|   r!   r  r
  r}   s        r6   r   zSysCaptureBase.__init__W  sY     B#C.		?w+--0)+l4996M#r8   c                    dj                  || j                  t        | d      xr t        | j                        xs d| j
                  | j                        S Nz(<{} {} _old={} _state={!r} tmpfile={!r}>r  z<UNSET>)formatr}   rG   rz   r  r  r  )r|   
class_names     r6   rz   zSysCaptureBase.repre  sI    9@@IID&!5d499oBKKLL
 	
r8   c                    dj                  | j                  j                  | j                  t	        | d      xr t        | j                        xs d| j                  | j                        S r  )	r  r   r   r}   rG   rz   r  r  r  r{   s    r6   __repr__zSysCaptureBase.__repr__n  sS    9@@NN##IID&!5d499oBKKLL
 	
r8   c                    | j                   |v s1J dj                  || j                   dj                  |                   y Nz+cannot {} in state {!r}: expected one of {}z, r  r  joinr|   opstatess      r6   _assert_statezSysCaptureBase._assert_statew  =    KK6!	
8??TYYv.
	
!r8   c                    | j                  dd       t        t        | j                  | j                         d| _        y )Nr   r  started)r  setattrr"   r}   r  r  r{   s    r6   r   zSysCaptureBase.start~  s.    7$45TYY-r8   c                    | j                  dd       | j                  dk(  ry t        t        | j                  | j
                         | `| j                  j                          d| _        y )Nr   r  r#  	suspendedr   )r  r  r$  r"   r}   r  r  r   r{   s    r6   r   zSysCaptureBase.done  sR    6#RS;;& TYY		*Ir8   c                    | j                  dd       t        t        | j                  | j                         d| _        y Nr   r#  r'  r'  )r  r$  r"   r}   r  r  r{   s    r6   r   zSysCaptureBase.suspend  s.    9&>?TYY		*!r8   c                    | j                  dd       | j                  dk(  ry t        t        | j                  | j
                         d| _        y Nr   r*  r#  )r  r  r$  r"   r}   r  r{   s    r6   r   zSysCaptureBase.resume  s=    8%=>;;)#TYY-r8   ry   )r!   r   r  zTextIO | Noner
  r   r   r   )r  r   r   r   r   r  r   r  ztuple[str, ...]r   r   r   )r   r   r   r   rz   r  r  r   r   r   r   rw   r8   r6   r  r  V  sU    04$EJ$$ -$>B$	$


 
"
 r8   r  c                       e Zd ZdZddZddZy)SysCaptureBinaryr8   c                   | j                  dd       | j                  j                  d       | j                  j                  j	                         }| j                  j                  d       | j                  j                          |S Nr   r*  r   r  r  r   rB   r   r   r|   ress     r6   r   zSysCaptureBinary.snap  d    6#;<!ll!!&&(!
r8   c                    | j                  dd       | j                  j                          | j                  j                  j	                  |       | j                  j                  j                          y Nr   r*  )r  r  r   rB   rn   r   s     r6   r   zSysCaptureBinary.writeorg  sO    :'?@				t$		 r8   Nr   bytesr   r9  r   r   r   r   r   r   r   r   rw   r8   r6   r/  r/    s    L!r8   r/  c                       e Zd ZdZddZddZy)
SysCapturer   c                    | j                  dd       t        | j                  t              sJ | j                  j	                         }| j                  j                  d       | j                  j                          |S r1  )r  rY   r  r   r   r   r   r3  s     r6   r   zSysCapture.snap  s`    6#;<$,,	222ll##%!
r8   c                    | j                  dd       | j                  j                  |       | j                  j                          y r7  )r  r  rn   r   r   s     r6   r   zSysCapture.writeorg  s1    :'?@				r8   Nr   r  r;  rw   r8   r6   r=  r=    s    Lr8   r=  c                  D    e Zd Zd	dZd
dZddZddZddZddZddZ	y)FDCaptureBasec                   || _         	 t        j                  |       d | _        t        j                  |      | _
        |dk(  r8t        t        j                  d      | _        t        |      | _        d	| _        y t        t        d      dddd      | _        |t         v r#t        || j                        | _        d	| _        y t#        |      | _        d	| _        y # t        $ r[ t        j
                  t        j                  t        j                        | _        t        j                  | j                  |       Y w xY w)
Nr   utf-8)rN   )rT   r   r   T)rN   rO   r   r   r  )targetfdrK   fstattargetfd_invalidr   rJ   devnullO_RDWRdup2rL   targetfd_saver  r=  
syscapturerv   r   r  r   r  )r|   rD  s     r6   r   zFDCaptureBase.__init__  s    	)HHX  %)D!VVH-q=

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

BII0ND!GGD))84	5s   C A EEc                    d| j                   j                   d| j                   d| j                   d| j                  d| j
                  dS )N< z oldfd= _state=z	 tmpfile=>)r   r   rD  rJ  r  r  r{   s    r6   r  zFDCaptureBase.__repr__  sR    ''($--@R@R?S Tkk_Idll-=Q@	
r8   c                    | j                   |v s1J dj                  || j                   dj                  |                   y r  r  r  s      r6   r  zFDCaptureBase._assert_state  r   r8   c                    | j                  dd       t        j                  | j                  j	                         | j
                         | j                  j                          d| _        y)z4Start capturing on targetfd using memorized tmpfile.r   r"  r#  N)	r  rK   rI  r  rM   rD  rK  r   r  r{   s    r6   r   zFDCaptureBase.start  sI    7$45
##%t}}5r8   c                   | j                  dd       | j                  dk(  ryt        j                  | j                  | j
                         t        j                  | j                         | j                  W| j                  | j
                  k7  rt        j                  | j
                         t        j                  | j                         | j                  j                          | j                  j                          d| _        y)z_Stop capturing, restore streams, return original capture file,
        seeked to position zero.r   r&  N)r  r  rK   rI  rJ  rD  r   rF  rK  r   r  r{   s    r6   r   zFDCaptureBase.done  s     	6#RS;;& 
""DMM2
##$  ,$$5'HHT**+r8   c                    | j                  dd       | j                  dk(  ry | j                  j                          t	        j
                  | j                  | j                         d| _        y r)  )r  r  rK  r   rK   rI  rJ  rD  r{   s    r6   r   zFDCaptureBase.suspend
  sQ    9&>?;;+%!
""DMM2!r8   c                    | j                  dd       | j                  dk(  ry | j                  j                          t	        j
                  | j                  j                         | j                         d| _        y r,  )	r  r  rK  r   rK   rI  r  rM   rD  r{   s    r6   r   zFDCaptureBase.resume  sX    8%=>;;)# 
##%t}}5r8   N)rD  r   r   r   r   r-  r   )
r   r   r   r   r  r  r   r   r   r   rw   r8   r6   rA  rA    s&    '$R

  " r8   rA  c                  $    e Zd ZdZdZddZddZy)FDCaptureBinaryzWCapture IO to/from a given OS-level file descriptor.

    snap() produces `bytes`.
    r8   c                   | j                  dd       | j                  j                  d       | j                  j                  j	                         }| j                  j                  d       | j                  j                          |S r1  r2  r3  s     r6   r   zFDCaptureBinary.snap#  r5  r8   c                h    | j                  dd       t        j                  | j                  |       y)"Write to original file descriptor.r   r*  N)r  rK   rn   rJ  r   s     r6   r   zFDCaptureBinary.writeorg+  s'    :'?@
##T*r8   Nr8  r:  r   r   r   __doc__r   r   r   rw   r8   r6   rW  rW    s    
 L+r8   rW  c                  $    e Zd ZdZdZddZddZy)	FDCapturezTCapture IO to/from a given OS-level file descriptor.

    snap() produces text.
    r   c                    | j                  dd       | j                  j                  d       | j                  j                         }| j                  j                  d       | j                  j	                          |S r1  )r  r  r   r   r   r3  s     r6   r   zFDCapture.snap9  s^    6#;<!ll!!
r8   c                    | j                  dd       t        j                  | j                  |j	                  d             y)rZ  r   r*  rC  N)r  rK   rn   rJ  encoder   s     r6   r   zFDCapture.writeorgA  s0    :'?@
##T[[%9:r8   Nr   r  r[  rw   r8   r6   r^  r^  1  s    
 L;r8   r^  )      c                  &    e Zd ZU dZded<   ded<   y)CaptureResultOThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.r	   rr   rs   N)r   r   r   r\  r   rw   r8   r6   re  re  N  s    ]r8   re  c                      e Zd ZdZdZy)re  rf  rw   N)r   r   r   r\  r   rw   r8   r6   re  re  W  s     	^	r8   rr   rs   c                  n    e Zd ZdZdZ	 	 	 	 	 	 	 	 ddZddZddZddZdddZ	ddZ
dd	Zdd
ZddZy)MultiCaptureNFc                .    || _         || _        || _        y ry   in_rr   rs   )r|   rl  rr   rs   s       r6   r   zMultiCapture.__init__d  s     03/2/2r8   c                    d| j                   d| j                  d| j                  d| j                  d| j                  dS )Nz<MultiCapture out=z err=z in_=rO  z _in_suspended=rP  )rr   rs   rl  r  _in_suspendedr{   s    r6   r  zMultiCapture.__repr__n  sJ     E$((U488, Okk_OD4F4F3IL	
r8   c                    d| _         | j                  r| j                  j                          | j                  r| j                  j                          | j                  r| j                  j                          y y )Nr#  )r  rl  r   rr   rs   r{   s    r6   start_capturingzMultiCapture.start_capturingt  sM    88HHNN88HHNN88HHNN r8   c                    | j                         \  }}|r)| j                  J | j                  j                  |       |r)| j                  J | j                  j                  |       ||fS )z?Pop current snapshot out/err capture and flush to orig streams.)
readouterrrr   r   rs   r|   rr   rs   s      r6   pop_outerr_to_origzMultiCapture.pop_outerr_to_orig}  se    ??$S88'''HHc"88'''HHc"Cxr8   c                   d| _         | j                  r| j                  j                          | j                  r| j                  j                          |r/| j                  r"| j                  j                          d| _        y y y )Nr'  T)r  rr   r   rs   rl  rn  r|   rl  s     r6   suspend_capturingzMultiCapture.suspend_capturing  s_    !88HH88HH488HH!%D 3r8   c                "   d| _         | j                  r| j                  j                          | j                  r| j                  j                          | j                  r0| j
                  J | j
                  j                          d| _        y y )Nr#  F)r  rr   r   rs   rn  rl  r{   s    r6   resume_capturingzMultiCapture.resume_capturing  sg    88HHOO88HHOO88'''HHOO!&D r8   c                ,   | j                   dk(  rt        d      d| _         | j                  r| j                  j                          | j                  r| j                  j                          | j
                  r| j
                  j                          yy)z+Stop capturing and reset capturing streams.stoppedzwas already stoppedN)r  
ValueErrorrr   r   rs   rl  r{   s    r6   stop_capturingzMultiCapture.stop_capturing  sb    ;;)#23388HHMMO88HHMMO88HHMMO r8   c                     | j                   dk(  S )z7Whether actively capturing -- not suspended or stopped.r#  )r  r{   s    r6   
is_startedzMultiCapture.is_started  s    {{i''r8   c                    | j                   r| j                   j                         nd}| j                  r| j                  j                         nd}t        ||      S r  )rr   r   rs   re  rs  s      r6   rr  zMultiCapture.readouterr  s=    !%dhhmmor!%dhhmmorS#&&r8   )rl  CaptureBase[AnyStr] | Nonerr   r  rs   r  r   r   r   r   )r   ztuple[AnyStr, AnyStr]Frl  r   r   r   r   r   zCaptureResult[AnyStr])r   r   r   r  rn  r   r  rp  rt  rw  ry  r}  r  rr  rw   r8   r6   ri  ri  `  s_    FM3'3 (3 (	3
 
3
	&	'
('r8   ri  c                N   | dk(  r)t        t        d      t        d      t        d            S | dk(  r)t        t        d      t        d      t        d            S | dk(  rt        d d d       S | dk(  r$t        d t        dd	
      t        dd	
            S t        d|       )Nr!   r   r   r   rk  r"   r#   r$   Tr	  zunknown capturing method: )ri  r^  r=  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                     e Zd ZdZddZd dZd!dZd"dZd#dZd#dZ	d#dZ
d$d%d	Zd$d%d
Zd#dZd&dZd'dZd#dZd#dZd#dZd#dZd#dZej,                  d(d       Zej,                  d)d       Z ed      	 	 	 	 d*d       Z ed      d+d       Z ed      d+d       Z ed      d+d       Z ed      d#d       Z ed      d#d       Zy),rf   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                .    || _         d | _        d | _        y ry   _method_global_capturing_capture_fixture)r|   r(   s     r6   r   zCaptureManager.__init__  s    $;?<@r8   c                V    d| j                   d| j                  d| j                  dS )Nz<CaptureManager _method=z _global_capturing=z _capture_fixture=rP  r  r{   s    r6   r  zCaptureManager.__repr__  s:    &t||&66I$J`J`Ic d  $ 5 58;	
r8   c                    | j                         ry| j                  r#d| j                  j                  j                   S y)Nglobalzfixture F)is_globally_capturingr  requestfixturenamer{   s    r6   is_capturingzCaptureManager.is_capturing  s=    %%'  d33;;GGHIIr8   c                     | j                   dk7  S )Nr#   )r  r{   s    r6   r  z$CaptureManager.is_globally_capturing  s    ||t##r8   c                    | j                   J t        | j                        | _         | j                   j                          y ry   )r  r  r  rp  r{   s    r6   rj   z%CaptureManager.start_global_capturing  s7    %%---!24<<!@..0r8   c                    | j                   <| j                   j                          | j                   j                          d | _         y y ry   )r  rt  r}  r{   s    r6   ri   z$CaptureManager.stop_global_capturing  s?    !!-""557""113%)D" .r8   c                R    | j                   | j                   j                          y y ry   )r  ry  r{   s    r6   resume_global_capturez$CaptureManager.resume_global_capture  s'     !!-""335 .r8   c                V    | j                   | j                   j                  |       y y )Nrl  )r  rw  rv  s     r6   rk   z%CaptureManager.suspend_global_capture   s*    !!-""444= .r8   c                F    | j                          | j                  |       y ry   )suspend_fixturerk   rv  s     r6   r   zCaptureManager.suspend  s    ##C(r8   c                D    | j                          | j                          y ry   )r  resume_fixturer{   s    r6   r   zCaptureManager.resume	  s    ""$r8   c                R    | j                   J | j                   j                         S ry   )r  rr  r{   s    r6   rm   z"CaptureManager.read_global_capture  s)    %%111%%0022r8   c                    | j                   rX| j                   j                  j                  }|j                  j                  }|j                  j                  d| d| d       || _         y )Nzcannot use z and z at the same time)r  r  r  
raiseerror)r|   capture_fixturecurrent_fixturerequested_fixtures       r6   set_fixturezCaptureManager.set_fixture  sh      "33;;GGO / 7 7 C C##../0o5FFWX !0r8   c                    d | _         y ry   )r  r{   s    r6   unset_fixturezCaptureManager.unset_fixture  s
     $r8   c                R    | j                   r| j                   j                          yy)z|If the current item is using ``capsys`` or ``capfd``, activate
        them so they take precedence over the global capture.N)r  _startr{   s    r6   activate_fixturezCaptureManager.activate_fixture  s$       !!((* !r8   c                R    | j                   r| j                   j                          yy)zDDeactivate the ``capsys`` or ``capfd`` fixture of this item, if any.N)r  r   r{   s    r6   deactivate_fixturez!CaptureManager.deactivate_fixture%  s"      !!'') !r8   c                R    | j                   r| j                   j                          y y ry   )r  _suspendr{   s    r6   r  zCaptureManager.suspend_fixture*  s"      !!**, !r8   c                R    | j                   r| j                   j                          y y ry   )r  _resumer{   s    r6   r  zCaptureManager.resume_fixture.  s"      !!))+ !r8   c              #    K   | j                   xr | j                   j                         }|r| j                          | j                  xr | j                  j	                         }|r| j                          	 d |r| j                          |r| j                          yy# |r| j                          |r| j                          w w xY ww)zLContext manager to temporarily disable global and current fixture capturing.N)r  _is_startedr  r  r  rk   r  r  )r|   
do_fixture	do_globals      r6   global_and_fixture_disabledz*CaptureManager.global_and_fixture_disabled4  s      **Rt/D/D/P/P/R
  "**Rt/E/E/P/P/R	'')	&**,##%  **,##% s   A5C8B" <&C"'C		Cc              #    K   | j                          | j                          	 d  | j                          | j                  d       | j	                         \  }}|j                  |d|       |j                  |d|       y # | j                          | j                  d       | j	                         \  }}|j                  |d|       |j                  |d|       w xY ww)NFr  r\   r]   )r  r  r  rk   rm   add_report_section)r|   whenitemrr   rs   s        r6   item_capturez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$Tr`   c              #  P  K   t        |t              rx| j                          	 d }| j                          | j	                         \  }}|r|j
                  j                  d|f       |r|j
                  j                  d|f       |S d }|S # | j                          w xY ww)NzCaptured stdoutzCaptured stderr)rY   r   r  rk   rm   sectionsappend)r|   	collectorreprr   rs   s        r6   pytest_make_collect_reportz)CaptureManager.pytest_make_collect_reportU  s      i&&&(.++-//1HC##%6$<=##%6$<= 
 C
 ++-s   !B&B A)B&B##B&c              #  b   K   | j                  d|      5  d cd d d        S # 1 sw Y   y xY ww)Nsetupr  r|   r  s     r6   pytest_runtest_setupz#CaptureManager.pytest_runtest_setuph  s$     w- .--   /#
/,/c              #  b   K   | j                  d|      5  d cd d d        S # 1 sw Y   y xY ww)Ncallr  r  s     r6   pytest_runtest_callz"CaptureManager.pytest_runtest_callm  s$     vt, -,,r  c              #  b   K   | j                  d|      5  d cd d d        S # 1 sw Y   y xY ww)Nteardownr  r  s     r6   pytest_runtest_teardownz&CaptureManager.pytest_runtest_teardownr  s$     z40 100r  )tryfirstc                $    | j                          y ry   ri   r{   s    r6   pytest_keyboard_interruptz(CaptureManager.pytest_keyboard_interruptw      ""$r8   c                $    | j                          y ry   r  r{   s    r6   pytest_internalerrorz#CaptureManager.pytest_internalerror{  r  r8   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  r  r  rj   ri   r  rk   r   r   rm   r  r  r  r  r  r  
contextlibcontextmanagerr  r  r   r  r  r  r  r  r  rw   r8   r6   rf   rf     s7   $A

$1
*6>)
30%+*
-, & &  9 9 d"	6 $ d  d  d  t% % t% %r8   rf   c                      e Zd ZdZdd	 	 	 	 	 	 	 ddZddZddZddZddZdd	Z	dd
Z
ej                  dd       Zy)CaptureFixturez|Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
    :fixture:`capfd` and :fixture:`capfdbinary` fixtures.F	_ispytestc                   t        |       || _        || _        d | _        | j                  j                  | _        | j                  j                  | _        y ry   )r   captureclassr  _capturer   _captured_out_captured_err)r|   r  r  r  s       r6   r   zCaptureFixture.__init__  sJ     	y!7C59%)%6%6%C%C%)%6%6%C%Cr8   c                    | j                   Lt        d | j                  d      | j                  d            | _         | j                   j                          y y )Nr   r   rk  )r  ri  r  rp  r{   s    r6   r  zCaptureFixture._start  sN    == (%%a(%%a(DM
 MM))+ !r8   c                    | j                   i| j                   j                         \  }}| xj                  |z  c_        | xj                  |z  c_        | j                   j	                          d | _         y y ry   )r  rt  r  r  r}  rs  s      r6   r   zCaptureFixture.close  s`    ==$}}779HC#%#%MM((* DM %r8   c                   | j                   | j                  }}| j                  '| j                  j                         \  }}||z  }||z  }| j                  j
                  | _         | j                  j
                  | _        t        ||      S )zRead and return the captured output so far, resetting the internal
        buffer.

        :returns:
            The captured content as a namedtuple with ``out`` and ``err``
            string attributes.
        )r  r  r  rr  r  r   re  )r|   captured_outcaptured_errrr   rs   s        r6   rr  zCaptureFixture.readouterr  s     &*%7%79K9Kl==$}}//1HCCLCL!..;;!..;;\<88r8   c                R    | j                   | j                   j                          yy)z1Suspend this fixture's own capturing temporarily.N)r  rw  r{   s    r6   r  zCaptureFixture._suspend  s!    ==$MM++- %r8   c                R    | j                   | j                   j                          yy)z0Resume this fixture's own capturing temporarily.N)r  ry  r{   s    r6   r  zCaptureFixture._resume  s!    ==$MM**, %r8   c                P    | j                   | j                   j                         S y)z5Whether actively capturing -- not disabled or closed.F)r  r  r{   s    r6   r  zCaptureFixture._is_started  s"    ==$==++--r8   c              #     K   | j                   j                  j                  j                  d      }|j	                         5  d ddd       y# 1 sw Y   yxY ww)z>Temporarily disable capturing while inside the ``with`` block.rc   N)r  configre   	getpluginr  )r|   
capmanagers     r6   disabledzCaptureFixture.disabled  sG      &*\\%8%8%F%F%P%P&

 335 655s   A AA	AAAN)r  ztype[CaptureBase[AnyStr]]r  r   r  r   r   r   r   r  r   r  )r   r   r   r\  r   r  r   rr  r  r  r  r  r  r  rw   r8   r6   r  r    st    =  D/D D
 D 
D,!9".
-
  r8   r  c              #    K   | j                   j                  j                  d      }t        t        | d      }|j                  |       |j                          | |j                          |j                          yw)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"
    rc   Tr  N)	r  re   r  r  r=  r  r  r   r  r  rq   r  s      r6   capsysr    si     & %^^99CCDTUF$ZDIO
'

   A>B c              #    K   | j                   j                  j                  d      }t        t        | d      }|j                  |       |j                          | |j                          |j                          yw)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"
    rc   Tr  N)	r  re   r  r  r/  r  r  r   r  r  s      r6   capsysbinaryr    sj     & %^^99CCDTUF$%5w$OO
'

r  c              #    K   | j                   j                  j                  d      }t        t        | d      }|j                  |       |j                          | |j                          |j                          yw)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"
    rc   Tr  N)	r  re   r  r  r^  r  r  r   r  r  s      r6   capfdr  	  si     & %^^99CCDTUF$Y4HO
'

r  c              #    K   | j                   j                  j                  d      }t        t        | d      }|j                  |       |j                          | |j                          |j                          yw)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"

    rc   Tr  N)	r  re   r  r  rW  r  r  r   r  r  s      r6   capfdbinaryr  %  si     ( %^^99CCDTUF$_gNO
'

r  )r4   r   r   r   r   )rU   r   r   r   )ro   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_   rt   rI   rv   r   r   r   ABCr   r  r   r   r  r9  r/  r=  rA  rW  r^  version_infore  
namedtupleri  r  rf   r  r  r  r  r  rw   r8   r6   <module>r     sj   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   