a
    “˜ëj¥A  ã                   @  s
  U d dl mZ 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 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r’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’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/eZ0dhZ1h d£Z2dZ3ddd d!d"ge3¢R Z4d#Z5ee6ƒZ7d$e8d%< ee3f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 e3¢e4¢e5¢d/‘d0‘R fe1d1fe2d2fe)d3fe*d4fe.d5fe/d6fe'd7fe0d8fgZ9d9e8d:< e9D ]$\Z:Z;e:D ]Z<e7e<  =e;¡ �q„�qxd;d;d<œd=d>„Z>d?d?d@œdAdB„Z?edCdDœdEdF„ƒZ@d;dGdHdIœdJdK„ZAd?dLd@œdMdN„ZBdOdPd;dQdRœdSdT„ZCdUS )Vé    )Úannotations)Údefaultdict)ÚIterable)Úcopy)Ú	lru_cacheÚpartial)ÚTYPE_CHECKINGÚAny)Ú
CoreSchemaÚPydanticCustomErrorÚValidationErrorÚto_jsonable_python)Úcore_schemaé   )ÚPydanticMetadata)Úimport_cached_field_infoÚstrictZ	fail_fastÚ
min_lengthÚ
max_length>   ÚgeÚleÚgtÚltÚmultiple_ofÚallow_inf_nanÚstrip_whitespaceÚto_lowerÚto_upperÚpatternÚcoerce_numbers_to_strÚ
ascii_onlyZ
max_digitsZdecimal_placesÚ
union_mode>   r   Zhost_requiredZdefault_pathZallowed_schemesZdefault_hostÚdefault_port)Ú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   z
typed-dictÚmodel)Úunion)r%   r&   )Úbool)Úuuid)zlax-or-strict)Úenum)Údecimal)Úcomplexz&list[tuple[set[str], tuple[str, ...]]]Úconstraint_schema_pairingsr	   ©ÚvÚreturnc                 C  s(   t | ƒtttttt d ƒfvr$t| ƒS | S ©N)Útyper-   r#   r,   r$   r6   r   )r=   © rA   úk/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pydantic/_internal/_known_annotated_metadata.pyÚas_jsonable_valuee   s    rC   zIterable[Any])r   r>   c                 c  sf   ddl }tƒ }| D ]N}t||jƒr.|E dH  qt||ƒrZ|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:
        ```python
        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   Ú
isinstanceZGroupedMetadataÚmetadatar   )r   ÚatZ	FieldInfoÚ
annotationrA   rA   rB   Úexpand_grouped_metadatak   s    
rI   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   )rD   ÚGtZGeÚLtZLeZ
MultipleOfZMinLenZMaxLen)rG   rA   rA   rB   Ú_get_at_to_constraint_map“   s    	ùrL   r
   zCoreSchema | None)rH   Úschemar>   c                   sZ  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rœt	ˆ |d
 ƒ|d
< |  S ˆ|
v rÈˆdkr¾ˆdkr¾|	|d< qJ|	|ˆ< qJˆ|v �rddddœ‡‡fdd„}| 
t |tjf i ˆ|	i¤Ž¡¡ qJˆ|v �rˆtv �r–|}|d dv �r@|d
 }�q&|d }|dk�sn|dk�r‚|d d dk�r‚ˆdk�r|dnd}nˆdk�r�dnd}nˆ}t t|ˆ fi ˆ|	i¤Ž|¡}| di ¡}| d¡ }du�rôi |¥|t|	ƒi¥|d< n|t|	ƒi|d< ||d< qJˆdk�r0|	du �r0t ||¡}qJtdˆ› d ˆ› d!�ƒ‚qJ|D ]î‰ tˆ ƒ }tƒ  }v �r´|| ‰| ˆ¡}|du �r’tdˆ› �ƒ‚t t|ˆtˆ ˆƒiƒ|¡}�qLn„tˆ |j|jfƒ�r2tˆ jd"ƒ�räˆ jj›d#�nd$‰tˆ |jƒ�rddd%œ‡ ‡fd&d'„}nddd%œ‡ ‡fd(d'„}t ||¡}n dS �qL|�rV|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:
        RuntimeError: If a constraint can't be applied to a specific schema type.
        ValueError: If an unknown constraint is encountered.
    r   Nr   )ÚNUMERIC_VALIDATOR_LOOKUPÚforbid_inf_nan_checkr@   >   r    r   r   r   r   r   zUnknown constraint >   zfunction-afterzfunction-beforezfunction-wrapr   rM   r!   r5   Úmoder	   zcs.ValidatorFunctionWrapHandler)ÚvalueÚhandlerr>   c                   sj   z|| ƒ}W nX t yd } z@d| ¡ d d v rLtdˆ › d| › dˆ› d�ƒ‚|‚W Y d }~n
d }~0 0 |S )Nr@   r   úUnable to apply constraint 'z' to supplied value z for schema of type 'ú')r   ÚerrorsÚ	TypeError)rQ   rR   ÚxÚve)Ú
constraintÚschema_typerA   rB   Ú+_apply_constraint_with_incompatibility_infoç   s    ÿzIapply_known_metadata.<locals>._apply_constraint_with_incompatibility_infor'   zjson-or-pythonZjson_schemar   ZminItemsZmaxItemsZ	minLengthZ	maxLengthrF   Zpydantic_js_updatesr   FrS   z' to schema of type 'rT   Ú__qualname__ú Ú r<   c                   s$   ˆ   | ¡}|s tddˆ› d�ƒ‚| S )NZpredicate_failedz
Predicate Úfailed©Úfuncr   ©r=   Zpredicate_satisfied©rH   Úpredicate_namerA   rB   Úval_func6  s    

þz&apply_known_metadata.<locals>.val_funcc                   s$   ˆ   | ¡}|r tddˆ› d�ƒ‚| S )NZnot_operation_failedzNot of r_   r`   rb   rc   rA   rB   re   A  s    

þ)rD   Z_validatorsrN   rO   r   Úcollect_known_metadataÚitemsr2   Ú
ValueErrorÚapply_known_metadataÚappendÚcsZno_info_wrap_validator_functionZ
str_schemaÚLENGTH_CONSTRAINTSZ no_info_after_validator_functionr   ÚgetrC   ÚRuntimeErrorr@   rL   ÚgetattrrE   Z	PredicateÚNotÚhasattrra   r\   Zchain_schema)rH   rM   rG   rN   rO   Zschema_updateZother_metadataZchain_schema_constraintsZchain_schema_stepsrQ   Zallowed_schemasr[   Zinner_schemaZinner_schema_typeZjs_constraint_keyrF   Zexisting_json_schema_updatesÚannotation_typeÚat_to_constraint_mapZ	validatorre   rA   )rH   rY   rd   rZ   rB   ri   ©   sž    

ÿÿ


ÿÿÿÿ
þ

þ

ÿ 	


ri   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ƒr�t|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:
        ```python
        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Úkr=   rA   rA   rB   Ú
<dictcomp>y  ó    z*collect_known_metadata.<locals>.<dictcomp>c                 S  s   i | ]\}}|d ur||“qS r?   rA   rv   rA   rA   rB   ry     rz   )rI   rE   r   ÚupdateÚ__dict__r@   rL   ro   Ú
issubclassÚvarsrg   rj   )r   ÚresÚ	remainingrH   rr   rs   rY   rA   rA   rB   rf   V  s    
rf   zdict[str, Any]zIterable[str]ÚNone)rF   Ú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 rA   rA   )rw   rx   rA   rA   rB   Ú
<listcomp>’  rz   z"check_metadata.<locals>.<listcomp>N)Úkeysr)   rV   Újoin)rF   r‚   rƒ   ÚunknownrA   rA   rB   Úcheck_metadataƒ  s
    ÿrˆ   N)DÚ
__future__r   Úcollectionsr   Úcollections.abcr   r   Ú	functoolsr   r   Útypingr   r	   Zpydantic_corer
   r   r   r   r   rk   Ú_fieldsr   Z_import_utilsr   ZSTRICTZ	FAIL_FASTrl   Z
INEQUALITYZNUMERIC_CONSTRAINTSZ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COMPLEX_CONSTRAINTSZUNION_CONSTRAINTSZURL_CONSTRAINTSZTEXT_SCHEMA_TYPESZSEQUENCE_SCHEMA_TYPESZNUMERIC_SCHEMA_TYPESr)   r2   Ú__annotations__r;   ÚconstraintsZschemasÚcr{   rC   rI   rL   ri   rf   rˆ   rA   rA   rA   rB   Ú<module>   s°   
ÿþýüûúùø
	ì( .-