U
    e                     @   s@  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rddl$m%Z% ee&e'df e(dddZ)eeee ee f  e
eee ee f e'f e
e'e	f dddZ*e'ee' dddZ+dddeddfe'ee	 ee
e'ef  ee	 ee(ef ee ee ee' ed	ddZ,ddeee
ee ee f  edddZ-e'e'e'e'dd d!Z.d"e'd#d$d%Z/e
e	e	f e
e	e	f dd&d'd(Z0eeef eeef eeef d)d*d+Z1dS ),    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 krdS | dkrdS t | }|dk p.|dk S )NT>   4XX2XX1XXdefault5XX3XX   >   0     )int)r   Zcurrent_status_code r&   N/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/fastapi/utils.pyis_body_allowed_for_status_code   s    r(   )flat_modelsmodel_name_mapr   c                 C   s^   i }| D ]P}t ||td\}}}|| || }d|krP|d dd |d< |||< q|S )N)r*   Z
ref_prefixdescriptionr   )r   r   updatesplit)r)   r*   ZdefinitionsmodelZm_schemaZm_definitionsZm_nested_modelsZ
model_namer&   r&   r'   get_model_definitions&   s      

r0   )pathr   c                 C   s   t td| S )Nz{(.*?)})setrefindall)r1   r&   r&   r'   get_path_param_names8   s    r5   T)	nametype_class_validatorsr   requiredmodel_config
field_infoaliasr   c           	   
   C   sh   |pi }|pt  }tjt| ||||||d}z||dW S  tk
rb   tjd| ddY nX dS )zB
    Create a new response field. Raises if type_ is invalid.
    )r6   r7   r8   r   r9   r:   r<   )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/N)r   	functoolspartialr   RuntimeErrorfastapi
exceptionsZFastAPIError)	r6   r7   r8   r   r9   r:   r;   r<   Zresponse_fieldr&   r&   r'   create_response_field<   s(    

rB   cloned_types)fieldrD   r   c                   sR   d kri  | j }t|r*t|dr*|j}|}t|trttt |} |}|d krt	|j
|d}| |< |j D ]}t| d|j|j< qxt| j|d}| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| jr fdd| jD |_| jrt| j d|_| j|_| j|_| j|_| j|_| j|_|   |S )N__pydantic_model__)__base__rC   )r6   r7   c                    s   g | ]}t | d qS )rC   )create_cloned_field).0Z	sub_fieldrC   r&   r'   
<listcomp>   s   z'create_cloned_field.<locals>.<listcomp>)!r7   r   hasattrrF   r   r   r   r	   getr   __name__Z
__fields__valuesrH   r6   rB   Z	has_aliasr<   r8   r   r9   r:   r;   
allow_noneZvalidate_alwaysZ
sub_fieldsZ	key_fieldZ
validatorsZpre_validatorsZpost_validatorsZ
parse_jsonshapeZpopulate_validators)rE   rD   original_typeZuse_typefZ	new_fieldr&   rC   r'   rH   e   sV    

 
 rH   )r6   r1   methodr   c                 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DeprecationWarningr3   sublower)r6   r1   rS   operation_idr&   r&   r'   generate_operation_id_for_path   s    r^   r   )router   c                 C   sB   | j | j }tdd|}| js$t|d t| jd   }|S )NrV   rW   r   )r6   Zpath_formatr3   r[   methodsAssertionErrorlistr\   )r_   r]   r&   r&   r'   generate_unique_id   s
    
rc   )	main_dictupdate_dictr   c                 C   s   |  D ]z\}}|| kr@t| | tr@t|tr@t| | | q|| krzt| | trzt|| trz| | ||  | |< q|| |< qd S )N)items
isinstancedictdeep_dict_updaterb   )rd   re   keyvaluer&   r&   r'   ri      s     ri   )
first_itemextra_itemsr   c                 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   )rl   rm   rf   itemr&   r&   r'   get_value_or_default   s
    


ro   )2r=   r3   rX   dataclassesr   enumr   typingr   r   r   r   r   r	   r
   r   r@   Zfastapi.datastructuresr   r   Zfastapi.openapi.constantsr   Zpydanticr   r   r   Zpydantic.class_validatorsr   Zpydantic.fieldsr   r   r   Zpydantic.schemar   Zpydantic.utilsr   Zroutingr   r%   strboolr(   r0   r5   rB   rH   r^   rc   ri   ro   r&   r&   r&   r'   <module>   sn   (

,3  "


