
    f                        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y)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.
    c                @    t         |   |       || _        || _        y N)super__init__cursor_positionmessage)selfr   r   	__class__s      T/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/validation.pyr   zValidationError.__init__"   s    !.    c                h    | j                   j                   d| j                  d| j                  dS )Nz(cursor_position=z
, message=))r   __name__r   r   r   s    r   __repr__zValidationError.__repr__'   s8    ..))**;D<P<P;SS]^b^j^j]mmnoor   )r    )r   intr   strreturnNoner&   r%   )r    
__module____qualname____doc__r   r"   __classcell__)r   s   @r   r   r      s    
pr   r   c                  P    e Zd ZdZedd       ZddZe	 	 d	 	 	 	 	 	 	 dd       Zy)	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`.
    c                     y)z
        Validate the input.
        If invalid, this should raise a :class:`.ValidationError`.

        :param document: :class:`~prompt_toolkit.document.Document` instance.
        N r   documents     r   validatezValidator.validate8   s     	r   c                L   K   	 | j                  |       y# t        $ r  w xY w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   r0   s     r   validate_asynczValidator.validate_asyncB   s(     	MM(# 		s   $ $!$c                    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)clsvalidate_funcerror_messagemove_cursor_to_ends       r   from_callablezValidator.from_callableM   s    , &m]DVWWr   Nr1   r
   r&   r'   )zInvalid inputF)r8   Callable[[str], bool]r9   r%   r:   boolr&   r   )	r    r)   r*   r+   r   r2   r4   classmethodr;   r/   r   r   r   r   +   sh    
  	  -#(	X,X X !	X
 
X Xr   r   )	metaclassc                  8    e Zd ZdZ	 	 	 	 	 	 	 	 ddZddZddZy)	r6   z0
    Validate input from a simple callable.
    c                .    || _         || _        || _        y r   )funcr9   r:   )r   rC   r9   r:   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    )$))a88r   c                    | j                  |j                        s;| j                  rt        |j                        }nd}t	        || j
                        y )Nr   )r   r   )rC   textr:   lenr   r9   )r   r1   indexs      r   r2   z_ValidatorFromCallable.validateu   sF    yy'&&HMM*!%ASASTT (r   N)rC   r=   r9   r%   r:   r>   r&   r'   r(   r<   )r    r)   r*   r+   r   r"   r2   r/   r   r   r6   r6   f   s7    5)5:=5SW5	59Ur   r6   c                  (    e Zd ZdZddZddZddZy)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.)
    c                    || _         y r   )	validator)r   rK   s     r   r   zThreadedValidator.__init__   s	    "r   c                :    | j                   j                  |       y r   )rK   r2   r0   s     r   r2   zThreadedValidator.validate   s    )r   c                H    K   d fd}t        |       d{    y7 w)z:
        Run the `validate` function in a thread.
        c                 &    j                         S r   )r2   )r1   r   s   r   run_validation_threadz?ThreadedValidator.validate_async.<locals>.run_validation_thread   s    ==**r   N)r&   r'   r   )r   r1   rO   s   `` r   r4   z ThreadedValidator.validate_async   s     
	+ ++@AAAs   " "N)rK   r   r&   r'   r<   r    r)   r*   r+   r   r2   r4   r/   r   r   r   r      s    #*Br   r   c                      e Zd ZdZddZy)r   z1
    Validator class that accepts any input.
    c                     y r   r/   r0   s     r   r2   zDummyValidator.validate   s    r   Nr<   )r    r)   r*   r+   r2   r/   r   r   r   r      s    r   r   c                       e Zd ZdZddZddZy)r   zq
    Validator that can be switched on/off according to
    a filter. (This wraps around another validator.)
    c                2    || _         t        |      | _        y r   )rK   r   filter)r   rK   rU   s      r   r   zConditionalValidator.__init__   s    "'r   c                \    | j                         r| j                  j                  |       y y r   )rU   rK   r2   r0   s     r   r2   zConditionalValidator.validate   s"    ;;=NN##H- r   N)rK   r   rU   r   r&   r'   r<   )r    r)   r*   r+   r   r2   r/   r   r   r   r      s    
(.r   r   c                  (    e Zd ZdZddZddZddZy)r   z
    Validator class that can dynamically returns any Validator.

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