Mini Shell

Direktori : /lib/python3.6/site-packages/simpleline/input/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/simpleline/input/__pycache__/input_threading.cpython-36.pyc

3

<�Zc��@srddlZddlmZmZddlmZddlmZddlm	Z	m
Z
e�ZdZGdd�de
�ZGd	d
�d
e
ed�ZdS)�N)�ABCMeta�abstractmethod)�App)�get_simpleline_logger)�InputReceivedSignal�InputReadySignalZSimplelineInputThreadcsneZdZdZdZ�fdd�Zedd��Zdd�Zed	d
��Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Z�ZS)�InputThreadManagerzManager object for input threads.

    This manager helps with concurrent user input (still you really shouldn't do that).
    Ncst�j�g|_d|_dS)NF)�super�__init__�_input_stack�_processing_input)�self)�	__class__��%/usr/lib/python3.6/input_threading.pyr
*s
zInputThreadManager.__init__cCst�}||_|j�dS)N)r�_InputThreadManager__instance�_post_init_configuration)�cls�instancerrr�create_new_instance/sz&InputThreadManager.create_new_instancecCstj�jt|jj�dS)N)r�get_event_loopZregister_signal_handlerrr�_input_received_handler)r
rrrr6s
z+InputThreadManager._post_init_configurationcCs|js|j�|jS)N)rr)rrrr�get_instance:szInputThreadManager.get_instancecCsb|jj�}|j|j�|jr&|jj�x&|jD]}|j�|jr.|jj�q.W|jj�d|_dS)NF)	r�pop�emit_input_ready_signal�data�thread�join�emit_failed_input_ready_signal�clearr)r
�signal�args�
thread_object�trrrrAs


z*InputThreadManager._input_received_handlerTcCs"|jj|�|j|�|j�dS)z�Start input thread to get user input.

        :param input_thread_object: Input thread object based on InputThread class.
        :param concurrent_check: Should the concurrent thread check be fatal? (default True).
        N)r�append�_check_input_thread_running�_start_user_input_async)r
Zinput_thread_objectZconcurrent_checkrrr�start_input_threadRs
z%InputThreadManager.start_input_threadcCsht|j�dkrd|stjd�nFd}x*|jD] }|jp6d}|dj|j|�7}q*W|j�tdj|���dS)N�zcAsking for multiple inputs with concurrent check bypassed, last who asked wins! Others are dropped.�ZUnknownz&Input handler: {} Input requester: {}
zGCan't run multiple input threads at the same time!
Asking for input:
{})	�lenr�logZwarning�requester_source�format�source�rstrip�KeyError)r
Zraise_concurrent_check�msgr#r,rrrr%\s

z.InputThreadManager._check_input_thread_runningcCs8|jd}|jr|j|�dS|j�d|_|j�dS)Nr(T���)rr�_print_new_prompt�initialize_thread�start_thread)r
r"rrrr&ns

z*InputThreadManager._start_user_input_asynccCs|j�}t|dd�dS)Nr))�end)�text_prompt�print)r
r"�promptrrrr3ysz$InputThreadManager._print_new_prompt)T)�__name__�
__module__�__qualname__�__doc__rr
�classmethodrrrrr'r%r&r3�
__classcell__rr)rrr"s

rcs�eZdZdZd�fdd�	Zedd��Zedd��Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
edd��Zedd��Z�ZS)�InputRequestaBase input request class.

    This should be overloaded for every InputHandler class. Purpose of this class is to print
    prompt and get input from user.

    The `run_input` method is the entry point for this class. Output from this method must be
    a user input.
    The `text_prompt` method is used to get textual representation of a prompt. This will be used
    on concurrent input to replace existing prompt to get new input.

    WARNING:
        The `run_input` method will run in a separate thread!
    Ncs t�j�||_||_d|_dS)N)r	r
�_source�_requester_sourcer)r
r.r,)rrrr
�s
zInputRequest.__init__cCs|jS)z[Get direct source of this input request.

        :returns: InputHandler instance.
        )rA)r
rrrr.�szInputRequest.sourcecCs|jS)zmGet requester -- source of this input.

        :returns: Anything probably UIScreen based instance.
        )rB)r
rrrr,�szInputRequest.requester_sourcecCs0|j}|j�}t|||dd�}tj�j|�dS)z�Emit the InputReadySignal signal with collected input data.

        :param input_data: Input data received.
        :type input_data: str
        T)r.�input_handler_sourcer�successN)r.�_get_request_sourcerrr�enqueue_signal)r
Z
input_data�handler_source�
signal_source�
new_signalrrrr�s

z$InputRequest.emit_input_ready_signalcCs0|j}|j�}t||ddd�}tj�j|�dS)z,Emit the InputReadySignal with failed state.r)F)r.rCrrDN)r.rErrrrF)r
rGrHrIrrrr�s

z+InputRequest.emit_failed_input_ready_signalcCs|jp
|jS)z�Get user input request source.

        That means object who is using InputHandler.
        If this object is not specified then return InputHandler as a source.
        )r,r.)r
rrrrE�sz InputRequest._get_request_sourcecCstjt|jd�|_d|j_dS)z|Initialize thread for this input request.

        Do not call this directly! Will be called by InputThreadManager.
        )�name�targetTN)�	threadingZThread�INPUT_THREAD_NAME�runrZdaemon)r
rrrr4�szInputRequest.initialize_threadcCs|jj�dS)zfStart input thread.

        Do not call this directly! Will be called by InputThreadManager.
        N)r�start)r
rrrr5�szInputRequest.start_threadcCs |j�}tj�jt||��dS)z�Run the `run_input` method and propagate input outside.

        Do not call this method directly. It will be called by InputThreadManager.
        N)�	get_inputrrrFr)r
rrrrrN�szInputRequest.runcCsdS)z�Get text representation of the user prompt.

        This will be used to get high priority input.

        :returns: String representation of the prompt or None if no prompt is present.
        Nr)r
rrrr7�szInputRequest.text_promptcCsdS)z�Print prompt and get an input from user.

        ..NOTE: Overload this method in your class.

        Return this input from a function.
        r)r)r
rrrrP�szInputRequest.get_input)N)r:r;r<r=r
�propertyr.r,rrrEr4r5rNrr7rPr?rr)rrr@�s

		
r@)�	metaclass)rL�abcrrZ
simplelinerZsimpleline.loggingrZsimpleline.event_loop.signalsrrr+rM�objectrr@rrrr�<module>s^