
     h                    ,   d Z ddlmZ ddlmZmZ ddlmZ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Optional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      U/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/prompt_toolkit/validation.pyr   zValidationError.__init__!   s.    !!!.    c                X    d                     | j        j        | j        | j                  S )Nz&{}(cursor_position={!r}, message={!r}))formatr!   __name__r   r   r    s    r"   __repr__zValidationError.__repr__&   s-    7>>N# L
 
 	
r#   )r   r   )r   r   r   r   r   r   r   r   )r&   
__module____qualname____doc__r   r(   __classcell__)r!   s   @r"   r   r      s`               

 
 
 
 
 
 
 
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.validate;   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)r3   r   r2   s     r"   validate_asynczValidator.validate_asyncE   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)clsr7   r9   r:   s       r"   from_callablezValidator.from_callableP   s    , &m]DVWWWr#   Nr/   r   r   r   )r6   F)r7   r8   r9   r   r:   r;   r   r   )	r&   r*   r+   r,   r   r3   r5   classmethodr?   r1   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.
    funcr8   r9   r   r:   r;   r   r   c                0    || _         || _        || _        d S r   )rD   r9   r:   )r    rD   r9   r:   s       r"   r   z_ValidatorFromCallable.__init__n   s!     	*"4r#   c                    d| j         dS )NzValidator.from_callable())rD   r'   s    r"   r(   z_ValidatorFromCallable.__repr__u   s    8$)8888r#   r/   r   c                    |                      |j                  s4| j        rt          |j                  }nd}t	          || j                  d S )Nr   )r   r   )rD   textr:   lenr   r9   )r    r/   indexs      r"   r3   z_ValidatorFromCallable.validatex   s\    yy'' 	U& HM**!%ASTTTT	U 	Ur#   N)rD   r8   r9   r   r:   r;   r   r   r)   r@   )r&   r*   r+   r,   r   r(   r3   r1   r#   r"   r=   r=   i   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   )rM   )r    rM   s     r"   r   zThreadedValidator.__init__   s    "r#   r/   r   c                :    | j                             |           d S r   )rM   r3   r2   s     r"   r3   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   )r3   )r/   r    s   r"   run_validation_threadz?ThreadedValidator.validate_async.<locals>.run_validation_thread   s    ==***r#   N)r   r   r   )r    r/   rR   s   `` r"   r5   z ThreadedValidator.validate_async   sT      
	+ 	+ 	+ 	+ 	+ 	+ 	+ ++@AAAAAAAAAAAr#   N)rM   r   r   r   r@   r&   r*   r+   r,   r   r3   r5   r1   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   r1   r2   s     r"   r3   zDummyValidator.validate   s    r#   Nr@   )r&   r*   r+   r,   r3   r1   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.)
    rM   r   filterr   r   r   c                <    || _         t          |          | _        d S r   )rM   r   rW   )r    rM   rW   s      r"   r   zConditionalValidator.__init__   s    "''r#   r/   r   c                f    |                                  r| j                            |           d S d S r   )rW   rM   r3   r2   s     r"   r3   zConditionalValidator.validate   s8    ;;== 	.N##H-----	. 	.r#   N)rM   r   rW   r   r   r   r@   )r&   r*   r+   r,   r   r3   r1   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   )r[   )r    r[   s     r"   r   zDynamicValidator.__init__   s    *r#   r/   r   c                t    |                                  pt                      }|                    |           d S r   )r[   r   r3   r    r/   rM   s      r"   r3   zDynamicValidator.validate   s8    &&((<N,<,<	8$$$$$r#   c                   K   |                                  pt                      }|                    |           d {V  d S r   )r[   r   r5   r_   s      r"   r5   zDynamicValidator.validate_async   sN      &&((<N,<,<	&&x00000000000r#   N)r[   r\   r   r   r@   rS   r1   r#   r"   r   r      sZ         + + + +% % % %1 1 1 1 1 1r#   r   N)r,   
__future__r   abcr   r   typingr   r   prompt_toolkit.eventloopr	   r/   r   filtersr   r   __all__	Exceptionr   r   r=   r   r   r   r   r1   r#   r"   <module>rh      s    # " " " " " ' ' ' ' ' ' ' ' % % % % % % % % A A A A A A       , , , , , , , ,  
 
 
 
 
i 
 
 
*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#   