
    Dg-                        d dl Z d dlZd dlZd dlZ	 d dlmZ n# e$ r	 d dlmZ Y nw xY wej        dk     r G d de          ZneZ	 d dlm	Z	 n# e$ r  G d de          Z	Y nw xY wd	d
ddZ
 G d d          ZddZ G d de          Z G d de          Z G d de          Z G d de          Z G d d          Z	 e j        ZdS # e$ r e j        dk    rdZY dS dZY dS w xY w)    N)StringIO   r   c                       e Zd Zd ZdS )TextIOc                     t          |t                    s t          |t          | dd          d          }t          j        | |          S )N	_encodingUTF-8replace)
isinstanceunicodegetattrr   writeselfdatas     C/var/www/sysmax/venv/lib/python3.11/site-packages/py/_io/capture.pyr   zTextIO.write   sD    dG,, UtWT;%H%H)TT>$---    N__name__
__module____qualname__r    r   r   r   r      #        	. 	. 	. 	. 	.r   r   )BytesIOc                       e Zd Zd ZdS )r   c                 z    t          |t                    rt          d|          t          j        | |          S )Nznot a byte value: )r   r   	TypeErrorr   r   r   s     r   r   zBytesIO.write   s<    $(( Ai ?@@@>$---r   Nr   r   r   r   r   r      r   r   r   stdinstdoutstderr)r         c                   ,    e Zd ZdZd	dZd Zd Zd ZdS )
	FDCapturez5 Capture IO to/from a given os-level filedescriptor. NTFc                 ^   || _         |?|dk    r9t          j        d          }t          |d          }|                                 || _        t          j        | j                   | _        |r%t          t          t          |                   | _        |r|                                  dS dS )z save targetfd descriptor, and open a new
            temporary file there.  If no tmpfile is
            specified a tempfile.Tempfile() will be opened
            in text mode.
        Nr   zwb+r
   )encoding)targetfdtempfileTemporaryFiledupfileclosetmpfileosdup_savefdr   syspatchsysdict_oldsysstart)r   r(   r-   nowpatchsysfs         r   __init__zFDCapture.__init__"   s     !?x1}}&u--Aa'222GGGIIIvdm,, 	@"3X(>??DL 	JJLLLLL	 	r   c                    	 t          j        | j                   n# t          $ r t	          d          w xY w| j        dk    r| j        st          j        t          t           j	                  }t          j
        |d           t          j        |           t          | d          r4t          t          t          | j                 t!                                 d S d S t          j
        | j                                        | j                   t          | d          r-t          t          t          | j                 | j                   d S d S )Nz;saved filedescriptor not valid, did you call start() twice?r   r3   )r.   fstatr0   OSError
ValueErrorr(   r-   opendevnullpathO_RDONLYdup2r,   hasattrsetattrr1   r2   DontReadFromInputfileno)r   fds     r   r4   zFDCapture.start4   s<   	/HT\"""" 	/ 	/ 	/ . / / /	/ =Adlbk22BGBNNNHRLLLtY'' O\$-8:K:M:MNNNNNO O GDL''))4=999tY'' H\$-8$,GGGGGH Hs    6c                 @   t          j        | j        | j                   t          j        | j                   | j        dk    r| j                            d           t          | d          r+t          t          t          | j                 | j                   | j        S )zF unpatch and clean up, returns the self.tmpfile (file object)
        r   r3   )r.   r@   r0   r(   r,   r-   seekrA   rB   r1   r2   r3   r   s    r   donezFDCapture.doneE   s     	dm,,,
=ALa   4## 	DCdm4dlCCC|r   c                 
   t          j                    }	 t          j        | j        |                                           |                    |           |                                 dS # |                                 w xY w)z8 write a string to the original file descriptor
        N)r)   r*   r.   r@   r0   rD   r   r,   )r   r   tempfps      r   writeorgzFDCapture.writeorgP   sh     '))	GDL&--//222LLLLNNNNNFLLNNNNs   AA, ,B)NTF)r   r   r   __doc__r8   r4   rI   rL   r   r   r   r%   r%      s^        ??   $H H H"	 	 	    r   r%   Fc                 l   	 |                                  }|p| j        }n# t          $ r |r | cY S w xY wt          j        |          }t
          j        dk    r3||                    dd          }d}t          j        ||||d          S t          j        |||          } |t          | |          S | S )ae   return a new open file object that's a duplicate of f

        mode is duplicated if not given, 'buffering' controls
        buffer size (defaulting to no buffering) and 'raising'
        defines whether an exception is raised when an incompatible
        file object is passed in (if raising is False, the file
        object itself will be returned)
    r   Nb T)closefd)
rD   modeAttributeErrorr.   r/   r1   version_infor   fdopenEncodedFile)r7   rR   	bufferingraisingr'   rE   newfds          r   r+   r+   [   s    XXZZ~qv    	 F2JJE
5  <<R((DIyi4HHHHIeT9--q(+++s     22c                   &    e Zd Zd Zd Zd Zd ZdS )rV   c                 "    || _         || _        d S N)_streamr'   )r   r]   r'   s      r   r8   zEncodedFile.__init__x   s     r   c                     t          |t                    r|                    | j                  }n%t          |t                    rnt	          |          }| j                            |           d S r\   )r   r   encoder'   strr]   r   )r   objs     r   r   zEncodedFile.write|   se    c7## 	**T]++CCS!! 	c((C3r   c                 Z    d                     |          }|                     |           d S )NrP   )joinr   )r   linelistr   s      r   
writelineszEncodedFile.writelines   s+    wwx  

4r   c                 ,    t          | j        |          S r\   )r   r]   )r   names     r   __getattr__zEncodedFile.__getattr__   s    t|T***r   N)r   r   r   r8   r   re   rh   r   r   r   rV   rV   w   sP        ! ! !       + + + + +r   rV   c                   6    e Zd Zd Z ee          Zd Zd ZdS )Capturec                      |             }	  ||i |}|                                 \  }}n# |                                 \  }}w xY w|||fS )z return a (res, out, err) tuple where
            out and err represent the output/error output
            during function execution.
            call the given function with args/kwargs
            and capture output/error during its execution.
        )reset)clsfuncargskwargssoresouterrs           r   callzCapture.call   sd     SUU	"$'''CxxzzHCrxxzzHC!!!!C}s	   , Ac                 b   t          | d          rt          d          d| _        |                     d          \  }}d\  }}|r/|j        s(|                                }|                                 |r5||k    r/|j        s(|                                }|                                 ||fS )z@ reset sys.stdout/stderr and return captured output as strings. _resetzwas already resetTF)save)rP   rP   )rA   r<   rw   rI   closedreadr,   )r   outfileerrfilers   rt   s        r   rl   zCapture.reset   s    4"" 	2011199%900S 	7> 	,,..CMMOOO 	w'))'.),,..CMMOOOCxr   c                 \    |                                  }|                                 \  }}|S )z7 return current snapshot captures, memorize tempfiles. )
readouterrrI   )r   outerrr{   r|   s       r   suspendzCapture.suspend   s(    ""99;;r   N)r   r   r   ru   classmethodrl   r   r   r   r   rj   rj      sR           ;tD      r   rj   c                   D    e Zd ZdZ	 	 ddZd Zd Zd ZddZd	 Z	d
 Z
dS )StdCaptureFDz This class allows to capture writes to FD1 and FD2
        and may connect a NULL file to FD0 (and prevent
        reads from sys.stdin).  If any of the 0,1,2 file descriptors
        is invalid it will not be captured.
    TFc                 z    ||||||d| _         |                                  |r|                                  d S d S )N)rs   rt   mixedin_r6   r5   )_options_savestartall)r   rs   rt   r   r   r6   r5   s          r   r8   zStdCaptureFD.__init__   sV      
 
 	

 	MMOOOOO	 	r   c                 X   | j         d         }| j         d         }| j         d         }| j         d         }| j         d         }|r*	 t          dd d|          | _        n# t          $ r Y nw xY w|rRd }t	          |d	          r|}	 t          d
|d|          | _        | j        j        | j         d<   n# t          $ r Y nw xY w|rf|r|r| j        j        }nt	          |d	          r|}nd }	 t          d|d|          | _        | j        j        | j         d<   d S # t          $ r Y d S w xY wd S )Nr   rs   rt   r   r6   r   F)r-   r5   r6   r   r"   r#   )r   r%   r   r;   rA   rs   r-   rt   )r   r   rs   rt   r   r6   r-   s          r   r   zStdCaptureFD._save   s   mE"mE"mE"g&=, 	$Q%%' ' '    		GsG$$ $Q$x9 9 9'+x'7e$$    	 u (*g&& $Q$x9 9 9'+x'7e$$$   	 	s6   A 
A+*A+,B2 2
B?>B?+,D 
D'&D'c                     t          | d          r| j                                         t          | d          r| j                                         t          | d          r| j                                         d S d S )Nr   rs   rt   )rA   r   r4   rs   rt   rH   s    r   r   zStdCaptureFD.startall   s~    4 	HNN4 	HNN4 	HNN	 	r   c                 .    |                                   dS z, resume capturing with original temp files. Nr   rH   s    r   resumezStdCaptureFD.resume       r   c                 x   dx}}t          | d          r*| j        j        j        s| j                                        }t          | d          r*| j        j        j        s| j                                        }t          | d          r| j                                        }|r|                                  ||fS )/ return (outfile, errfile) and stop capturing. Nrs   rt   r   )rA   rs   r-   ry   rI   rt   r   r   )r   rx   r{   r|   r-   s        r   rI   zStdCaptureFD.done   s      '4 	&(8(? 	&hmmooG4 	&(8(? 	&hmmooG4 	&hmmooG 	JJLLLr   c                     t          | d          r |                     | j        j                  }nd}t          | d          r |                     | j        j                  }nd}||fS )4 return snapshot value of stdout/stderr capturings. rs   rP   rt   )rA   _readsnapshotrs   r-   rt   r   rs   rt   s      r   r~   zStdCaptureFD.readouterr  sm    4 	$$TX%566CCC4 	$$TX%566CCCCxr   c                    |                     d           |                                }t          |dd           }|r!t          j                            ||d          }|                    d           |                     d           |S )Nr   r'   r   )rG   rz   r   pybuiltin_totexttruncate)r   r7   rr   encs       r   r   zStdCaptureFD._readsnapshot  ss    	q			ffhhaT** 	:*$$S#y99C	

1	q			
r   N)TTFTTTT)r   r   r   rM   r8   r   r   r   rI   r~   r   r   r   r   r   r      s         
 27%)   " " "H           
 
 
    r   r   c                   4    e Zd ZdZd
dZd ZddZd Zd Zd	S )
StdCapturea   This class allows to capture writes to sys.stdout|stderr "in-memory"
        and will raise errors on tries to read from sys.stdin. It only
        modifies sys.stdout|stderr|stdin attributes and does not
        touch underlying File Descriptors (use StdCaptureFD for that).
    TFc                 P   t           j        | _        t           j        | _        t           j        | _        |rt          |d          st                      }|| _	        |r#|r|}nt          |d          st                      }|| _
        || _        |r|                                  d S d S )Nfiler   )r1   r    _oldoutr!   _olderrr   _oldinrA   r   rs   rt   r   r   )r   rs   rt   r   r   r5   s         r   r8   zStdCapture.__init__   s    zzy 	wsF++ 	((C 	 S'** hh 	MMOOOOO	 	r   c                     | j         r| j         t          _        | j        r| j        t          _        | j        r!t                      xt          _        | _        d S d S r\   )rs   r1   r    rt   r!   r   rC   r   rH   s    r   r   zStdCapture.startall1  sT    8 	"CJ8 	"CJ8 	9%6%8%88CI	9 	9r   c                 B   dx}}| j         r9| j         j        s-| j        t          _        | j         }|                    d           | j        r9| j        j        s-| j        t          _        | j        }|                    d           | j	        r| j
        t          _        ||fS )r   Nr   )rs   ry   r   r1   r    rG   rt   r   r!   r   r   r   )r   rx   r{   r|   s       r   rI   zStdCapture.done9  s      '8 	DHO 	CJhGLLOOO8 	DHO 	CJhGLLOOO8 	$CIr   c                 .    |                                   dS r   r   rH   s    r   r   zStdCapture.resumeH  r   r   c                 b   dx}}| j         rM| j                                         }| j                             d           | j                             d           | j        rM| j                                        }| j                            d           | j                            d           ||fS )r   rP   r   )rs   getvaluer   rG   rt   r   s      r   r~   zStdCapture.readouterrL  s    c8 	(##%%CHa   HMM!8 	(##%%CHa   HMM!Cxr   N)TTTFTr   )	r   r   r   rM   r8   r   rI   r   r~   r   r   r   r   r     ss         
   "9 9 9             r   r   c                   6    e Zd ZdZd ZeZeZeZd Zd Z	d Z
dS )rC   a  Temporary stub class.  Ideally when stdin is accessed, the
    capturing should be turned off, with possibly all data captured
    so far sent to the screen.  This should be configurable, though,
    because in automated test runs it is better to crash than
    hang indefinitely.
    c                      t          d          )Nz+reading from stdin while output is captured)IOError)r   ro   s     r   rz   zDontReadFromInput.read`  s    CDDDr   c                      t          d          )Nz/redirected Stdin is pseudofile, has no fileno())r<   rH   s    r   rD   zDontReadFromInput.filenof  s    JKKKr   c                     dS )NFr   rH   s    r   isattyzDontReadFromInput.isattyh  s    ur   c                     d S r\   r   rH   s    r   r,   zDontReadFromInput.closej  s    r   N)r   r   r   rM   rz   readline	readlines__iter__rD   r   r,   r   r   r   rC   rC   Y  so         E E EHIHL L L      r   rC   ntNULz	/dev/null)Nr   FN)r.   r1   r   r)   ior   ImportErrorrT   r   r   r2   r%   r+   objectrV   rj   r   r   rC   devnullr>   rS   rg   r   r   r   <module>r      s   				 



 				 " " " "!!!!!!!!" e. . . . . . . . . F. . . .. . . . .( . . . . .. xH559 9 9 9 9 9 9 9x   8+ + + + +& + + +*# # # # #f # # #Le e e e e7 e e eP= = = = = = = =~       ("*KKK " " "	w$!	"s6    ''A A$#A$C C("C('C(