o
     d                     @   sl  d dl Z d dlZd dlZd dlm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 d dlZd dlmZmZ d dlmZ d dlmZmZmZ d dlmZ d d	lmZmZmZ d d
l m!Z! d dl"m#Z# erlddl$m%Z% dee&e'df de(fddZ)deeee ee f  de
eee ee f e'f de
e'e	f fddZ*de'dee' fddZ+ddde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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/Z/d0e
e	e	f d1e
e	e	f ddfd2d3Z0d4eeef d5eeef deeef fd6d7Z1dS )8    N)is_dataclass)Enum)TYPE_CHECKINGAnyDictOptionalSetTypeUnioncast)DefaultPlaceholderDefaultType)
REF_PREFIX)
BaseConfig	BaseModelcreate_model)	Validator)	FieldInfo
ModelFieldUndefinedType)model_process_schema)lenient_issubclass   )APIRoute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'   8/usr/local/lib/python3.10/dist-packages/fastapi/utils.pyis_body_allowed_for_status_code   s   r)   flat_modelsmodel_name_mapc                 C   s^   i }| D ](}t ||td\}}}|| || }d|v r(|d dd |d< |||< q|S )N)r+   
ref_prefixdescriptionr   )r   r   updatesplit)r*   r+   definitionsmodelm_schemam_definitionsm_nested_models
model_namer'   r'   r(   get_model_definitions&   s   

r7   pathc                 C   s   t td| S )Nz{(.*?)})setrefindall)r8   r'   r'   r(   get_path_param_names8   s   r<   Tnametype_class_validatorsr!   requiredmodel_config
field_infoaliasc           	   
   C   s^   |pi }|pt  }tjt| ||||||d}z||dW S  ty.   tjd| ddw )zB
    Create a new response field. Raises if type_ is invalid.
    )r=   r>   r?   r!   r@   rA   rC   )rB   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/N)r   	functoolspartialr   RuntimeErrorfastapi
exceptionsFastAPIError)	r=   r>   r?   r!   r@   rA   rB   rC   response_fieldr'   r'   r(   create_response_field<   s.   
rK   cloned_typesfieldrM   c                   sN   d u ri  | j }t|rt|dr|j}|}t|trIttt |} |}|d u rIt	|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__rL   )r=   r>   c                    s   g | ]}t | d qS )rL   )create_cloned_field).0	sub_fieldrL   r'   r(   
<listcomp>   s    
z'create_cloned_field.<locals>.<listcomp>)!r>   r   hasattrrO   r   r   r   r	   getr   __name__
__fields__valuesrQ   r=   rK   	has_aliasrC   r?   r!   r@   rA   rB   
allow_nonevalidate_always
sub_fields	key_field
validatorspre_validatorspost_validators
parse_jsonshapepopulate_validators)rN   rM   original_typeuse_typef	new_fieldr'   rL   r(   rQ   e   sR   


rQ   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DeprecationWarningr:   sublower)r=   r8   ri   operation_idr'   r'   r(   generate_operation_id_for_path   s   rt   router   c                 C   sB   | j | j }tdd|}| jsJ |d t| jd   }|S )Nrl   rm   r   )r=   path_formatr:   rq   methodslistrr   )ru   rs   r'   r'   r(   generate_unique_id   s
   
ry   	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_updaterx   )rz   r{   keyvaluer'   r'   r(   r      s"   
r   
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.
    )r}   r   )r   r   r|   itemr'   r'   r(   get_value_or_default   s   

r   )2rD   r:   rn   dataclassesr   enumr   typingr   r   r   r   r   r	   r
   r   rG   fastapi.datastructuresr   r   fastapi.openapi.constantsr   pydanticr   r   r   pydantic.class_validatorsr   pydantic.fieldsr   r   r   pydantic.schemar   pydantic.utilsr   routingr   r%   strboolr)   r7   r<   rK   rQ   rt   ry   r   r   r'   r'   r'   r(   <module>   s    (


	
,
2
&


