
    [Fi7              	       0   d 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 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d"   Z/d#e#d$dfd%Z0d]d&Z1d'ed$dfd(Z2 e!d)*      d+e d$ed,   fd-       Z3 G d. d/ejh                        Z5 G d0 d1ejh                        Z6 G d2 d3e6      Z7 G d4 d5e      Z8 G d6 d7ejr                  ee         Z:d8d9d:d;Z; G d< d=e:e<         Z= G d> d?e:e         Z> G d@ dAe>e?         Z@ G dB dCe>e<         ZA G dD dEe:e         ZB G dF dGeBe?         ZC G dH dIeBe<         ZDej                  dJk\  sere G dK dLeee                ZFn" G dM dL ej                  dLdNdOg      ee         ZF G dP dQee         ZHdRe/d$eHe<   fdSZI G dT dU      ZJ G dV dWee         ZKe'dXe(d$eeKe<   ddf   fdY       ZLe'dXe(d$eeKe?   ddf   fdZ       ZMe'dXe(d$eeKe<   ddf   fd[       ZNe'dXe(d$eeKe?   ddf   fd\       ZOy)^z+Per-test stdout/stderr capturing mechanism.    NUnsupportedOperation)TemporaryFile)TracebackType)Any)AnyStr)BinaryIO)Final)final)	Generator)Generic)Iterable)Iterator)List)Literal)
NamedTuple)Optional)TextIO)Tuple)Type)TYPE_CHECKING)Union)Config)hookimpl)Parser)check_ispytest)fixture)
SubRequest)	Collector)File)Item)CollectReportfdsysnotee-sysparserreturnc                     | 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destr2   )getgroup
_addoption)r(   groups     a/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/capture.pypytest_addoptionr;   /   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)rA   s    r:   _colorama_workaroundrC   B   s7     ||w'	 (  		s   ' 	33streamc                     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 )NrH   r   w)hasattrrG   ioTextIOWrapperopenosdupfilenoencodingerrorsnewlinesline_buffering)fmode	bufferingrD   s      r:   _reopen_stdioz3_windowsconsoleio_workaround.<locals>._reopen_stdiou   sq    v}}e,aCII
#T95JJHHJJ
 	
r<   rbwb)r%   r?   r@   rL   rG   rH   
isinstancerM   _WindowsConsoleIOstdinstdoutstderr)rD   
raw_stdoutrZ   s   `  r:   _windowsconsoleio_workaroundrc   Q   s    0 <<""7+ws<O/P 68$&-fmmU&C""Jj""6"67
 cii.CIszz40CJszz40CJr<   Twrapperearly_configNNNc              #   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_namespacer4   rc   r%   r`   rC   pluginmanagerCaptureManagerregisteradd_cleanupstop_global_capturingstart_global_capturingsuspend_global_captureBaseExceptionread_global_capturewritera   )rf   nsrk   capmanouterrs         r:   pytest_load_initial_conftestsry      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                   <    e Zd ZdZedefd       Zedefd       Zy)EncodedFile r)   c                 ,    t        | j                        S N)reprrG   selfs    r:   namezEncodedFile.name   s     DKK  r<   c                 N    | j                   j                  j                  dd      S )Nb )rG   rX   replacer   s    r:   rX   zEncodedFile.mode   s!     {{''R00r<   N)__name__
__module____qualname__	__slots__propertystrr   rX   r|   r<   r:   r{   r{      s;    I!c ! !
 1c 1 1r<   r{   c                   ,     e Zd Zd fdZdefdZ xZS )	CaptureIOr)   c                 P    t         |   t        j                         ddd       y )NUTF-8r   T)rS   newlinewrite_through)super__init__rM   BytesIO)r   	__class__s    r:   r   zCaptureIO.__init__   s     SWXr<   c                     t        | j                  t        j                        sJ | j                  j	                         j                  d      S )Nr   )r]   rG   rM   r   getvaluedecoder   s    r:   r   zCaptureIO.getvalue   s8    $++rzz222{{##%,,W55r<   r)   N)r   r   r   r   r   r   __classcell__r   s   @r:   r   r      s    Y6# 6r<   r   c                   <     e Zd Zdeddf fdZdedef fdZ xZS )TeeCaptureIOotherr)   Nc                 0    || _         t        | 	          y r~   )_otherr   r   )r   r   r   s     r:   r   zTeeCaptureIO.__init__   s    r<   sc                 X    t         |   |       | j                  j                  |      S r~   )r   rt   r   )r   r   r   s     r:   rt   zTeeCaptureIO.write   s$    a{{  ##r<   )	r   r   r   r   r   r   intrt   r   r   s   @r:   r   r      s.    f  $s $s $ $r<   r   c                   n   e Zd Zedefd       Zd dedefdZeZdefdZ	d de
e   dee   fdZdee   fdZdefd	Zd!dZdefdZd!dZdefdZd"dededefdZdefdZdefdZd#de
e   defdZdedefdZdee   dd
fdZdefdZd$dZde
ee      de
e   de
e    dd
fdZ!ede"fd       Z#y
)%DontReadFromInputr)   c                 6    t         j                  j                  S r~   )r%   	__stdin__rS   r   s    r:   rS   zDontReadFromInput.encoding   s    }}%%%r<   sizec                     t        d      NzJpytest: reading from stdin while output is captured!  Consider using `-s`.OSErrorr   r   s     r:   readzDontReadFromInput.read       X
 	
r<   c                 "    | j                         S r~   )readliner   s    r:   __next__zDontReadFromInput.__next__   s    }}r<   hintc                     t        d      r   r   )r   r   s     r:   	readlineszDontReadFromInput.readlines   r   r<   c                     | S r~   r|   r   s    r:   __iter__zDontReadFromInput.__iter__       r<   c                     t        d      )Nz/redirected stdin is pseudofile, has no fileno()r   r   s    r:   rR   zDontReadFromInput.fileno   s    "#TUUr<   Nc                     t        d      )Nz.redirected stdin is pseudofile, has no flush()r   r   s    r:   flushzDontReadFromInput.flush   s    "#STTr<   c                      yNFr|   r   s    r:   isattyzDontReadFromInput.isatty       r<   c                      y r~   r|   r   s    r:   closezDontReadFromInput.close       r<   c                      yr   r|   r   s    r:   readablezDontReadFromInput.readable   r   r<   offsetwhencec                     t        d      )Nz0redirected stdin is pseudofile, has no seek(int)r   )r   r   r   s      r:   seekzDontReadFromInput.seek   s    "#UVVr<   c                      yr   r|   r   s    r:   seekablezDontReadFromInput.seekable   r   r<   c                     t        d      )Nz-redirected stdin is pseudofile, has no tell()r   r   s    r:   tellzDontReadFromInput.tell   s    "#RSSr<   c                     t        d      )Nzcannot truncate stdinr   r   s     r:   truncatezDontReadFromInput.truncate       "#:;;r<   datac                     t        d      )Nzcannot write to stdinr   r   r   s     r:   rt   zDontReadFromInput.write   r   r<   linesc                     t        d      )NzCannot write to stdinr   )r   r   s     r:   
writelineszDontReadFromInput.writelines   r   r<   c                      yr   r|   r   s    r:   writablezDontReadFromInput.writable  r   r<   c                     | S r~   r|   r   s    r:   	__enter__zDontReadFromInput.__enter__  r   r<   typevalue	tracebackc                      y r~   r|   )r   r   r   r   s       r:   __exit__zDontReadFromInput.__exit__  s     	r<   c                     | S r~   r|   r   s    r:   rG   zDontReadFromInput.buffer  s	     r<   )rK   r   )r   r~   )r)   r   )$r   r   r   r   r   rS   r   r   r   r   r   r   r   r   r   rR   r   boolr   r   r   r   r   r   r   rt   r   r   r   r   r   rr   r   r   r	   rG   r|   r<   r:   r   r      s   &# & &
 
c 

 H# 
hsm 
T#Y 

(3- V VU $ W3 W WC W$ Tc T<Xc] <c <<# <# << <$ <$ tM*+ & M*	
 
   r<   r   c                   6   e Zd ZU eed<   ej                  deddf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
eddfd       Zej                  defd       Zy)CaptureBaseEMPTY_BUFFERr$   r)   Nc                     t               r~   NotImplementedErrorr   r$   s     r:   r   zCaptureBase.__init__      !##r<   c                     t               r~   r   r   s    r:   startzCaptureBase.start  r   r<   c                     t               r~   r   r   s    r:   donezCaptureBase.done#  r   r<   c                     t               r~   r   r   s    r:   suspendzCaptureBase.suspend'  r   r<   c                     t               r~   r   r   s    r:   resumezCaptureBase.resume+  r   r<   r   c                     t               r~   r   r   s     r:   writeorgzCaptureBase.writeorg/  r   r<   c                     t               r~   r   r   s    r:   snapzCaptureBase.snap3  r   r<   r   )r   r   r   r   __annotations__abcabstractmethodr   r   r   r   r   r   r   r   r|   r<   r:   r   r     s    $3 $4 $ $ 	$ $ 	$ $ 	$ $ 	$ $ 	$V $ $ $ 	$f $ $r<   r   r_   r`   ra   )r         c                   \    e Zd ZdZdeddfdZddZddZddZdd	Z	de
fd
Zde
ddfdZy)	NoCapturer   r$   r)   Nc                      y r~   r|   r   s     r:   r   zNoCapture.__init__>  r   r<   c                      y r~   r|   r   s    r:   r   zNoCapture.startA  r   r<   c                      y r~   r|   r   s    r:   r   zNoCapture.doneD  r   r<   c                      y r~   r|   r   s    r:   r   zNoCapture.suspendG  r   r<   c                      y r~   r|   r   s    r:   r   zNoCapture.resumeJ  r   r<   c                      yNr   r|   r   s    r:   r   zNoCapture.snapM  s    r<   r   c                      y r~   r|   r   s     r:   r   zNoCapture.writeorgP  r   r<   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r|   r<   r:   r   r   ;  sM    L3 4 c S T r<   r   c            
           e Zd Z	 ddddedee   deddfdZd	edefd
Z	defdZ
dedeedf   ddfdZddZddZddZddZy)SysCaptureBaseNFteer$   tmpfiler  r)   c                    t         |   }t        t        |      | _        || _        |1|dk(  rt               }n!|s
t               nt        | j                        }|| _        d| _	        y )Nr_   initialized)
patchsysdictgetattrr%   _oldr   r   r   r   r	  _state)r   r$   r	  r  r   s        r:   r   zSysCaptureBase.__init__U  sY     B#C.		?w+--0)+l4996M#r<   
class_namec                     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   rL   r   r  r  r	  )r   r  s     r:   r   zSysCaptureBase.reprc  sI    9@@IID&!5d499oBKKLL
 	
r<   c                     dj                  | j                  j                  | j                  t	        | d      xr t        | j                        xs d| j                  | j                        S r  )	r  r   r   r   rL   r   r  r  r	  r   s    r:   __repr__zSysCaptureBase.__repr__l  sS    9@@NN##IID&!5d499oBKKLL
 	
r<   opstates.c                     | j                   |v s1J dj                  || j                   dj                  |                   y Nz+cannot {} in state {!r}: expected one of {}z, r  r  joinr   r  r  s      r:   _assert_statezSysCaptureBase._assert_stateu  =    KK6!	
8??TYYv.
	
!r<   c                     | j                  dd       t        t        | j                  | j                         d| _        y )Nr   r  started)r  setattrr%   r   r	  r  r   s    r:   r   zSysCaptureBase.start|  s.    7$45TYY-r<   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    r:   r   zSysCaptureBase.done  sR    6#RS;;& TYY		*Ir<   c                     | j                  dd       t        t        | j                  | j                         d| _        y Nr   r!  r%  r%  )r  r"  r%   r   r  r  r   s    r:   r   zSysCaptureBase.suspend  s.    9&>?TYY		*!r<   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    r:   r   zSysCaptureBase.resume  s=    8%=>;;)#TYY-r<   r~   r   )r   r   r   r   r   r   r   r   r   r   r  r   r  r   r   r   r   r|   r<   r:   r  r  T  s    37$HM$$ ( 0$AE$	$
s 
s 

# 

 
U38_ 
 
 
"
 r<   r  c                   ,    e Zd ZdZdefdZdeddfdZy)SysCaptureBinaryr<   r)   c                    | j                  dd       | j                  j                  d       | j                  j                  j	                         }| j                  j                  d       | j                  j                          |S Nr   r(  r   r  r	  r   rG   r   r   r   ress     r:   r   zSysCaptureBinary.snap  d    6#;<!ll!!&&(!
r<   r   Nc                     | j                  dd       | j                  j                          | j                  j                  j	                  |       | j                  j                  j                          y Nr   r(  )r  r  r   rG   rt   r   s     r:   r   zSysCaptureBinary.writeorg  sO    :'?@				t$		 r<   )r   r   r   r   bytesr   r   r|   r<   r:   r,  r,    s&    Le !U !t !r<   r,  c                   ,    e Zd ZdZdefdZdeddfdZy)
SysCapturer   r)   c                     | j                  dd       t        | j                  t              sJ | j                  j	                         }| j                  j                  d       | j                  j                          |S r.  )r  r]   r	  r   r   r   r   r0  s     r:   r   zSysCapture.snap  s`    6#;<$,,	222ll##%!
r<   r   Nc                     | j                  dd       | j                  j                  |       | j                  j                          y r4  )r  r  rt   r   r   s     r:   r   zSysCapture.writeorg  s1    :'?@				r<   )r   r   r   r   r   r   r   r|   r<   r:   r7  r7    s&    Lc S T r<   r7  c                   f    e Zd ZdeddfdZdefdZdedeedf   ddfd	Zdd
Z	ddZ
ddZddZy)FDCaptureBasetargetfdr)   Nc                    || _         	 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)rS   )rY   r   r   T)rS   rT   r   r   r  )r<  rP   fstattargetfd_invalidr   rO   devnullO_RDWRdup2rQ   targetfd_saver	  r7  
syscapturer{   r   r  r   r  )r   r<  s     r:   r   zFDCaptureBase.__init__  s    	)HHX  %)D!VVH-q=

W=DL0:80DDO $ '*  "DL <'",Xt||"D $ #,H"5#E  	5 46772::ryy3QD!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   r<  rD  r  r	  r   s    r:   r  zFDCaptureBase.__repr__  sR    ''($--@R@R?S Tkk_Idll-=Q@	
r<   r  r  .c                     | j                   |v s1J dj                  || j                   dj                  |                   y r  r  r  s      r:   r  zFDCaptureBase._assert_state  r  r<   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  rP   rC  r	  rR   r<  rE  r   r  r   s    r:   r   zFDCaptureBase.start  sI    7$45
##%t}}5r<   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  rP   rC  rD  r<  r   r@  rE  r   r	  r   s    r:   r   zFDCaptureBase.done  s     	6#RS;;& 
""DMM2
##$  ,$$5'HHT**+r<   c                     | j                  dd       | j                  dk(  ry | j                  j                          t	        j
                  | j                  | j                         d| _        y r'  )r  r  rE  r   rP   rC  rD  r<  r   s    r:   r   zFDCaptureBase.suspend  sQ    9&>?;;+%!
""DMM2!r<   c                     | j                  dd       | j                  dk(  ry | j                  j                          t	        j
                  | j                  j                         | j                         d| _        y r*  )	r  r  rE  r   rP   rC  r	  rR   r<  r   s    r:   r   zFDCaptureBase.resume  sX    8%=>;;)# 
##%t}}5r<   r   )r   r   r   r   r   r   r  r   r  r   r   r   r   r|   r<   r:   r;  r;    sX    '$ '$ '$R
# 

 
U38_ 
 
  " r<   r;  c                   0    e Zd ZdZdZdefdZdeddfdZy)FDCaptureBinaryzWCapture IO to/from a given OS-level file descriptor.

    snap() produces `bytes`.
    r<   r)   c                    | j                  dd       | j                  j                  d       | j                  j                  j	                         }| j                  j                  d       | j                  j                          |S r.  r/  r0  s     r:   r   zFDCaptureBinary.snap!  r2  r<   r   Nc                 h    | j                  dd       t        j                  | j                  |       y)"Write to original file descriptor.r   r(  N)r  rP   rt   rD  r   s     r:   r   zFDCaptureBinary.writeorg)  s'    :'?@
##T*r<   )r   r   r   __doc__r   r5  r   r   r|   r<   r:   rQ  rQ    s-    
 Le +U +t +r<   rQ  c                   0    e Zd ZdZdZdefdZdeddfdZy)	FDCapturezTCapture IO to/from a given OS-level file descriptor.

    snap() produces text.
    r   r)   c                     | j                  dd       | j                  j                  d       | j                  j                         }| j                  j                  d       | j                  j	                          |S r.  )r  r	  r   r   r   r0  s     r:   r   zFDCapture.snap7  s^    6#;<!ll!!
r<   r   Nc                     | j                  dd       t        j                  | j                  |j	                  d             y)rT  r   r(  r>  N)r  rP   rt   rD  encoder   s     r:   r   zFDCapture.writeorg?  s0    :'?@
##T[[%9:r<   )r   r   r   rU  r   r   r   r   r|   r<   r:   rW  rW  /  s-    
 Lc ;S ;T ;r<   rW  )      c                   &    e Zd ZU dZeed<   eed<   y)CaptureResultOThe result of :method:`caplog.readouterr() <pytest.CaptureFixture.readouterr>`.rw   rx   N)r   r   r   rU  r   r   r|   r<   r:   r^  r^  L  s    ]r<   r^  c                       e Zd ZdZdZy)r^  r_  r|   N)r   r   r   rU  r   r|   r<   r:   r^  r^  U  s     	^	r<   rw   rx   c                       e Zd ZdZdZdeee      deee      deee      ddfdZde	fdZ
dd	Zdeeef   fd
ZddeddfdZddZddZdefdZdee   fdZy)MultiCaptureNFin_rw   rx   r)   c                 .    || _         || _        || _        y r~   rc  rw   rx   )r   rc  rw   rx   s       r:   r   zMultiCapture.__init__b  s     362525r<   c                     d| j                   d| j                  d| j                  d| j                  d| j                  dS )Nz<MultiCapture out=z err=z in_=rI  z _in_suspended=rJ  )rw   rx   rc  r  _in_suspendedr   s    r:   r  zMultiCapture.__repr__l  sJ     E$((U488, Okk_OD4F4F3IL	
r<   c                     d| _         | j                  r| j                  j                          | j                  r| j                  j                          | j                  r| j                  j                          y y )Nr!  )r  rc  r   rw   rx   r   s    r:   start_capturingzMultiCapture.start_capturingr  sM    88HHNN88HHNN88HHNN r<   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.)
readouterrrw   r   rx   r   rw   rx   s      r:   pop_outerr_to_origzMultiCapture.pop_outerr_to_orig{  se    ??$S88'''HHc"88'''HHc"Cxr<   c                    d| _         | j                  r| j                  j                          | j                  r| j                  j                          |r/| j                  r"| j                  j                          d| _        y y y )Nr%  T)r  rw   r   rx   rc  rg  r   rc  s     r:   suspend_capturingzMultiCapture.suspend_capturing  s_    !88HH88HH488HH!%D 3r<   c                 "   d| _         | j                  r| j                  j                          | j                  r| j                  j                          | j                  r0| j
                  J | j
                  j                          d| _        y y )Nr!  F)r  rw   r   rx   rg  rc  r   s    r:   resume_capturingzMultiCapture.resume_capturing  sg    88HHOO88HHOO88'''HHOO!&D r<   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  
ValueErrorrw   r   rx   rc  r   s    r:   stop_capturingzMultiCapture.stop_capturing  sb    ;;)#23388HHMMO88HHMMO88HHMMO r<   c                      | j                   dk(  S )z7Whether actively capturing -- not suspended or stopped.r!  )r  r   s    r:   
is_startedzMultiCapture.is_started  s    {{i''r<   c                     | j                   r| j                   j                         nd}| j                  r| j                  j                         nd}t        ||      S r  )rw   r   rx   r^  rl  s      r:   rk  zMultiCapture.readouterr  s=    !%dhhmmor!%dhhmmorS#&&r<   r   F)r   r   r   r  rg  r   r   r   r   r   r  ri  r   rm  r   rp  rr  rv  rx  r^  rk  r|   r<   r:   rb  rb  ^  s    FM6k&)*6 k&)*6 k&)*	6
 
6
# 
	E&&.$9 	&T &d &	'
(D ('M&1 'r<   rb  r-   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   re  r%   r&   r'   Tr  zunknown capturing method: )rb  rW  r7  ru  )r-   s    r:   _get_multicapturer|    s    ~	!)A,IaLQQ	5
1:a=jQRmTT	4$D99	9	*QD1z!7N
 	
 1&<
==r<   c                   :   e Zd ZdZdeddfdZdefdZdeee	f   fdZ
de	fdZd&d	Zd&d
Zd&dZd'de	ddfdZd'de	ddfdZd&dZdee   fdZd(dZd&dZd&dZd&dZd&dZd&dZej6                  ded   fd       Zej6                  dededed   fd       Z e d      de!dede"e"f   fd       Z# e d      deded   fd        Z$ e d      deded   fd!       Z% e d      deded   fd"       Z& e d#      d&d$       Z' e d#      d&d%       Z(y))rl   a  The capture plugin.

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

    There are two levels of capture:

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

    * fixture: when a test function or one of its fixture depend on the
      ``capsys`` or ``capfd`` fixtures. In this case special handling is
      needed to ensure the fixtures take precedence over the global capture.
    r-   r)   Nc                 .    || _         d | _        d | _        y r~   _method_global_capturing_capture_fixture)r   r-   s     r:   r   zCaptureManager.__init__  s    $>B?Cr<   c                 V    d| j                   d| j                  d| j                  dS )Nz<CaptureManager _method=z _global_capturing=z _capture_fixture=rJ  r  r   s    r:   r  zCaptureManager.__repr__  s:    &t||&66I$J`J`Ic d  $ 5 58;	
r<   c                     | j                         ry| j                  r#d| j                  j                  j                  z  S y)Nglobalz
fixture %sF)is_globally_capturingr  requestfixturenamer   s    r:   is_capturingzCaptureManager.is_capturing  s:    %%'  $"7"7"?"?"K"KKKr<   c                      | j                   dk7  S )Nr&   )r  r   s    r:   r  z$CaptureManager.is_globally_capturing  s    ||t##r<   c                     | j                   J t        | j                        | _         | j                   j                          y r~   )r  r|  r  ri  r   s    r:   rp   z%CaptureManager.start_global_capturing  s7    %%---!24<<!@..0r<   c                     | j                   <| j                   j                          | j                   j                          d | _         y y r~   )r  rm  rv  r   s    r:   ro   z$CaptureManager.stop_global_capturing  s?    !!-""557""113%)D" .r<   c                 R    | j                   | j                   j                          y y r~   )r  rr  r   s    r:   resume_global_capturez$CaptureManager.resume_global_capture  s'     !!-""335 .r<   rc  c                 V    | j                   | j                   j                  |       y y )Nrc  )r  rp  ro  s     r:   rq   z%CaptureManager.suspend_global_capture  s*    !!-""444= .r<   c                 F    | j                          | j                  |       y r~   )suspend_fixturerq   ro  s     r:   r   zCaptureManager.suspend  s    ##C(r<   c                 D    | j                          | j                          y r~   )r  resume_fixturer   s    r:   r   zCaptureManager.resume  s    ""$r<   c                 R    | j                   J | j                   j                         S r~   )r  rk  r   s    r:   rs   z"CaptureManager.read_global_capture  s)    %%111%%0022r<   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       r:   set_fixturezCaptureManager.set_fixture  sh      "33;;GGO / 7 7 C C##../0o5FFWX !0r<   c                     d | _         y r~   )r  r   s    r:   unset_fixturezCaptureManager.unset_fixture  s
     $r<   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    r:   activate_fixturezCaptureManager.activate_fixture  s$       !!((* !r<   c                 R    | j                   r| j                   j                          yy)zDDeactivate the ``capsys`` or ``capfd`` fixture of this item, if any.N)r  r   r   s    r:   deactivate_fixturez!CaptureManager.deactivate_fixture#  s"      !!'') !r<   c                 R    | j                   r| j                   j                          y y r~   )r  _suspendr   s    r:   r  zCaptureManager.suspend_fixture(  s"      !!**, !r<   c                 R    | j                   r| j                   j                          y y r~   )r  _resumer   s    r:   r  zCaptureManager.resume_fixture,  s"      !!))+ !r<   rg   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  rx  rq   r  r  )r   
do_fixture	do_globals      r:   global_and_fixture_disabledz*CaptureManager.global_and_fixture_disabled2  s      **Rt/D/D/P/P/R
  "**Rt/E/E/P/P/R	'')	&**,##%  **,##% s   A5C8B" <&C"'C		Cwhenitemc              #     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`   ra   )r  r  r  rq   rs   add_report_section)r   r  r  rw   rx   s        r:   item_capturezCaptureManager.item_captureC  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$Trd   	collectorc              #   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)r]   r    r  rq   rs   sectionsappend)r   r  reprw   rx   s        r:   pytest_make_collect_reportz)CaptureManager.pytest_make_collect_reportS  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     r:   pytest_runtest_setupz#CaptureManager.pytest_runtest_setupf  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     r:   pytest_runtest_callz"CaptureManager.pytest_runtest_callk  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     r:   pytest_runtest_teardownz&CaptureManager.pytest_runtest_teardownp  s-     z40 		 	 	r  )tryfirstc                 $    | j                          y r~   ro   r   s    r:   pytest_keyboard_interruptz(CaptureManager.pytest_keyboard_interruptu      ""$r<   c                 $    | j                          y r~   r  r   s    r:   pytest_internalerrorz#CaptureManager.pytest_internalerrory  r  r<   r   rz  )r  zCaptureFixture[Any]r)   N))r   r   r   rU  _CaptureMethodr   r   r  r   r   r  r  rp   ro   r  rq   r   r   r^  rs   r  r  r  r  r  r  
contextlibcontextmanagerr   r  r!   r  r   r   r"   r  r  r  r  r  r  r|   r<   r:   rl   rl     s   $D~ D$ D

# 
eCI. $t $1
*6>$ >4 >)4 )D )
3]3%7 30%+*
-, &Y7G-H & &  9 9D 9Y?O5P 9 9 d"	45	6 $ d )<L2M   d ;K1L   dD Y?O5P   t% % t% %r<   rl   c            	           e Zd ZdZdddeee      dededdfd	Z	dd
Z
ddZdee   fdZddZddZdefdZej$                  ded   fd       Zy)CaptureFixturez|Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
    :fixture:`capfd` and :fixture:`capfdbinary` fixtures.F	_ispytestcaptureclassr  r  r)   Nc                    t        |       || _        || _        d | _        | j                  j                  | _        | j                  j                  | _        y r~   )r   r  r  _capturer   _captured_out_captured_err)r   r  r  r  s       r:   r   zCaptureFixture.__init__  sJ     	y!7C8<%)%6%6%C%C%)%6%6%C%Cr<   c                     | j                   Lt        d | j                  d      | j                  d            | _         | j                   j                          y y )Nr   r   re  )r  rb  r  ri  r   s    r:   r  zCaptureFixture._start  sN    == (%%a(%%a(DM
 MM))+ !r<   c                     | j                   i| j                   j                         \  }}| xj                  |z  c_        | xj                  |z  c_        | j                   j	                          d | _         y y r~   )r  rm  r  r  rv  rl  s      r:   r   zCaptureFixture.close  s`    ==$}}779HC#%#%MM((* DM %r<   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  rk  r  r   r^  )r   captured_outcaptured_errrw   rx   s        r:   rk  zCaptureFixture.readouterr  s     &*%7%79K9Kl==$}}//1HCCLCL!..;;!..;;\<88r<   c                 R    | j                   | j                   j                          yy)z1Suspend this fixture's own capturing temporarily.N)r  rp  r   s    r:   r  zCaptureFixture._suspend  s!    ==$MM++- %r<   c                 R    | j                   | j                   j                          yy)z0Resume this fixture's own capturing temporarily.N)r  rr  r   s    r:   r  zCaptureFixture._resume  s!    ==$MM**, %r<   c                 P    | j                   | j                   j                         S y)z5Whether actively capturing -- not disabled or closed.F)r  rx  r   s    r:   r  zCaptureFixture._is_started  s"    ==$==++--r<   rg   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.ri   N)r  configrk   	getpluginr  )r   
capmanagers     r:   disabledzCaptureFixture.disabled  sP      &*\\%8%8%F%F%P%P&

 335 		 	 	s   A AA	AAAr   )r   r   r   rU  r   r   r   r   r   r   r  r   r^  rk  r  r  r  r  r  r   r  r|   r<   r:   r  r  ~  s    =  D;v./D D
 D 
D,!9M&1 9".
-
T  )$45  r<   r  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"
    ri   Tr  N)	r  rk   r  r  r7  r  r  r   r  r  rv   r  s      r:   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"
    ri   Tr  N)	r  rk   r  r  r,  r  r  r   r  r  s      r:   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"
    ri   Tr  N)	r  rk   r  r  rW  r  r  r   r  r  s      r:   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"

    ri   Tr  N)	r  rk   r  r  rQ  r  r  r   r  r  s      r:   capfdbinaryr     si     & %^^99CCDTUF$_gNO
'

r  r   )PrU  r   collectionsr  rM   r   rP   r%   tempfiler   typesr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _pytest.configr   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.fixturesr   r   _pytest.nodesr   r    r!   _pytest.reportsr"   r  r;   rC   rc   ry   rN   r{   r   r   r   ABCr   r  r   r   r  r5  r,  r7  r;  rQ  rW  version_infor^  
namedtuplerb  r|  rl   r  r  r  r  r  r|   r<   r:   <module>r     s.   1 
   	 # 	 
 "                     ! # , - $ ' #   ) 56V  &41 41D 41n 
$ 9EU;V  :1""" 1 6   6$9 $I I^$#''76? $@ xH5C  2@ [( @ F!~e, !$$ "\ K' \ ~+mE* +,;c" ;6 w-

GFO  ?Q'76? Q'h>n >c1B >"x% x%vKWV_ Kb 	J 9^C-@$-L#M  	4 	* >%3H$PT3T)U  	4 	: )N3,?t,K"L  	4 	 	.2Gt2S(T  	r<   