
    h                        S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJrJr  / S	Qr " S
 S\5      r " S S\S9r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)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                  >   ^  \ rS rSrSrSSU 4S jjjrSS jrSrU =r$ )	r      z
Error raised by :meth:`.Validator.validate`.

:param cursor_position: The cursor position where the error occurred.
:param message: Text.
c                <   > [         TU ]  U5        Xl        X l        g N)super__init__cursor_positionmessage)selfr   r   	__class__s      lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\prompt_toolkit/validation.pyr   ValidationError.__init__"   s    !.    c                l    U R                   R                   SU R                  < SU R                  < S3$ )Nz(cursor_position=z
, message=))r   __name__r   r   r   s    r   __repr__ValidationError.__repr__'   s8    ..))**;D<P<P;SS]^b^j^j]mmnoor   r   r   )r    )r   intr   strreturnNoner*   r)   )	r"   
__module____qualname____firstlineno____doc__r   r$   __static_attributes____classcell__)r   s   @r   r   r      s     
p pr   r   c                  `    \ rS rSrSr\SS j5       rSS jr\  S	       S
S jj5       r	Sr
g)r   +   az  
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                    g)z
Validate the input.
If invalid, this should raise a :class:`.ValidationError`.

:param document: :class:`~prompt_toolkit.document.Document` instance.
N r   documents     r   validateValidator.validate8   s     	r   c                N   #     U R                  U5        g! [         a    e f = f7f)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)r9   r   r7   s     r   validate_asyncValidator.validate_asyncB   s'     	MM(# 		s   % %"%c                    [        XU5      $ )a  
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_callableValidator.from_callableM   s    , &mDVWWr   r6   Nr8   r
   r*   r+   )zInvalid inputF)rA   Callable[[str], bool]rB   r)   rC   boolr*   r   )r"   r-   r.   r/   r0   r   r9   r<   classmethodrD   r1   r6   r   r   r   r   +   sh    
  	  -#(	X,X X !	X
 
X Xr   r   )	metaclassc                  F    \ rS rSrSr        SS jrS	S jrS
S jrSrg)r?   f   z(
Validate input from a simple callable.
c                (    Xl         X l        X0l        g r   )funcrB   rC   )r   rN   rB   rC   s       r   r   _ValidatorFromCallable.__init__k   s     	*"4r   c                $    SU R                   < S3$ )NzValidator.from_callable(r!   )rN   r#   s    r   r$   _ValidatorFromCallable.__repr__r   s    )$))a88r   c                    U R                  UR                  5      (       d<  U R                  (       a  [        UR                  5      nOSn[	        X R
                  S9eg )Nr   r&   )rN   textrC   lenr   rB   )r   r8   indexs      r   r9   _ValidatorFromCallable.validateu   sG    yy''&&HMM*!%ASASTT (r   )rB   rN   rC   N)rN   rG   rB   r)   rC   rH   r*   r+   r,   rF   )	r"   r-   r.   r/   r0   r   r$   r9   r1   r6   r   r   r?   r?   f   s7    5)5:=5SW5	59Ur   r?   c                  6    \ rS rSrSrSS jrS	S jrS	S jrSrg)
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                    Xl         g r   	validator)r   r[   s     r   r   ThreadedValidator.__init__   s    "r   c                :    U R                   R                  U5        g r   )r[   r9   r7   s     r   r9   ThreadedValidator.validate   s    )r   c                L   ^ ^#    SUU 4S jjn[        U5      I Sh  vN   g N7f)z*
Run the `validate` function in a thread.
c                 &   > TR                  T 5      $ r   )r9   )r8   r   s   r   run_validation_thread?ThreadedValidator.validate_async.<locals>.run_validation_thread   s    ==**r   N)r*   r+   r   )r   r8   ra   s   `` r   r<    ThreadedValidator.validate_async   s!     
	+ 	+ ++@AAAs   $"$rZ   N)r[   r   r*   r+   rF   	r"   r-   r.   r/   r0   r   r9   r<   r1   r6   r   r   r   r      s    #*Br   r   c                  "    \ rS rSrSrSS jrSrg)r      z)
Validator class that accepts any input.
c                    g r   r6   r7   s     r   r9   DummyValidator.validate   s    r   r6   NrF   )r"   r-   r.   r/   r0   r9   r1   r6   r   r   r   r      s    r   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)	r      ze
Validator that can be switched on/off according to
a filter. (This wraps around another validator.)
c                0    Xl         [        U5      U l        g r   )r[   r   filter)r   r[   rl   s      r   r   ConditionalValidator.__init__   s    "'r   c                f    U R                  5       (       a  U R                  R                  U5        g g r   )rl   r[   r9   r7   s     r   r9   ConditionalValidator.validate   s$    ;;==NN##H- r   )rl   r[   N)r[   r   rl   r   r*   r+   rF   )r"   r-   r.   r/   r0   r   r9   r1   r6   r   r   r   r      s    
(.r   r   c                  6    \ rS rSrSrSS jrS	S jrS	S jrSrg)
r      z
Validator class that can dynamically returns any Validator.

:param get_validator: Callable that returns a :class:`.Validator` instance.
c                    Xl         g r   get_validator)r   rt   s     r   r   DynamicValidator.__init__   s    *r   c                h    U R                  5       =(       d
    [        5       nUR                  U5        g r   )rt   r   r9   r   r8   r[   s      r   r9   DynamicValidator.validate   s&    &&(<N,<	8$r   c                   #    U R                  5       =(       d
    [        5       nUR                  U5      I S h  vN   g  N7fr   )rt   r   r<   rw   s      r   r<   DynamicValidator.validate_async   s/     &&(<N,<	&&x000s   6A >A rs   N)rt   zCallable[[], Validator | None]r*   r+   rF   rd   r6   r   r   r   r      s    +%1r   r   N)r0   
__future__r   abcr   r   typingr   prompt_toolkit.eventloopr   r8   r
   filtersr   r   __all__	Exceptionr   r   r?   r   r   r   r   r6   r   r   <module>r      s   
 # '  A  ,pi p"8X' 8XvUY U2B	 B0Y .9 . 1y 1r   