a
    Ofm7                     @  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 d dlmZ dd	lmZ e	rd
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Z-eZ.dhZ/h dZ0dZ1dddd d!ge1R Z2d"Z3ee4Z5d#e6d$< ee1f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+d.fe,d/feg e1e2e3d0d1R fe/d2fe0d3fe(d4fe)d5fe-d6fe.d7fe&d8fgZ7d9e6d:< e7D ]$\Z8Z9e8D ]Z:e5e: ;e9 qzqnd;d<d=d>d?d@Z<dAdAdBdCdDZ=dEdEdFdGdHZ>edIdJdKdLZ?dAdMdNdOdPdQZ@dEdRdFdSdTZAdUdVdAd=dWdXdYZBdZS )[    )annotations)defaultdict)copy)	lru_cachepartial)TYPE_CHECKINGAnyCallableIterable)
CoreSchemaPydanticCustomErrorto_jsonable_python)core_schema   )PydanticMetadata   )GetJsonSchemaHandlerstrictZ	fail_fast
min_length
max_length>   gtgeleltmultiple_ofallow_inf_nanstrip_whitespaceto_lowerto_upperpatterncoerce_numbers_to_strZ
max_digitsZdecimal_places
union_mode>   Zdefault_hostdefault_portZdefault_pathZhost_requiredZallowed_schemesr   )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$   )r'   )r(   )r)   r*   )dict)r+   )r,   )r-   )r.   r/   r1   )r0   )r/   z
typed-dictmodel)union)r%   r&   )bool)uuid)zlax-or-strict)enum)decimalz&list[tuple[set[str], tuple[str, ...]]]constraint_schema_pairingscs.CoreSchemazCallable[[], dict[str, Any]]None)sfreturnc                   s\   dddd fdd}d| v rJ| d }d| v r>|d  | qX|g|d< nd|gi| d< d S )	Nr;   r   dict[str, Any])r=   handlerr?   c                   s   || }|    |S N)update)r=   rA   Z	js_schemar>    e/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pydantic/_internal/_known_annotated_metadata.pyupdate_js_schemac   s    z.add_js_update_schema.<locals>.update_js_schemametadataZpydantic_js_functions)append)r=   r>   rG   rH   rE   rD   rF   add_js_update_schemab   s    rJ   r   vr?   c                 C  s(   t | tttttt d fvr$t| S | S rB   )typer-   r#   r,   r$   r6   r   rL   rE   rE   rF   as_jsonable_valuer   s    rO   zIterable[Any])r   r?   c                 c  sl   ddl }ddlm} | D ]N}t||jr4|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)	FieldInfo)annotated_typesZpydantic.fieldsrP   
isinstanceZGroupedMetadatarH   r   )r   atrP   
annotationrE   rE   rF   expand_grouped_metadatax   s    
rU   zdict[type, str])r?   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   )rQ   GtZGeLtZLeZ
MultipleOfZMinLenZMaxLen)rS   rE   rE   rF   _get_at_to_constraint_map   s    	rX   r   zCoreSchema | None)rT   schemar?   c              	     s  ddl }ddlm}m} | }t g\}}|d }h d}g }	| D ]\}
|
tvrjtd|
 t|
 }|dv r|
d	krt	 |d
 |d
< |  S ||v r|
dkr|dkr|d< qJ||
< qJ|
|v r|	
tjf i |
i qJ|
h ttv r|
tv r|
n||
tv r|}|d dv r6|d
 }q|d }|dksd|dkrx|d d dkrx|
dkrrdndn|
dkrdndtt||
fi |
i|}t|fdd qJ|
dkrdu rt||}qJtd|
 d| qJ|D ] t  }t  }v rF|| }
tt||
|
t |
i|}qnXt |jrt jdrp jj dndddd  fd!d"}t||}n dS q|	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_validatorrM   >   r   r    r   r   r   zUnknown constraint >   zfunction-wrapzfunction-beforezfunction-afterr   rY   r!   r5   moder'   zjson-or-pythonZjson_schemar   ZminItemsZmaxItemsZ	minLengthZ	maxLengthc                     s    t iS rB   )rO   rE   )json_schema_constraintvaluerE   rF   <lambda>      z&apply_known_metadata.<locals>.<lambda>r   FzUnable to apply constraint z to schema __qualname__  r   rK   c                   s      | stdd d| S )NZpredicate_failedz
Predicate Zfailed)funcr   rN   )rT   predicate_namerE   rF   val_func  s    

z&apply_known_metadata.<locals>.val_func)rQ   Z_validatorsrZ   r[   r   collect_known_metadataitemsr2   
ValueErrorapply_known_metadatarI   csZ
str_schemaNUMERIC_CONSTRAINTSLENGTH_CONSTRAINTSZ no_info_after_validator_functionr   rJ   RuntimeErrorrM   rX   getattrrR   Z	Predicatehasattrrd   ra   Zchain_schema)rT   rY   rS   rZ   r[   Zschema_updateZother_metadataZschema_typeZchain_schema_constraintsZchain_schema_steps
constraintZallowed_schemasZinner_schemaZinner_schema_typeannotation_typeat_to_constraint_maprf   rE   )rT   r]   re   r^   rF   rj      s|    



 	


rj   z tuple[dict[str, Any], list[Any]]c                 C  s   t | } i }g }| D ]}t|tr0||j qt| }t  }v r^|| }t||||< qt|trt|tr|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krL   rE   rE   rF   
<dictcomp>M  r`   z*collect_known_metadata.<locals>.<dictcomp>c                 S  s   i | ]\}}|d ur||qS rB   rE   rv   rE   rE   rF   ry   S  r`   )rU   rR   r   rC   __dict__rM   rX   ro   
issubclassvarsrh   rI   )r   res	remainingrT   rr   rs   rq   rE   rE   rF   rg   *  s    
rg   r@   zIterable[str])rH   allowedsource_typer?   c                 C  s<   |   t| }|r8t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 rE   rE   )rw   rx   rE   rE   rF   
<listcomp>f  r`   z"check_metadata.<locals>.<listcomp>N)keysr)   	TypeErrorjoin)rH   r   r   unknownrE   rE   rF   check_metadataW  s
    r   N)C
__future__r   collectionsr   r   	functoolsr   r   typingr   r   r	   r
   Zpydantic_corer   r   r   r   rk   _fieldsr   Zannotated_handlersr   ZSTRICTZ	FAIL_FASTrm   Z
INEQUALITYrl   ZALLOW_INF_NANZSTR_CONSTRAINTSZBYTES_CONSTRAINTSZLIST_CONSTRAINTSZTUPLE_CONSTRAINTSZSET_CONSTRAINTSZDICT_CONSTRAINTSZGENERATOR_CONSTRAINTSZSEQUENCE_CONSTRAINTSZFLOAT_CONSTRAINTSZDECIMAL_CONSTRAINTSZINT_CONSTRAINTSZBOOL_CONSTRAINTSZUUID_CONSTRAINTSZDATE_TIME_CONSTRAINTSZTIMEDELTA_CONSTRAINTSZTIME_CONSTRAINTSZLAX_OR_STRICT_CONSTRAINTSZENUM_CONSTRAINTSZUNION_CONSTRAINTSZURL_CONSTRAINTSZTEXT_SCHEMA_TYPESZSEQUENCE_SCHEMA_TYPESZNUMERIC_SCHEMA_TYPESr)   r2   __annotations__r:   constraintsZschemascrC   rJ   rO   rU   rX   rj   rg   r   rE   rE   rE   rF   <module>   s   
		(t-