| Server IP : 3.96.16.70 / Your IP : 216.73.216.15 Web Server : Apache System : Linux ip-172-31-26-103.ca-central-1.compute.internal 6.1.163-186.299.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Feb 24 16:35:42 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python3.9/site-packages/prompt_toolkit/__pycache__/ |
Upload File : |
a
�a^� � @ s� d Z ddlmZmZ ddlmZmZ ddlmZ ddl m
Z
ddlmZm
Z
g d�ZG d d
� d
e�ZG dd� ded
�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZdS )zV
Input validation for a `Buffer`.
(Validators will be called before accepting input.)
� )�ABCMeta�abstractmethod)�Callable�Optional��run_in_executor_with_context� )�Document)�FilterOrBool� to_filter)�ConditionalValidator�ValidationError� Validator�ThreadedValidator�DummyValidator�DynamicValidatorc s: e Zd ZdZdeedd�� fdd�
Zed�d d
�Z� ZS )r
z�
Error raised by :meth:`.Validator.validate`.
:param cursor_position: The cursor position where the error occurred.
:param message: Text.
r � N)�cursor_position�message�returnc s t � �|� || _|| _d S �N)�super�__init__r r )�selfr r �� __class__� �=/usr/lib/python3.9/site-packages/prompt_toolkit/validation.pyr s zValidationError.__init__�r c C s d| j j| j| jf S )Nz"%s(cursor_position=%r, message=%r))r �__name__r r �r r r r �__repr__$ s
�zValidationError.__repr__)r r ) r �
__module__�__qualname__�__doc__�int�strr r! �
__classcell__r r r r r
s r
c @ sX e Zd ZdZeedd�dd��Zedd�dd�Zed
e e
gef e
ed d
�dd��ZdS )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`.
N��documentr c C s dS )z�
Validate the input.
If invalid, this should raise a :class:`.ValidationError`.
:param document: :class:`~prompt_toolkit.document.Document` instance.
Nr �r r) r r r �validate9 s zValidator.validatec � s( z| � |� W n ty" � Y n0 dS )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)r+ r
r* r r r �validate_asyncC s zValidator.validate_async�
Invalid inputF)�
validate_func�
error_message�move_cursor_to_endr c C s 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)�clsr. r/ r0 r r r �
from_callableN s zValidator.from_callable)r- F)
r r"