Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/prompt_toolkit/__pycache__/patch_stdout.cpython-39.pyc
Ðазад
a d�h% � @ s� d Z ddlmZ ddlZddlZddlZddlZddlZddlm Z ddl mZmZm Z ddlmZmZ ddlmZ d d gZe ddd d�dd ��ZG dd� d�ZG dd � d �ZdS )a� patch_stdout ============ This implements a context manager that ensures that print statements within it won't destroy the user interface. The context manager will replace `sys.stdout` by something that draws the output above the current prompt, rather than overwriting the UI. Usage:: with patch_stdout(application): ... application.run() ... Multiple applications can run in the body of the context manager, one after the other. � )�annotationsN)�contextmanager)� Generator�TextIO�cast� )�get_app_session�run_in_terminal)�Output�patch_stdout�StdoutProxyF�boolzGenerator[None, None, None])�raw�returnc c sx t | d��Z}tj}tj}tt|�t_tt|�t_zdV W |t_|t_n|t_|t_0 W d � n1 sj0 Y dS )a� Replace `sys.stdout` by an :class:`_StdoutProxy` instance. Writing to this proxy will make sure that the text appears above the prompt, and that it doesn't destroy the output from the renderer. If no application is curring, the behavior should be identical to writing to `sys.stdout` directly. Warning: If a new event loop is installed using `asyncio.set_event_loop()`, then make sure that the context manager is applied after the event loop is changed. Printing to stdout will be scheduled in the event loop that's active when the context manager is created. :param raw: (`bool`) When True, vt100 terminal escape sequences are not removed/escaped. )r N)r �sys�stdout�stderrr r )r �proxy�original_stdoutZoriginal_stderr� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/prompt_toolkit/patch_stdout.pyr ( s �c @ s e Zd ZdZdS )�_Donez-Sentinel value for stopping the stdout proxy.N)�__name__� __module__�__qualname__�__doc__r r r r r I s r c @ s e Zd ZdZd5dddd�dd �Zd d �dd�Zd dd�dd�Zdd �dd�Zdd �dd�Zdd �dd�Z dd �dd�Z dddd�dd�Zddd�d d!�Zdd �d"d#�Z dd$d�d%d&�Zdd �d'd(�Zed)d �d*d+��Zd$d �d,d-�Zdd �d.d/�Zedd �d0d1��Zedd �d2d3��Zd4S )6r a� File-like object, which prints everything written to it, output above the current application/prompt. This class is compatible with other file objects and can be used as a drop-in replacement for `sys.stdout` or can for instance be passed to `logging.StreamHandler`. The current application, above which we print, is determined by looking what application currently runs in the `AppSession` that is active during the creation of this instance. This class can be used as a context manager. In order to avoid having to repaint the prompt continuously for every little write, a short delay of `sleep_between_writes` seconds will be added between writes in order to bundle many smaller writes in a short timespan. 皙�����?F�floatr �None)�sleep_between_writesr r c C sL || _ || _t�� | _g | _t� | _| jj| _ t �� | _| � � | _d| _d S �NF)r r � threading�RLock�_lock�_bufferr �app_session�output�_output�queue�Queue�_flush_queue�_start_write_thread� _flush_thread�closed)�selfr r r r r �__init___ s zStdoutProxy.__init__�r c C s | S �Nr �r. r r r � __enter__z s zStdoutProxy.__enter__�object)�argsr c G s | � � d S r1 )�close)r. r5 r r r �__exit__} s zStdoutProxy.__exit__c C s( | j s$| j�t� � | j�� d| _ dS )z� Stop `StdoutProxy` proxy. This will terminate the write thread, make sure everything is flushed and wait for the write thread to finish. TN)r- r* �putr r, �joinr2 r r r r6 � s zStdoutProxy.closezthreading.Threadc C s t j| jddd�}|�� |S )Nzpatch-stdout-flush-threadT)�target�name�daemon)r! �Thread� _write_thread�start)r. �threadr r r r+ � s �zStdoutProxy._start_write_threadc C s� d}|s�| j �� }t|t�rq�|s$qg }|�|� z| j �� }W n tjyX Y qvY q20 t|t�rjd}q2|�|� q2| �� }| � |d� |�� |d urt�| j � qd S )NFT� )r* �get� isinstancer �append� get_nowaitr( �Empty� _get_app_loop�_write_and_flushr9 �time�sleepr )r. �done�item�textZapp_loopr r r r>