Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /usr/local/lib/python3.9/site-packages/prompt_toolkit/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/lib/python3.9/site-packages/prompt_toolkit/__pycache__/validation.cpython-39.pyc
a

��Sh��@s�dZddlmZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
mZgd	�ZGd
d�de�ZGdd
�d
ed�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)zV
Input validation for a `Buffer`.
(Validators will be called before accepting input.)
�)�annotations)�ABCMeta�abstractmethod)�Callable��run_in_executor_with_context�)�Document)�FilterOrBool�	to_filter)�ConditionalValidator�ValidationError�	Validator�ThreadedValidator�DummyValidator�DynamicValidatorcs:eZdZdZd
dddd��fdd	�
Zdd
�dd�Z�ZS)r
z�
    Error raised by :meth:`.Validator.validate`.

    :param cursor_position: The cursor position where the error occurred.
    :param message: Text.
    r��int�str�None)�cursor_position�message�returncst��|�||_||_dS�N)�super�__init__rr)�selfrr��	__class__��C/usr/local/lib/python3.9/site-packages/prompt_toolkit/validation.pyr"szValidationError.__init__�rcCs|jj�d|j�d|j�d�S)Nz(cursor_position=z
, message=�))r�__name__rr�rrrr �__repr__'szValidationError.__repr__)rr)r#�
__module__�__qualname__�__doc__rr%�
__classcell__rrrr r
sr
c@sNeZdZdZeddd�dd��Zddd�dd�Zedddd
dd�dd��ZdS)ra�
    Abstract base class for an input validator.

    A validator is typically created in one of the following two ways:

    - Either by overriding this class and implementing the `validate` method.
    - Or by passing a callable to `Validator.from_callable`.

    If the validation takes some time and needs to happen in a background
    thread, this can be wrapped in a :class:`.ThreadedValidator`.
    r	r��documentrcCsdS)z�
        Validate the input.
        If invalid, this should raise a :class:`.ValidationError`.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        Nr�rr+rrr �validate8szValidator.validatec�s(z|�|�Wnty"�Yn0dS)z�
        Return a `Future` which is set when the validation is ready.
        This function can be overloaded in order to provide an asynchronous
        implementation.
        N)r-r
r,rrr �validate_asyncBszValidator.validate_async�
Invalid inputF�Callable[[str], bool]r�bool)�
validate_func�
error_message�move_cursor_to_endrcCst|||�S)aF
        Create a validator from a simple validate callable. E.g.:

        .. code:: python

            def is_valid(text):
                return text in ['hello', 'world']
            Validator.from_callable(is_valid, error_message='Invalid input')

        :param validate_func: Callable that takes the input string, and returns
            `True` if the input is valid input.
        :param error_message: Message to be displayed if the input is invalid.
        :param move_cursor_to_end: Move the cursor to the end of the input, if
            the input is invalid.
        )�_ValidatorFromCallable)�clsr2r3r4rrr �
from_callableMszValidator.from_callableN)r/F)	r#r&r'r(rr-r.�classmethodr7rrrr r+s	�r)�	metaclassc@sBeZdZdZddddd�dd�Zdd	�d
d�Zddd
�dd�ZdS)r5z0
    Validate input from a simple callable.
    r0rr1r)�funcr3r4rcCs||_||_||_dSr)r:r3r4)rr:r3r4rrr rksz_ValidatorFromCallable.__init__r!cCsd|j�d�S)NzValidator.from_callable(r")r:r$rrr r%rsz_ValidatorFromCallable.__repr__r	r*cCs4|�|j�s0|jrt|j�}nd}t||jd��dS)Nr)rr)r:�textr4�lenr
r3)rr+�indexrrr r-us
z_ValidatorFromCallable.validateN)r#r&r'r(rr%r-rrrr r5fsr5c@s@eZdZdZddd�dd�Zddd�d	d
�Zddd�dd�Zd
S)rz�
    Wrapper that runs input validation in a thread.
    (Use this to prevent the user interface from becoming unresponsive if the
    input validation takes too much time.)
    rr)�	validatorrcCs
||_dSr)r>)rr>rrr r�szThreadedValidator.__init__r	r*cCs|j�|�dSr)r>r-r,rrr r-�szThreadedValidator.validatec�s&dd���fdd�}t|�IdHdS)z:
        Run the `validate` function in a thread.
        rr!cs
����Sr)r-r�r+rrr �run_validation_thread�sz?ThreadedValidator.validate_async.<locals>.run_validation_threadNr)rr+r@rr?r r.�sz ThreadedValidator.validate_asyncN�r#r&r'r(rr-r.rrrr rsrc@s eZdZdZddd�dd�ZdS)rz1
    Validator class that accepts any input.
    r	rr*cCsdSrrr,rrr r-�szDummyValidator.validateN)r#r&r'r(r-rrrr r�src@s2eZdZdZdddd�dd�Zddd	�d
d�ZdS)
rzq
    Validator that can be switched on/off according to
    a filter. (This wraps around another validator.)
    rr
r)r>�filterrcCs||_t|�|_dSr)r>rrB)rr>rBrrr r�szConditionalValidator.__init__r	r*cCs|��r|j�|�dSr)rBr>r-r,rrr r-�szConditionalValidator.validateN)r#r&r'r(rr-rrrr r�src@s@eZdZdZddd�dd�Zddd�d	d
�Zddd�dd�Zd
S)rz�
    Validator class that can dynamically returns any Validator.

    :param get_validator: Callable that returns a :class:`.Validator` instance.
    zCallable[[], Validator | None]r)�
get_validatorrcCs
||_dSr)rC)rrCrrr r�szDynamicValidator.__init__r	r*cCs|��pt�}|�|�dSr)rCrr-�rr+r>rrr r-�szDynamicValidator.validatec�s"|��pt�}|�|�IdHdSr)rCrr.rDrrr r.�szDynamicValidator.validate_asyncNrArrrr r�srN)r(�
__future__r�abcrr�typingrZprompt_toolkit.eventlooprr+r	�filtersr
r�__all__�	Exceptionr
rr5rrrrrrrr �<module>s
;	

Yohohohohohooho | Sanrei Aya