o
    ɝi2#                     @   sV  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mZmZ d dlmZmZ d dlm Z  d dl!m"Z" d d	l#m$Z$ erid
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Z.deedddddfde*dede	ee*ef  de	e dee+ef deee df de	e" de	e* de$d  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)Z0de*de*d*e*de*fd+d,Z1d-d.de*fd/d0Z2d1eeef d2eeef ddfd3d4Z3d5eeef d6eeef deeef fd7d8Z4dS )9    N)is_dataclass)	TYPE_CHECKINGAnyDictMutableMappingOptionalSetTypeUnioncast)WeakKeyDictionary)
PYDANTIC_V2
BaseConfig
ModelFieldPydanticSchemaGenerationError	UndefinedUndefinedType	Validatorannotation_is_pydantic_v1lenient_issubclassmay_v1)DefaultPlaceholderDefaultType)	BaseModel)	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-   I/var/www/html/ocr-read/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)r0   r-   r-   r.   get_path_param_names=   s   r4   a  Invalid args for response field! Hint: check that {type_} 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/
validationautonametype_class_validatorsr&   requiredmodel_config
field_infoaliasmode)r5   serializationversion)1r6   c
              	   C   s"  |pi }t j}
|pt  }| ||||||
|d}t|s&t|t js&|	dkrDddlm} z	|jd	i |W S  tyC   t	j
td w trsddlm} |pTt|||d}|| |d}z	|jd	i |W S  tyr   t	j
td w ddlm} z	|jd	i |W S  ty   t	j
td w )
N)r7   r<   r8   r9   r&   r:   r;   r=   rA   r   v1r   v2)
annotationr&   r=   )r>   r7   r<   r-   )r   r   r   r   
isinstancefastapi._compatrC   r   RuntimeErrorfastapi
exceptionsFastAPIError_invalid_args_messager   _compatrE   r   )r7   r8   r9   r&   r:   r;   r<   r=   r>   r@   v1_model_configv1_field_info	v1_kwargsrC   rE   kwargsr-   r-   r.   create_model_fieldL   sP   
rS   cloned_typesfieldrU   c                   s  t rddlm} t| |jr| S ddlm}  d u rt | j}t	|r+t
|dr+|j}|}t||jrbtt|j |} |}|d u rb|j|j|d}| |< |j D ]}t| d|j|j< qUt| j|dd	}| j|_| 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 )Nr   rD   r   rB   __pydantic_model__)__base__rT   rA   )r7   r8   r@   c                    s   g | ]}t | d qS )rT   )create_cloned_field).0	sub_fieldrT   r-   r.   
<listcomp>   s    
z'create_cloned_field.<locals>.<listcomp>)*r   rN   rE   rG   r   rH   rC   r   r8   r   hasattrrW   r   r   r   r	   getcreate_model__name__
__fields__valuesrY   r7   rS   	has_aliasr=   r9   r&   default_factoryr:   r;   r<   
allow_nonevalidate_always
sub_fields	key_field
validatorspre_validatorspost_validators
parse_jsonshapepopulate_validators)rV   rU   rE   rC   original_typeuse_typef	new_fieldr-   rT   r.   rY      sb   

rY   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DeprecationWarningr2   sublower)r7   r0   rs   operation_idr-   r-   r.   generate_operation_id_for_path   s   r~   router   c                 C   sH   | j  | j }tdd|}| jsJ | dt| jd   }|S )Nrv   rw   r   )r7   path_formatr2   r{   methodslistr|   )r   r}   r-   r-   r.   generate_unique_id   s
   
r   	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)itemsrG   dictdeep_dict_updater   )r   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.
    )rG   r   )r   r   r   itemr-   r-   r.   get_value_or_default   s   

r   )5r2   rx   dataclassesr   typingr   r   r   r   r   r   r	   r
   r   weakrefr   rJ   rH   r   r   r   r   r   r   r   r   r   r   fastapi.datastructuresr   r   pydanticr   pydantic.fieldsr   typing_extensionsr   routingr   r   __annotations__r+   strboolr/   r4   rM   rS   rY   r~   r   r   r   r-   r-   r-   r.   <module>   s   
 ,0
	

>
?
&


