HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/primordial/__pycache__/validator.cpython-39.pyc
a

�,�hL$�@s�ddlZddlZddlmZmZddlmZmZmZmZm	Z	m
Z
mZddlm
Z
ddlmZmZmZddlmZe
eeeefZeeefZGdd�de�Zd*eeeed
�dd�Zd+eeeed
�dd�Zee��Zeed�dd�Zeed�dd�Zeed�dd�Zeed�dd�Z eed�dd�Z!e�"d�Z#eed�dd�Z$d,e	ee	eee	ed�dd �Z%d-eeefeeefeeeefd!�d"d#�Z&d.e
e	ee
eeefeed$�d%d&�Z'eed'�d(d)�Z(dS)/�N)�datetime�	timedelta)�Any�Callable�Dict�Iterable�List�Optional�Union)�UUID)�Schema�Url�MultipleInvalid)�CANONICAL_TIMESTRING_FORMATc@seZdZdZdS)�BadParameterExceptionz/To be raised when a validation operation fails.N)�__name__�
__module__�__qualname__�__doc__�rr�E/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/primordial/validator.pyrsrF)�	validator�param_value�coerce_�returnc
Csrt|�rbz||�}Wn6tyJ}ztd||f�|�WYd}~n
d}~00|durZ|}n|}|Std|��dS)a�Run a validation operation.

    Validate a particular parameter with a particular validator and possibly coerce the value into the validator's
    return type.

    :param validator: The validator to be run
    :param param_value: The value to be validated
    :param coerce_: Whether to return a type coerced value
    :raises ValueError: If the parameter could not be validated.
    z#Parameter %s failed validation (%s)NTz6Cannot use a non-callable as a parameter validator: %s)�callable�	Exceptionr�
ValueError)rrr�myval�e�retrrr�validates(r!)�param_validatorrrrcCs�|dur�t|t�r�|D]Z}|dur2|dur2|Szt|||d�}|WStyn}zWYd}~qd}~00qtd||f��t|||d�S|S)aValidate a parameter.

    :param param_validator: The validator (or list of validators) to be run
    :param param_value: The value to be validated
    :param coerce_: Whether to return a type coerced value
    :raises ValueError: If the parameter could not be validated.
    N�rz&No validator in list validated %s (%s))�
isinstancerr!rr)r"rrr�retval�_rrr�validate_param1s

r')�valrc
CsHzt|�Wn6tyB}ztd||f�|�WYd}~n
d}~00|S)aValidate that a string looks like a URL.

    url is intended to be used like str or int to be a basic callable that will except on type mismatch or non-
    coercible value.

    :param val: The value to be checked
    :raises ValueError: If the value does not look like a URL.
    zNot a url: %s (%s)N)�
URL_SCHEMArr)r(rrrr�urlUs

(r*cCs,zt�|t�}WdSty&YdS0dS)z�Validate that we can parse a datetime from a string.

    Catch exception and return false if strptime doesn't work.

    :param val: The value to be checked
    TFN)r�strptimerr)r(r&rrr�parseable_datetimehs
r,cCs&t|t�st|�r|Std|��dS)z�Validate that a value represents a datetime.

    :param val: The value to be checked
    :raises ValueError: If the value does not represent a datetime.
    zNot a datetime: %sN)r$rr,r�r(rrr�is_datetimevsr.cCst|t�r|Std|��dS)z�Validate that a value is a timedelta.

    :param val: The value to be checked
    :raises ValueError: If the value is not a timedelta.
    zNot a timedelta: %sN)r$rrr-rrr�is_timedelta�s
r/cCs&t|t�r|ikr|Std|��dS)z�Validate that a value is a non-empty dictionary.

    :param val: The value to be checked
    :raises ValueError: If the value is not a dictionary, or is empty.
    zNot a non-empty dict: %sN)r$�dictrr-rrr�is_non_empty_dict�sr1z^[a-z_][a-z0-9_]*$cCs$t�|�r|Stdtj|f��dS)z�Validate that argument is a valid Postgres identifier.

    :param val: The value to be checked
    :raises ValueError: If the value is not a valid Postgres identifier.
    z"Not a valid Postgres name (%s): %sN)�POSTGRES_NAME_REGEX�matchr�patternr-rrr�is_postgres_name�s

�r5)�positional_args�positional_arg_valuesrrc	Csvg}t|�D]d\}}z||}Wn(tyH}zd}WYd}~n
d}~00|durbt|||d�}n|}|�|�q|S)azValidate a list of positional arguments.

    If we run out of stated positionals, we simply dump the originals unvalidated (we're saying the validators are
    optional)

    :param positional_args: The validators to be run, in order, against the values
    :param positional_arg_values: The values to be validated
    :param coerce_: Whether to return type coerced values
    Nr#)�	enumerate�
IndexErrorr'�append)	r6r7r�outargs�indexZmyvaluerr&rrrr�internal_validate_positionals�sr=)�keyword_args�keyword_arg_valuesrrc	Csti}|��D]b\}}z||}Wn(tyH}zd}WYd}~n
d}~00|durbt|||d�}n|}|||<q|S)arValidate a dictionary of keyword arguments.

    If there is no matching validator for a particular keyword, then the original value is passed along in the output
    unvalidated.

    :param keyword_args: The validators to be run against the values
    :param keyword_arg_values: The values to be validated
    :param coerce_: Whether to return type coerced values
    Nr#)�items�KeyErrorr')	r>r?rZoutdict�key�valuerr&rrrr�internal_validate_keywords�s
rD)�positionals�keywordsrrcs���fdd�}|S)a>Either coerce the arguments in the suggested way or die with error back to the client.

    :param positionals: A list of validators to be run against positional arguments
    :param keywords: A dictionary of validators to be run against keyword arguments
    :param coerce_: Whether to return type coerced values
    cs t�������fdd��}|S)ZInnerc
s�z<�durt�|�d�}n|}�dur6t�|�d�}n|}Wn>tyz}z&tdt|�t|�f�|�WYd}~n
d}~00�|i|��S)zActual wrapperNr#zFailed to validate: %s, %s)r=rDrr�str)�args�kwargsr;Z	outkwargsr)r�functionrFrErr�wrapper�s0z3coerce_or_error.<locals>.decorator.<locals>.wrapper)�	functools�wraps)rJrK�rrFrE)rJr�	decorator�sz"coerce_or_error.<locals>.decoratorr)rErFrrOrrNr�coerce_or_error�s
rP)�
uuid_maybercCs(zt|�WdSty"YdS0dS)z]Validate that a value represents a UUID.

    :param uuid_maybe: The value to be checked
    TFN)rr)rQrrr�is_uuid�s
rR)F)F)F)F)NNF))rL�rerr�typingrrrrrr	r
�uuidrZ
voluptuousrr
rZprimordial.constantsrZ
ValidatorTyperGZDateTimeTyperr�boolr!r'r)r*r,r.r/r1�compiler2r5r=rDrPrRrrrr�<module>sL$!

���
��
�