Mini Shell

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

3

<�Zc4(�@s�ddlZddlmZddlmZddlmZddlmZm	Z	ddgZ
Gdd�de�ZGd	d
�d
e	�Z
Gdd�de�ZGdd
�d
e
�ZdS)�N)�App)�InputReadySignal)�
TextWidget)�InputThreadManager�InputRequest�InputHandler�PasswordInputHandlercs�eZdZd�fdd�	Zdd�Zdd�Zedd	��Zed
d��Zedd
��Z	e	j
dd
��Z	dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Z�ZS) rNcs:t�j�d|_||_d|_d|_d|_||_|j�dS)a�Class to handle input from the terminal.

        This class is designed to be instantiated on place where it should be used.
        The main method is `get_input()` which is non-blocking asynchronous call. It can be used
        as synchronous call be calling the `wait_on_input` method.

        To get result from this class use the `value` property.

        :param callback: You can specify callback which will be called when user give input.
        :type callback: Callback function with one argument which will be user input.

        :param source: Source of this input. It will be helpful in case of debugging an issue.
        :type source: Class which will process an input from this InputHandler.
        NF)	�super�__init__�_input�_input_callback�_input_received�_input_successful�_skip_concurrency_check�_source�_register_input_ready_signal)�self�callback�source)�	__class__��#/usr/lib/python3.6/input_handler.pyr
 s
zInputHandler.__init__cCstj�jt|j�dS)N)r�get_event_loopZregister_signal_handlerr�_input_received_handler)rrrrr9s
z)InputHandler._register_input_ready_signalcCsR|j|krdSd|_|j|_|js&dS|j|_|jdk	rN|j}d|_||j�dS)NT)Zinput_handler_sourcer
�successr�datarr)r�signal�args�cbrrrr=s

z$InputHandler._input_received_handlercCs|jS)zVReturn user input.

        :returns: String or None if no is input received.
        )r)rrrr�valuePszInputHandler.valuecCs|jS)zQGet source of this input.

        :returns: Anything probably UIScreen.
        )r)rrrrrXszInputHandler.sourcecCs|jS)zPIs this InputHandler skipping concurrency check?

        :returns bool
        )r)rrrr�skip_concurrency_check`sz#InputHandler.skip_concurrency_checkcCs
||_dS)z�Set if this InputHandler should skip concurrency check.

        Note if you skip this check, you can have unexpected behavior. Use with caution.

        :param value: True to skip the check, False if not.
        N)r)rrrrrr hscCs
||_dS)z�Set a callback to get user input asynchronously.

        :param callback: Callback called when user write their input.
        :type callback: Method with 1 argument which is user input: def cb(user_input)
        N)r)rrrrr�set_callbackrszInputHandler.set_callbackcCs|jS)zZWas user input already received?

        :returns: True if yes, False otherwise.
        )r
)rrrr�input_receivedzszInputHandler.input_receivedcCs(|jr
dSx|js"tj�jt�qWdS)z�Blocks execution till the user input is received.

        Events will works as expected during this blocking.

        Please check the `input_successful` method to test the input.
        N)r
rrZprocess_signalsr)rrrr�
wait_on_input�szInputHandler.wait_on_inputcCs|jS)z6Was input successful?

        :returns: bool
        )r)rrrr�input_successful�szInputHandler.input_successfulcCs|j�|j|�dS)a>Use prompt to ask for user input and wait (non-blocking) on user input.

        This is an asynchronous call. If you want to wait for user input then use
        the `wait_on_input` method. If you want to get results asynchronously then register
        callback in constructor or by the `set_callback` method.

        Check if user input was already received can be done by the `input_received` method call.

        :param prompt: Ask user what you want to get.
        :type prompt: String or Prompt instance.

        :returns: User input.
        :rtype: str
        N)�_clear_input�_invoke_input_thread)r�promptrrr�	get_input�szInputHandler.get_inputcCs"|j|�}tj�j||j�dS)N)�create_thread_objectrZget_instanceZstart_input_threadr)rr'Z
thread_objectrrrr&�s

z!InputHandler._invoke_input_threadcCsttj�j||�S)z�Create thread object containing all the information how to get user input.

        :returns: Instance of class inherited from `simpleline.input.InputThread`.
        )�InputHandlerRequestr�get_configuration�width)rr'rrrr)�sz!InputHandler.create_thread_objectcCsd|_d|_dS)NF)r
r)rrrrr%�szInputHandler._clear_input)NN)�__name__�
__module__�__qualname__r
rr�propertyrrr �setterr!r"r#r$r(r&r)r%�
__classcell__rr)rrrs
cs@eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�Z	S)r*zJThis is thread object to get input from user without blocking main thread.cs t�j||j�||_||_dS)a�Create request object to get input in InputThreadManager.

        :param width: Width of the screen prompt.
        :type width: int

        :param prompt: Input prompt.
        :type prompt: Instance of `simpleline.render.prompt.Prompt` class.

        :param input_handler: InputHandler instance which created this object.
        :type input_handler: InputHandler based instance.
        N)r	r
r�_width�_prompt)rr,r'�
input_handler)rrrr
�szInputHandlerRequest.__init__cCs*y|j�}Wntk
r$d}YnX|S)z�This method is responsible for interruptable user input.

        It is expected to be used in a thread started on demand
        and returns the input via the communication Queue.
        �)�
_ask_input�EOFError)rrrrrr(�s

zInputHandlerRequest.get_inputcCs0tt|j��}|j|j�|j�}dj|�dS)N�
� )r�strr4Zrenderr3�	get_lines�join)rZwidget�linesrrr�text_prompt�szInputHandlerRequest.text_promptcCs&|j�}tjj|�tjj�|j�S)N)r?�sys�stdout�write�flush�
_get_input)rr?rrrr7�s
zInputHandlerRequest._ask_inputcCst�S)N)�input)rrrrrD�szInputHandlerRequest._get_input)
r-r.r/�__doc__r
r(r?r7rDr2rr)rrr*�sr*cs.eZdZd�fdd�	Zdd�Zdd�Z�ZS)	rNcs t�j||d�tj�j|_dS)a�Class to handle hidden password input from the terminal.

        This class is designed to be instantiated on place where it should be used.
        The main method is `get_input()` which is non-blocking asynchronous call. It can be used
        as synchronous call be calling the `wait_on_input` method.

        To get result from this class use the `value` property.

        :param callback: You can specify callback which will be called when user give input.
        :type callback: Callback function with one argument which will be user input.

        :param source: Source of this input. It will be helpful in case of debugging an issue.
        :type source: Class which will process an input from this InputHandler.
        )rrN)r	r
rr+Zpassword_function�
_getpass_func)rrr)rrrr
�szPasswordInputHandler.__init__cCs|sdS||_dS)z%Set a function for getting passwords.N)rG)r�getpass_funcrrr�
set_pass_func�sz"PasswordInputHandler.set_pass_funccCsttj�j|||j�S)z5Return PasswordInputThread for getting user password.)�PasswordInputHandlerRequestrr+r,rG)rr'rrrr)sz)PasswordInputHandler.create_thread_object)NN)r-r.r/r
rIr)r2rr)rrr�scs(eZdZdZ�fdd�Zdd�Z�ZS)rJz8Similar as InputHandlerRequest but don't echo user keys.cst�j|||�||_dS)aSCreate request object to get password input in InputThreadManager.

        :param width: Width of the screen prompt.
        :type width: int

        :param prompt: Input prompt.
        :type prompt: Instance of `simpleline.render.prompt.Prompt` class.

        :param input_handler: InputHandler instance which created this object.
        :type input_handler: InputHandler based instance.

        :param getpass_func: Function to get user password.
        :type getpass_func: Function which gets prompt as only parameter and returns user input
                            string.
        N)r	r
rG)rr,r'r5rH)rrrr
sz$PasswordInputHandlerRequest.__init__cCs|j�}|j|�S)N)r?rG)rr?rrrr7"sz&PasswordInputHandlerRequest._ask_input)r-r.r/rFr
r7r2rr)rrrJsrJ)r@Z
simplelinerZsimpleline.event_loop.signalsrZsimpleline.render.widgetsrZ simpleline.input.input_threadingrr�__all__�objectrr*rrJrrrr�<module>s2!