o
    h                      @   sR  U d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZ d dlmZ d dlZd dlmZmZmZmZmZmZmZmZ d dlmZmZ d dlmZmZ d dl m!Z! d d	l"m#Z# ergd
dl$m%Z% e Z&eee ee f e'd< dee(e)df de*fddZ+de)de
e) fddZ,deeedddfde)dee de	ee)ef  de	e dee*ef dee de	e! de	e) de#d defdd Z-dd!d"ed#e	eee ee f  defd$d%Z.de)de)d&e)de)fd'd(Z/d)d*de)fd+d,Z0d-eeef d.eeef ddfd/d0Z1d1eeef d2eeef deeef fd3d4Z2d5e)defd6d7Z3dS )8    N)is_dataclass)	TYPE_CHECKINGAnyDictMutableMappingOptionalSetTypeUnioncast)WeakKeyDictionary)PYDANTIC_V2
BaseConfig
ModelFieldPydanticSchemaGenerationError	UndefinedUndefinedType	Validatorlenient_issubclass)DefaultPlaceholderDefaultType)	BaseModelcreate_model)	FieldInfo)Literal   )APIRoute_CLONED_TYPES_CACHEstatus_codereturnc                 C   s2   | d u rdS | dv rdS t | }|dk p|dv  S )NT>   1XX2XX3XX4XX5XXdefault   >   0     )int)r   current_status_code r+   C/var/www/html/ai/venv/lib/python3.10/site-packages/fastapi/utils.pyis_body_allowed_for_status_code*   s   r-   pathc                 C   s   t td| S )Nz{(.*?)})setrefindall)r.   r+   r+   r,   get_path_param_names;   s   r2   
validationnametype_class_validatorsr%   requiredmodel_config
field_infoaliasmode)r3   serializationc	           
   	   C   s   |pi }t r|pt|||d}n|pt }| |d}	t r$|	d|i n|	||||||d ztdi |	W S  ttfyL   tjd| ddw )	zB
    Create a new response field. Raises if type_ is invalid.
    )
annotationr%   r:   )r4   r9   r;   )r5   r6   r%   r7   r8   r:   z2Invalid args for response field! Hint: check that aY   is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/Nr+   )	r   r   updater   RuntimeErrorr   fastapi
exceptionsFastAPIError)
r4   r5   r6   r%   r7   r8   r9   r:   r;   kwargsr+   r+   r,   create_response_field?   s:   


rD   cloned_typesfieldrF   c                   sV  t r| S  d u r
t | j}t|rt|dr|j}|}t|trMtt	t |} 
|}|d u rMt|j|d}| |< |j D ]}t| d|j|j< q@t| j|d}| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| jr fdd| jD |_| jrt| j d|_| j|_| j|_| j|_| j |_ | j!|_!|"  |S )N__pydantic_model__)__base__rE   )r4   r5   c                    s   g | ]}t | d qS )rE   )create_cloned_field).0	sub_fieldrE   r+   r,   
<listcomp>   s    
z'create_cloned_field.<locals>.<listcomp>)#r   r   r5   r   hasattrrH   r   r   r   r	   getr   __name__
__fields__valuesrJ   r4   rD   	has_aliasr:   r6   r%   r7   r8   r9   
allow_nonevalidate_always
sub_fields	key_field
validatorspre_validatorspost_validators
parse_jsonshapepopulate_validators)rG   rF   original_typeuse_typef	new_fieldr+   rE   r,   rJ   p   sX   


rJ   methodc                 C   s:   t jdtdd | | }tdd|}|d |  }|S )Nzrfastapi.utils.generate_operation_id_for_path() was deprecated, it is not used internally, and will be removed soon   )
stacklevel\W_)warningswarnDeprecationWarningr0   sublower)r4   r.   rb   operation_idr+   r+   r,   generate_operation_id_for_path   s   rm   router   c                 C   sB   | j | j }tdd|}| jsJ |d t| jd   }|S )Nre   rf   r   )r4   path_formatr0   rj   methodslistrk   )rn   rl   r+   r+   r,   generate_unique_id   s
   
rr   	main_dictupdate_dictc                 C   s   |  D ]=\}}|| v r t| | tr t|tr t| | | q|| v r=t| | tr=t|| tr=| | ||  | |< q|| |< qd S )N)items
isinstancedictdeep_dict_updaterq   )rs   rt   keyvaluer+   r+   r,   rx      s   
rx   
first_itemextra_itemsc                 G   s*   | f| }|D ]}t |ts|  S q| S )z
    Pass items or `DefaultPlaceholder`s by descending priority.

    The first one to _not_ be a `DefaultPlaceholder` will be returned.

    Otherwise, the first item (a `DefaultPlaceholder`) will be returned.
    )rv   r   )r{   r|   ru   itemr+   r+   r,   get_value_or_default   s   

r~   
error_typec                 C   s   ddl m} |d|  dS )Nr   )IsStrz$^https://errors\.pydantic\.dev/.*/v/)regex)dirty_equalsr   )r   r   r+   r+   r,   match_pydantic_error_url   s   r   )4r0   rg   dataclassesr   typingr   r   r   r   r   r   r	   r
   r   weakrefr   r@   fastapi._compatr   r   r   r   r   r   r   r   fastapi.datastructuresr   r   pydanticr   r   pydantic.fieldsr   typing_extensionsr   routingr   r   __annotations__r)   strboolr-   r2   rD   rJ   rm   rr   rx   r~   r   r+   r+   r+   r,   <module>   s   
 ,(

	

4
7
&



