ó
    NÎ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      €ÚV/home/mande/repo/quber/.venv/lib/python3.13/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Ñ;SÐS]Ð^b×^jÑ^jÑ]mÐmnÐ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'   é € ð	Ø�M‰M˜(Õ#øÜó 	Øð	ü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   € ô, & mÐDVÓ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   € Ø�y‰y˜Ÿ™×'Ñ'Ø×&×&Ü˜HŸM™MÓ*‘à�ä!°%×ASÑASÑ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Ø:=ð5ØSWð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ÓAùs   „$œ"�$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$   € à�;‰;�=‰=Ø�N‰N×#Ñ# 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Ó0ùs   ‚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ô .ô 1�yõ 1r   