o
    Phz                     @   s  d Z ddlmZmZ ddlZddlZddlZddlZddlZddl	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ejeddZd ZZdZd	d
gZddgZejdrad
gZdgZd Zejdrzdd ejdejdd d   D ZW n e!y   Y nw ejdrd Zdd Z"G dd de#Z$eddfddZ%d-ddZ&ej'd d! Z(d"d# Z)d$d% Z*ej+ed&d'd( Z,ej+ed&d)d* Z-ej+ed&d+d, Z.dS ).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_FULLc                 C   s   g | ]
}| d dd qS )Nr   r   )split).0_term r   T/var/www/html/env_mimamsha/lib/python3.10/site-packages/blessed/tests/accessories.py
<listcomp>&   s    r   )toez-aT)stdout	close_fdszxterm screen ansi linuxc                 C   sd   zdd l }W n
 ty   Y d S w tjtjttjtjd}|j|d}|	d|  |
  |S )Nr   z.coveragerc)config_filezrun:note)coverageImportErrorospathjoindirname__file__pardirCoverage
set_optionstart)run_noter   _coveragerccovr   r   r   init_subproc_coverage3   s   
r%   c                   @   s(   e Zd ZdZdZdZdd Zdd ZdS )	as_subprocesszThis 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                 C   s
   || _ d S )N)func)selfr(   r   r   r   __init__J   s   
zas_subprocess.__init__c              
   O   s&  t  }t \}}|| jkrtdjt  | j||d}z
| j|i | W np ty   t	
 \}}}	t }
t|	D ]}|
| d q=|
dd |
dd t||D  t t	j d|
 t t	j  t t	j  t t	j  |d ur|  |  t d	 Y nw |d ur|  |  t d
 |t  krtd|t  t	jd t d	 t  }t!"| j# }	 zt $|d}W n	 t%y   Y nw |sn||&|7 }qt '|d
\}}t | dd|df }|dksJ |t (|d
ksJ d S )Nz5@as_subprocess-{pid};{func_name}(*{args}, **{kwargs}))pid	func_nameargskwargsutf-8z(-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=asciic                 S   s   g | ]	}|  d qS )r/   )rstripencode)r   _excr   r   r   r   a   s    z*as_subprocess.__call__.<locals>.<listcomp>   
r   r   z&TEST RUNNER HAS FORKED, {0}=>{1}: EXIT)fileTi  z!Output in child process:
%s
%s
%sz(======================================== ))r   getpidptyfork
_CHILD_PIDr%   formatr(   	Exceptionsysexc_infolist	traceback	format_tbappendr1   r2   extendformat_exception_onlywrite
__stdout__filenor   close
__stderr__	__stdin__stopsave_exitprintstderrsix	text_typecodecsgetincrementaldecoderencodingreadOSErrordecodewaitpidWEXITSTATUS)r)   r-   r.   pid_testrunnerr+   	master_fdr$   e_typee_valuee_tbo_errline
exc_outputdecoderr3   statusexc_output_msgr   r   r   __call__M   sv   




zas_subprocess.__call__N)__name__
__module____qualname____doc__r:   rT   r*   re   r   r   r   r   r&   B   s    r&   r'   c                 C   s   t  }t| }|d}||s7zt| d}W n	 ty%   Y nw |s)n||j|dd7 }||r||sDJ d||f |t	|d S )aK  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).
    r0   r   Ffinalz5Semaphore not recv before EOF (expected: %r, got: %r)N)
rP   rQ   rR   rS   rW   
startswithr   rU   rV   len)fd	semaphorerT   timeoutoutprb   r3   r   r   r   read_until_semaphore   s&   


rr   c                 C   sZ   t | }t }	 zt| d}W n
 ty   Y |S w |s#	 |S ||j|dd7 }q)z=Read file descriptor ``fd`` until EOF. Return decoded string.Td   Frj   )rR   rS   rP   rQ   r   rU   rV   rW   )rn   rT   rb   rq   r3   r   r   r   read_until_eof   s   rt   c                 c   s    z.t | }|d t j @ |d< t | t j| dV  W |d t jB |d< t | t j| dS |d t jB |d< t | t j| w )z@Ensure any bytes written to pty fd are not duplicated as output.   N)termios	tcgetattrECHO	tcsetattrTCSANOW)rn   attrsr   r   r   echo_off   s   
r|   c                 C   s:   zt | }W n t jy   d}Y nw |r|dS dS )z4Return the result of ``tigetstr`` except as Unicode.Nlatin1r6   )cursestigetstrerrorrW   )capvalr   r   r   unicode_cap   s   
r   c                 G   sn   zt | } W n t jy   d} Y nw | r5zt j| g|R  }W n t jy-   d}Y nw |r5|dS dS )z=Return the result of ``tparm(tigetstr())`` except as Unicode.Nr}   r6   )r~   r   r   tparmrW   )r   parmsr   r   r   r   unicode_parm   s   
r   )paramsc                 C      | j S )z.Common kind values for all kinds of terminals.paramrequestr   r   r   	all_terms      r   c                 C   r   )z*Various number of lines for screen height.r   r   r   r   r   
many_lines   r   r   c                 C   r   )z+Various number of columns for screen width.r   r   r   r   r   many_columns   r   r   )r'   )/ri   
__future__r   r   
contextlib
subprocess	functoolsr@   rv   rR   r~   r=   r8   r   blessedr   pytestrP   partialTestTerminalSEND_SEMAPHORE	SEMAPHORERECV_SEMAPHOREmany_lines_paramsmany_columns_paramsenvirongetr   all_terms_paramsPopenPIPEcommunicate
splitlinesrV   r%   objectr&   rr   rt   contextmanagerr|   r   r   fixturer   r   r   r   r   r   r   <module>   sp   
R







