o
    @j@                     @  s  U d dl mZ d dlmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
mZmZ d dlmZmZmZmZ d dlmZ dd	lmZ dd
lmZ e	rMddlmZ dhZdhZddhZh dZdheZdhZh eedddddZ h eeZ!h eeeZ"h eeeZ#h eeeZ$h eeZ%h eeZ&h eeZ'h eeeZ(ddhe(Z)h eeeZ*eZ+eZ,h eeZ-h eeZ.h eeZ/eZ0eZ1eZ2dhZ3h dZ4dZ5ddd d!d"ge5R Z6d#Z7ee8Z9d$e:d%< e e5fe!d&fe"d'fe#d(fe$d)fe%d*fe&d+fe(d,fe*d-fe-d.feg e5e6e7d/d0R fe3d1fe4d2fe+d3fe,d4fe0d5fe1d6fe)d7fe2d8fgZ;d9e:d:< e;D ]\Z<Z=e<D ]
Z>e9e> ?e= qDq>d_dAdBZ@d`dEdFZAdadIdJZBedbdLdMZCdcdRdSZDdddUdVZEded\d]ZFd^S )f    )annotations)defaultdict)copy)	lru_cachepartial)TYPE_CHECKINGAnyCallableIterable)
CoreSchemaPydanticCustomErrorValidationErrorto_jsonable_python)core_schema   )PydanticMetadata)import_cached_field_info   )GetJsonSchemaHandlerstrict	fail_fast
min_length
max_length>   gegtleltmultiple_ofallow_inf_nanstrip_whitespaceto_lowerto_upperpatterncoerce_numbers_to_str
max_digitsdecimal_places
union_mode>   r   default_hostdefault_pathdefault_porthost_requiredallowed_schemes)strbytesurlmulti-host-urllisttupleset	frozenset	generator)floatintdatetime	timedeltadatetimezdict[str, set[str]]CONSTRAINTS_TO_ALLOWED_SCHEMAS)r-   )r0   )r1   )r2   r3   )dict)r4   )r5   )r6   )r7   r8   r:   r9   z
typed-dictmodel)union)r.   r/   )bool)uuid)zlax-or-strict)enum)decimal)complexz&list[tuple[set[str], tuple[str, ...]]]constraint_schema_pairingsscs.CoreSchemafCallable[[], dict[str, Any]]returnNonec                   sX   d fdd}d	| v r#| d	 }d
| v r|d
  | d S |g|d
< d S d
|gi| d	< d S )NrE   rF   handlerr   rI   dict[str, Any]c                   s   || }|    |S N)update)rE   rK   	js_schemarG    {/var/www/www-root/data/www/ai-bot.pdev.uz/venv/lib/python3.10/site-packages/pydantic/_internal/_known_annotated_metadata.pyupdate_js_schemad   s   z.add_js_update_schema.<locals>.update_js_schemametadatapydantic_js_functions)rE   rF   rK   r   rI   rL   )append)rE   rG   rS   rT   rQ   rP   rR   add_js_update_schemac   s   rW   vr   c                 C  s(   t | tttttt d fvrt| S | S rM   )typer6   r,   r5   r-   r?   r   )rX   rQ   rQ   rR   as_jsonable_values   s   rZ   r   Iterable[Any]c                 c  sh    ddl }t }| D ]'}t||jr|E dH  q
t||r.|jE dH  t|}g |_|V  q
|V  q
dS )a  Expand the annotations.

    Args:
        annotations: An iterable of annotations.

    Returns:
        An iterable of expanded annotations.

    Example:
        ```py
        from annotated_types import Ge, Len

        from pydantic._internal._known_annotated_metadata import expand_grouped_metadata

        print(list(expand_grouped_metadata([Ge(4), Len(5)])))
        #> [Ge(ge=4), MinLen(min_length=5)]
        ```
    r   N)annotated_typesr   
isinstanceGroupedMetadatarT   r   )r   at	FieldInfo
annotationrQ   rQ   rR   expand_grouped_metadatay   s   
rb   dict[type, str]c                  C  s6   ddl } | jd| jd| jd| jd| jd| jd| jd	iS )
a  Return a mapping of annotated types to constraints.

    Normally, we would define a mapping like this in the module scope, but we can't do that
    because we don't permit module level imports of `annotated_types`, in an attempt to speed up
    the import time of `pydantic`. We still only want to have this dictionary defined in one place,
    so we use this function to cache the result.
    r   Nr   r   r   r   r   r   r   )r\   GtGeLtLe
MultipleOfMinLenMaxLen)r_   rQ   rQ   rR   _get_at_to_constraint_map   s   	rk   ra   schemar   CoreSchema | Nonec                   s  ddl ddlm}m} | }t g\}}|d h d}g }| D ]\tvr4td t }dv rMd	krMt	 |d
 |d
< |  S |v rcdkr^dkr^|d< n|< q%|v rd*fdd}	|
t|	tjd+i i q%h ttv rtv rn;tv r|}
|
d dv r|
d
 }
|
d dv s|
d }|dks|dkr|
d d dkrÈdkrdndndkrdndtt|fi di|}t|fdd q%d krd!u rt||}q%td" d# d$|D ]O t  }t  }v r&|| tt|t i|}qt jjfrOt jd%r< jj nd&d, fd(d)}t||}q dS |r_|g| }t|S |S )-a{  Apply `annotation` to `schema` if it is an annotation we know about (Gt, Le, etc.).
    Otherwise return `None`.

    This does not handle all known annotations. If / when it does, it can always
    return a CoreSchema and return the unmodified schema if the annotation should be ignored.

    Assumes that GroupedMetadata has already been expanded via `expand_grouped_metadata`.

    Args:
        annotation: The annotation.
        schema: The schema.

    Returns:
        An updated schema with annotation if it is an annotation we know about, `None` otherwise.

    Raises:
        PydanticCustomError: If `Predicate` fails.
    r   Nr   )forbid_inf_nan_checkget_constraint_validatorrY   >   r"   r    r!   r   r#   zUnknown constraint >   function-wrapfunction-afterfunction-beforer   rl   r&   r>   modevaluer   rK   cs.ValidatorFunctionWrapHandlerrI   c                   s\   z|| }W |S  t y- } zd| d d v r'td  d|  d d|d }~ww )NrY   r   Unable to apply constraint 'z' to supplied value z for schema of type '')r   errors	TypeError)rt   rK   xve)
constraintschema_typerQ   rR   +_apply_constraint_with_incompatibility_info   s   
zIapply_known_metadata.<locals>._apply_constraint_with_incompatibility_infor0   zjson-or-pythonjson_schemar   minItemsmaxItems	minLength	maxLengthconstraint_valuec                     s    t iS rM   )rZ   rQ   )json_schema_constraintrt   rQ   rR   <lambda>  s    z&apply_known_metadata.<locals>.<lambda>r   Frv   z' to schema of type 'rw   __qualname__ rX   c                   sJ     | }t jr|stdd d| S |r#tdd d| S )Npredicate_failedz
Predicate z failednot_operation_failedzNot of )funcr]   	Predicater   )rX   predicate_satisfied)ra   r_   predicate_namerQ   rR   val_func1  s   


z&apply_known_metadata.<locals>.val_func)rt   r   rK   ru   rI   r   rQ   rX   r   rI   r   )r\   _validatorsrn   ro   r   collect_known_metadataitemsr;   
ValueErrorapply_known_metadatarV   csno_info_wrap_validator_function
str_schemaNUMERIC_CONSTRAINTSLENGTH_CONSTRAINTS no_info_after_validator_functionr   rW   RuntimeErrorrY   rk   getattrr]   r   Nothasattrr   r   chain_schema)ra   rl   rn   ro   schema_updateother_metadatachain_schema_constraintschain_schema_stepsallowed_schemasr~   inner_schemainner_schema_typeannotation_typeat_to_constraint_mapr   rQ   )ra   r_   r|   r   r   r}   rt   rR   r      s   


r    tuple[dict[str, Any], list[Any]]c                 C  s   t | } i }g }| D ]C}t|tr||j q
t| }t  }v r/|| }t||||< q
t|trHt|trH|dd t	|
 D  q
|| q
dd |
 D }||fS )a  Split `annotations` into known metadata and unknown annotations.

    Args:
        annotations: An iterable of annotations.

    Returns:
        A tuple contains a dict of known metadata and a list of unknown annotations.

    Example:
        ```py
        from annotated_types import Gt, Len

        from pydantic._internal._known_annotated_metadata import collect_known_metadata

        print(collect_known_metadata([Gt(1), Len(42), ...]))
        #> ({'gt': 1, 'min_length': 42}, [Ellipsis])
        ```
    c                 S  s    i | ]\}}| d s||qS )_)
startswith.0krX   rQ   rQ   rR   
<dictcomp>s  s     z*collect_known_metadata.<locals>.<dictcomp>c                 S  s   i | ]\}}|d ur||qS rM   rQ   r   rQ   rQ   rR   r   y  s    )rb   r]   r   rN   __dict__rY   rk   r   
issubclassvarsr   rV   )r   res	remainingra   r   r   r|   rQ   rQ   rR   r   P  s   
r   rT   rL   allowedIterable[str]source_typec                 C  s<   |   t| }|rtd|dddd |D  dS )a  A small utility function to validate that the given metadata can be applied to the target.
    More than saving lines of code, this gives us a consistent error message for all of our internal implementations.

    Args:
        metadata: A dict of metadata.
        allowed: An iterable of allowed metadata.
        source_type: The source type.

    Raises:
        TypeError: If there is metadatas that can't be applied on source type.
    z/The following constraints cannot be applied to z: z, c                 S  s   g | ]}|qS rQ   rQ   )r   r   rQ   rQ   rR   
<listcomp>  s    z"check_metadata.<locals>.<listcomp>N)keysr2   ry   join)rT   r   r   unknownrQ   rQ   rR   check_metadata}  s   r   N)rE   rF   rG   rH   rI   rJ   r   )r   r[   rI   r[   )rI   rc   )ra   r   rl   r   rI   rm   )r   r[   rI   r   )rT   rL   r   r   r   r   rI   rJ   )G
__future__r   collectionsr   r   	functoolsr   r   typingr   r   r	   r
   pydantic_corer   r   r   r   r   r   _fieldsr   _import_utilsr   annotated_handlersr   STRICT	FAIL_FASTr   
INEQUALITYr   ALLOW_INF_NANSTR_CONSTRAINTSBYTES_CONSTRAINTSLIST_CONSTRAINTSTUPLE_CONSTRAINTSSET_CONSTRAINTSDICT_CONSTRAINTSGENERATOR_CONSTRAINTSSEQUENCE_CONSTRAINTSFLOAT_CONSTRAINTSDECIMAL_CONSTRAINTSINT_CONSTRAINTSBOOL_CONSTRAINTSUUID_CONSTRAINTSDATE_TIME_CONSTRAINTSTIMEDELTA_CONSTRAINTSTIME_CONSTRAINTSLAX_OR_STRICT_CONSTRAINTSENUM_CONSTRAINTSCOMPLEX_CONSTRAINTSUNION_CONSTRAINTSURL_CONSTRAINTSTEXT_SCHEMA_TYPESSEQUENCE_SCHEMA_TYPESNUMERIC_SCHEMA_TYPESr2   r;   __annotations__rD   constraintsschemascrN   rW   rZ   rb   rk   r   r   r   rQ   rQ   rQ   rR   <module>   s    
		


(
 
-