
    Mh                    (   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZ g d	Z G d
 de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )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DynamicValidatorc                  .     e Zd ZdZdd fd
ZddZ xZS )r   z
    Error raised by :meth:`.Validator.validate`.

    :param cursor_position: The cursor position where the error occurred.
    :param message: Text.
    r    cursor_positionintmessagestrreturnNonec                f    t                                          |           || _        || _        d S N)super__init__r   r   )selfr   r   	__class__s      Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/validation.pyr   zValidationError.__init__"   s.    !!!.    c                @    | j         j         d| j        d| j        dS )Nz(cursor_position=z
, message=))r    __name__r   r   r   s    r!   __repr__zValidationError.__repr__'   s-    .)ooD<Poo^b^joooor"   )r   r   )r   r   r   r   r   r   r   r   )r%   
__module____qualname____doc__r   r'   __classcell__)r    s   @r!   r   r      sh               
p p p p p p p pr"   r   c                  P    e Zd ZdZedd            ZddZe	 	 ddd            ZdS )r   a  
    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`.
    documentr
   r   r   c                    dS )z
        Validate the input.
        If invalid, this should raise a :class:`.ValidationError`.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        N r   r.   s     r!   validatezValidator.validate8   s	     	r"   c                T   K   	 |                      |           dS # t          $ r  w xY w)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)r2   r   r1   s     r!   validate_asynczValidator.validate_asyncB   sA      	MM(##### 	 	 		s    'Invalid inputFvalidate_funcCallable[[str], bool]error_messager   move_cursor_to_endboolc                $    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)clsr6   r8   r9   s       r!   from_callablezValidator.from_callableM   s    , &m]DVWWWr"   Nr.   r
   r   r   )r5   F)r6   r7   r8   r   r9   r:   r   r   )	r%   r)   r*   r+   r   r2   r4   classmethodr>   r0   r"   r!   r   r   +   s        
 
    ^	 	 	 	  -#(	X X X X [X X Xr"   r   )	metaclassc                  *    e Zd ZdZdd
ZddZddZdS )r<   z0
    Validate input from a simple callable.
    funcr7   r8   r   r9   r:   r   r   c                0    || _         || _        || _        d S r   )rC   r8   r9   )r   rC   r8   r9   s       r!   r   z_ValidatorFromCallable.__init__k   s!     	*"4r"   c                    d| j         dS )NzValidator.from_callable(r$   )rC   r&   s    r!   r'   z_ValidatorFromCallable.__repr__r   s    8$)8888r"   r.   r
   c                    |                      |j                  s4| j        rt          |j                  }nd}t	          || j                  d S )Nr   )r   r   )rC   textr9   lenr   r8   )r   r.   indexs      r!   r2   z_ValidatorFromCallable.validateu   s\    yy'' 	U& HM**!%ASTTTT	U 	Ur"   N)rC   r7   r8   r   r9   r:   r   r   r(   r?   )r%   r)   r*   r+   r   r'   r2   r0   r"   r!   r<   r<   f   s`         5 5 5 59 9 9 9U U U U U Ur"   r<   c                  *    e Zd ZdZddZdd	Zdd
ZdS )r   z
    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.)
    	validatorr   r   r   c                    || _         d S r   )rK   )r   rK   s     r!   r   zThreadedValidator.__init__   s    "r"   r.   r
   c                :    | j                             |           d S r   )rK   r2   r1   s     r!   r2   zThreadedValidator.validate   s    )))))r"   c                F    K   d fd}t          |           d{V  dS )z:
        Run the `validate` function in a thread.
        r   r   c                 .                                    S r   )r2   )r.   r   s   r!   run_validation_threadz?ThreadedValidator.validate_async.<locals>.run_validation_thread   s    ==***r"   N)r   r   r   )r   r.   rP   s   `` r!   r4   z ThreadedValidator.validate_async   sT      
	+ 	+ 	+ 	+ 	+ 	+ 	+ ++@AAAAAAAAAAAr"   N)rK   r   r   r   r?   r%   r)   r*   r+   r   r2   r4   r0   r"   r!   r   r      s`         # # # #* * * *B B B B B Br"   r   c                      e Zd ZdZddZdS )	r   z1
    Validator class that accepts any input.
    r.   r
   r   r   c                    d S r   r0   r1   s     r!   r2   zDummyValidator.validate   s    r"   Nr?   )r%   r)   r*   r+   r2   r0   r"   r!   r   r      s2              r"   r   c                  "    e Zd ZdZddZddZdS )r   zq
    Validator that can be switched on/off according to
    a filter. (This wraps around another validator.)
    rK   r   filterr   r   r   c                <    || _         t          |          | _        d S r   )rK   r   rU   )r   rK   rU   s      r!   r   zConditionalValidator.__init__   s    "''r"   r.   r
   c                f    |                                  r| j                            |           d S d S r   )rU   rK   r2   r1   s     r!   r2   zConditionalValidator.validate   s8    ;;== 	.N##H-----	. 	.r"   N)rK   r   rU   r   r   r   r?   )r%   r)   r*   r+   r   r2   r0   r"   r!   r   r      sF         
( ( ( (. . . . . .r"   r   c                  *    e Zd ZdZddZdd	Zdd
ZdS )r   z
    Validator class that can dynamically returns any Validator.

    :param get_validator: Callable that returns a :class:`.Validator` instance.
    get_validatorCallable[[], Validator | None]r   r   c                    || _         d S r   )rY   )r   rY   s     r!   r   zDynamicValidator.__init__   s    *r"   r.   r
   c                t    |                                  pt                      }|                    |           d S r   )rY   r   r2   r   r.   rK   s      r!   r2   zDynamicValidator.validate   s8    &&((<N,<,<	8$$$$$r"   c                   K   |                                  pt                      }|                    |           d {V  d S r   )rY   r   r4   r]   s      r!   r4   zDynamicValidator.validate_async   sN      &&((<N,<,<	&&x00000000000r"   N)rY   rZ   r   r   r?   rQ   r0   r"   r!   r   r      sZ         + + + +% % % %1 1 1 1 1 1r"   r   N)r+   
__future__r   abcr   r   typingr   prompt_toolkit.eventloopr   r.   r
   filtersr   r   __all__	Exceptionr   r   r<   r   r   r   r   r0   r"   r!   <module>rf      s   
 # " " " " " ' ' ' ' ' ' ' '       A A A A A A       , , , , , , , ,  p p p p pi p p p"8X 8X 8X 8X 8X' 8X 8X 8X 8XvU U U U UY U U U2B B B B B	 B B B0    Y   . . . . .9 . . . 1 1 1 1 1y 1 1 1 1 1r"   