
    (phz                        S r SSKJrJr  SSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKrSSKJr  SSKrSSKr\R$                  " \SS9rS=rrSrS	S
/rSS/r\R2                  R5                  S5      (       a  S
/rS/rSR7                  5       r\R2                  R5                  S5      (       a`   \R:                  " S\R<                  SS9R?                  5       S   RA                  5        V s/ s H  o R7                  SS5      S   PM     sn rO0\R2                  R5                  S5      (       a  SR7                  5       rS r" " S S\#5      r$\SS4S jr%S"S jr&\RN                  S 5       r(S r)S r*\RV                  " \S9S 5       r,\RV                  " \S9S  5       r-\RV                  " \S9S! 5       r.gs  sn f ! \! a     Nf = f)#z)Accessories for automated py.test runner.    )with_statementprint_functionN)Terminalzxterm-256color)kinds
   SEMAPHORE
s   SEMAPHORE
(   P      
   
TEST_QUICK   z)xterm screen ansi vt220 rxvt cons25 linux	TEST_FULL)toez-aT)stdout	close_fdszxterm screen ansi linuxc                 P    SS K n[        R                  R	                  [        R                  R                  [        5      [        R                  [        R                  S5      nUR                  US9nUR                  SU 5        UR                  5         U$ ! [         a     g f = f)Nr   z.coveragerc)config_filezrun:note)coverageImportErrorospathjoindirname__file__pardirCoverage
set_optionstart)run_noter   _coveragerccovs       L/var/www/html/venv/lib/python3.13/site-packages/blessed/tests/accessories.pyinit_subproc_coverager"   3   s    	 ggllGGOOH%IIryy K8z8,		
  		s   B 
B%$B%c                   ,    \ rS rSrSrSrSrS rS rSr	g)	as_subprocessB   zThis helper executes test cases in a child process,
avoiding a python-internal bug of _curses: setupterm()
may not be called more than once per process.
r   utf8c                     Xl         g )Nfunc)selfr)   s     r!   __init__as_subprocess.__init__J   s    	    c           	      4   [         R                  " 5       n[        R                  " 5       u  pEX@R                  :X  a  [        SR                  [         R                  " 5       U R                  XS95      n U R                  " U0 UD6  Ub   UR                  5         UR                  5         [         R                  " S5        U[         R                  " 5       :w  aQ  [;        S	R                  U[         R                  " 5       5      [        R<                  S
9  [         R                  " S5        [>        R@                  " 5       n[B        RD                  " U RF                  5      " 5       n  [         RH                  " US5      nU(       d  OXRM                  U5      -  nM5  [         RN                  " US5      u  pO[         R4                  " U5        SS< SU< SS< 3nUS:X  d   U5       e[         RP                  " U5      S:X  d   eg ! [         Ga    [        R                  " 5       u  pxn	[        5       n
[        R                   " U	5       H1  nU
R#                  UR%                  5       R'                  S5      5        M3     U
R#                  SR'                  S5      5        U
R)                  [        R*                  " Xx5       Vs/ s H!  oR%                  5       R'                  S5      PM#     Os  snf sn5        [         R,                  " [        R.                  R1                  5       SR3                  U
5      5        [         R4                  " [        R.                  R1                  5       5        [         R4                  " [        R6                  R1                  5       5        [         R4                  " [        R8                  R1                  5       5        Ub   UR                  5         UR                  5         [         R                  " S5         GNEf = f! [J         a     GM}  f = f)Nz5@as_subprocess-{pid};{func_name}(*{args}, **{kwargs}))pid	func_nameargskwargsr   zutf-8z(-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=ascii   
r	   z&TEST RUNNER HAS FORKED, {0}=>{1}: EXIT)filei  zOutput in child process:
z(========================================
 ))r   getpidptyfork
_CHILD_PIDr"   formatr)   stopsave_exit	Exceptionsysexc_infolist	traceback	format_tbappendrstripencodeextendformat_exception_onlywrite
__stdout__filenor   close
__stderr__	__stdin__printstderrsix	text_typecodecsgetincrementaldecoderencodingreadOSErrordecodewaitpidWEXITSTATUS)r*   r1   r2   pid_testrunnerr/   	master_fdr    e_typee_valuee_tbo_errline_exc
exc_outputdecoderstatusexc_output_msgs                    r!   __call__as_subprocess.__call__M   s   //!
 (GBIIK499!  23C		4*6*& ?HHJHHJ RYY[(:6."))+6SZZIHHQK]]_
..t}}=?wwy%0 ....J  jja(

 z9/R// ~~f%***m  (+%%//5DLL!5!5g!>? 6i//89'=="(343 AEkkm227;34 5 ..0%**U2CD..01..01--/0?HHJHHJ!D  s2   4H  %P  B;P;(K$
#DPP
PPr(   N)
__name__
__module____qualname____firstlineno____doc__r;   rW   r+   ri   __static_attributes__ r-   r!   r$   r$   B   s     JHD+r-   r$   r&   c                    [         R                  " 5       n[        R                  " U5      " 5       nUR	                  S5      nUR                  U5      (       dJ   [        R                  " U S5      nU(       d  O*XER	                  USS9-  nUR                  U5      (       d  MJ  UR                  U5      (       d   SU< SU< S35       eU[        U5      S $ ! [         a     MA  f = f)	a7  Read file descriptor ``fd`` until ``semaphore`` is found.

Used to ensure the child process is awake and ready. For timing
tests; without a semaphore, the time to fork() would be (incorrectly)
included in the duration of the test, which can be very length on
continuous integration servers (such as Travis-CI).
r3   r	   Ffinalz)Semaphore not recv before EOF (expected: z, got: )N)
rS   rT   rU   rV   rZ   
startswithr   rX   rY   len)fd	semaphorerW   timeoutoutprf   rd   s          r!   read_until_semaphorer|      s     ==?D**846G  )Iooi((	772q>D t511 ooi(( ??9%% 8%.	78% I    		s   C 
C$#C$c                     [         R                  " U5      " 5       n[        R                  " 5       n  [        R
                  " U S5      nU(       d   U$ X2R                  USS9-  nM6  ! [         a     U$ f = f)z=Read file descriptor ``fd`` until EOF. Return decoded string.d   Frs   )rU   rV   rS   rT   r   rX   rY   rZ   )rx   rW   rf   r{   rd   s        r!   read_until_eofr      s|    **846G==?D
	772s#D K 	t511   	 K	s   A( (
A65A6c              #     #     [         R                  " U 5      nUS   [         R                  ) -  US'   [         R                  " U [         R                  U5        Sv   US   [         R                  -  US'   [         R                  " U [         R                  U5        g! WS   [         R                  -  US'   [         R                  " U [         R                  U5        f = f7f)z@Ensure any bytes written to pty fd are not duplicated as output.   N)termios	tcgetattrECHO	tcsetattrTCSANOW)rx   attrss     r!   echo_offr      s     6!!"%8w||m+a"goou58gll*a"goou5 8gll*a"goou5s   C"AB A C"ACC"c                      [         R                  " U 5      nU(       a  UR                  S5      $ g! [         R                   a    Sn N1f = f)z4Return the result of ``tigetstr`` except as Unicode.Nlatin1r7   )cursestigetstrerrorrZ   )capvals     r!   unicode_capr      sF    ooc" zz(##	 << s   1 A
	A
c                     [         R                  " U 5      n U (       a0   [         R                  " U /UQ76 nU(       a  UR	                  S5      $ g! [         R                   a    Sn  NPf = f! [         R                   a    Sn NMf = f)z=Return the result of ``tparm(tigetstr())`` except as Unicode.Nr   r7   )r   r   r   tparmrZ   )r   parmsr   s      r!   unicode_parmr      s|    ooc" 	,,s+U+C ::h'' << 
 || 	C	s"   A A, A)(A),BB)paramsc                     U R                   $ )z.Common kind values for all kinds of terminals.paramrequests    r!   	all_termsr           ==r-   c                     U R                   $ )z*Various number of lines for screen height.r   r   s    r!   
many_linesr      r   r-   c                     U R                   $ )z+Various number of columns for screen width.r   r   s    r!   many_columnsr      r   r-   )r&   )/ro   
__future__r   r   
contextlib
subprocess	functoolsrD   r   rU   r   rA   r9   r   blessedr   pytestrS   partialTestTerminalSEND_SEMAPHORE	SEMAPHORERECV_SEMAPHOREmany_lines_paramsmany_columns_paramsenvirongetsplitall_terms_paramsPopenPIPEcommunicate
splitlinesrY   r"   objectr$   r|   r   contextmanagerr   r   r   fixturer   r   r   )_terms   0r!   <module>r      s   / 5        
 
 	   
  0@A+ +!H "g ::>>,%>DDF ::>>+	 ]$.OO'+- []1 )jl+,+ ).KKa #+, ZZ^^L!!0668O+F O+d (6"("!< 	6 	6  '( )
 () *
 *+ ,a,  s$   7=G 4F<G <G G
	G
