a
    `g                     @   s  d dl 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	m
Z
mZmZmZ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 d dlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3 d d	l4m5Z5m6Z6 d d
l7m8Z8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z?m@Z@ d dlAmBZB d dlCmDZDmEZE d dlFmGZG d dlHmIZI d dlJm3ZK d dlLmMZM d dlNmOZOmPZPmQZQmRZRmSZS d dlTmUZUmVZV d dlWmXZX d dlYmZZZ d dl[m\Z\m]Z]m^Z^ dZ_dZ`ddddZaddebejcebeeeb  e8ddd Zdejcebe8d!d"d#Zeddd$ejce
d%e	f ebeeb eeeb  e8d&d'd(Zfeee
d%e	f  eebd%f f Zgd)dd*e8eheeeg  e8d+d,d-Ziee ee d.d/d0Zje8ee d1d2d3Zke
d%e	f e jld4d5d6Zme	eebe	f e	d7d8d9Zne
d%e	f e	d4d:d;Zoddd<d=ebe
d%e	f eeb eeeb  ehe8d>d?d@Zpebe	e8eeh dAdBdCZqeG dDdE dEZrebe	e	eherdFdGdHZsee8ddIdJdKZte
d%e	f ehd4dLdMZue
d%e	f ehd4dNdOZve
d%e	f ehd4dPdQZwe
d%e	f eeebe	f e	dRdSdTZxeG dUdV dVZyddddddWeeVeZf e8eeeebe	f eOf  eeK eeX ee	 eeee
d%e	f eeb f e	f  eeheydX
dYdZZzee	eebe	f eebd%f ee	ee	 f d[d\d]Z{doeeebe	f eebdf e	d^d_d`Z|ee eeebe	f eRePf eeebe	f ee	 f dadbdcZ}ee ehd.dddeZ~ee eOeebe	f dfdgdhZee eeeebe	f eOf  eheeebe	f eeebe	f  f didjdkZe8ebehee dldmdnZdS )p    N)AsyncExitStackcontextmanager)copydeepcopy)	dataclass)AnyCallable	CoroutineDict
ForwardRefListMappingOptionalSequenceTupleTypeUnioncast)params)PYDANTIC_V2ErrorWrapper
ModelFieldRequiredParam	Undefined_regenerate_error_with_loccopy_field_infocreate_body_modelevaluate_forwardreffield_annotation_is_scalarget_annotation_from_field_infoget_cached_model_fieldsget_missing_field_erroris_bytes_fieldis_bytes_sequence_fieldis_scalar_fieldis_scalar_sequence_fieldis_sequence_field.is_uploadfile_or_nonable_uploadfile_annotation!is_uploadfile_sequence_annotationlenient_issubclasssequence_typesserialize_sequence_valuevalue_is_sequence)BackgroundTasks)asynccontextmanagercontextmanager_in_threadpool)	DependantSecurityRequirement)logger)SecurityBase)OAuth2SecurityScopes)OpenIdConnect)create_model_fieldget_path_param_names)	BaseModel)	FieldInfo)run_in_threadpool)FormDataHeadersImmutableMultiDictQueryParams
UploadFile)HTTPConnectionRequest)Response)	WebSocket)	Annotatedget_args
get_originzForm data requires "python-multipart" to be installed. 
You can install "python-multipart" with: 

pip install python-multipart
zForm data requires "python-multipart" to be installed. It seems you installed "multipart" instead. 
You can remove "multipart" with: 

pip uninstall multipart

And then install "python-multipart" with: 

pip install python-multipart
)returnc                  C   s   zddl m}  | dksJ W n ttfy   zXddlm}  | sDJ zddlm} |sZJ W n& ty   tt	 t
t	d Y n0 W n& ty   tt t
td Y n0 Y n0 d S )Nr   )__version__z0.0.12)parse_options_header)Zpython_multipartrI   ImportErrorAssertionError	multipartZmultipart.multipartrJ   r2   error!multipart_incorrect_install_errorRuntimeErrormultipart_not_installed_error)rI   rJ    rR   h/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/fastapi/dependencies/utils.pyensure_multipart_is_installed[   s     

rT   )security_scopes)
param_namedependspathrU   rH   c                 C   s   |j s
J t||j || |dS )N)rW   
dependencyrX   namerU   )rY   get_sub_dependantrV   rW   rX   rU   rR   rR   rS   get_param_sub_dependantv   s    
r]   )rW   rX   rH   c                 C   s"   t | jsJ dt| | j|dS )Nz;A parameter-less dependency must have a callable dependency)rW   rY   rX   )callablerY   r[   )rW   rX   rR   rR   rS   get_parameterless_sub_dependant   s    r_   )rZ   rU   .)rW   rY   rX   rZ   rU   rH   c           	      C   s|   d }|p
g }t | tjr(| j}|| t |trTg }t |ttfrH|}t||d}t	||||| j
d}|rx|j| |S )N)Zsecurity_schemescopes)rX   callrZ   rU   	use_cache)
isinstancer   ZSecurityr`   extendr3   r4   r6   r1   get_dependantrb   security_requirementsappend)	rW   rY   rX   rZ   rU   Zsecurity_requirementZdependency_scopesZ
use_scopessub_dependantrR   rR   rS   r[      s,    

r[   Fskip_repeatsvisited)	dependantrj   rk   rH   c             
   C   s   |d u rg }| | j t| j | j | j | j | j | j	 | j
| jd}| jD ]v}|rr|j|v rrq^t|||d}|j|j |j|j |j|j |j|j |j|j |j	|j	 q^|S )N)path_paramsquery_paramsheader_paramscookie_paramsbody_paramsrf   rb   rX   ri   )rg   	cache_keyr0   rm   r   rn   ro   rp   rq   rf   rb   rX   dependenciesget_flat_dependantrd   )rl   rj   rk   flat_dependantrh   Zflat_subrR   rR   rS   rt      s4    

rt   )fieldsrH   c                 C   s:   | s| S | d }t | dkr6t|jtr6t|j}|S | S )Nr      )lenr)   type_r9   r    )rv   first_fieldfields_to_extractrR   rR   rS   _get_flat_fields_from_params   s    
r|   )rl   rH   c                 C   sD   t | dd}t|j}t|j}t|j}t|j}|| | | S )NT)rj   )rt   r|   rm   rn   ro   rp   )rl   ru   rm   rn   ro   rp   rR   rR   rS   get_flat_params   s    



r}   )ra   rH   c                    s<   t | }t| di   fdd|j D }t |}|S )N__globals__c              	      s,   g | ]$}t j|j|j|jt|j d qS ))rZ   kinddefault
annotation)inspect	ParameterrZ   r   r   get_typed_annotationr   ).0paramglobalnsrR   rS   
<listcomp>   s   
z'get_typed_signature.<locals>.<listcomp>)r   	signaturegetattr
parametersvalues	Signature)ra   r   Ztyped_paramsZtyped_signaturerR   r   rS   get_typed_signature   s    

	
r   )r   r   rH   c                 C   s"   t | trt| } t| ||} | S N)rc   strr   r   )r   r   rR   rR   rS   r      s    
r   c                 C   s6   t | }|j}|t jju r d S t| di }t||S )Nr~   )r   r   return_annotationr   emptyr   r   )ra   r   r   r   rR   rR   rS   get_typed_return_annotation   s    
r   T)rZ   rU   rb   )rX   ra   rZ   rU   rb   rH   c                 C   s   t | }t|}|j}t||| ||d}| D ]\}	}
|	|v }t|	|
j|
j|d}|jd ur~t	|	|j| |d}|j
| q0t|	|j|dr|jd u s0J d|	q0|jd usJ t|jjtjr|j|j q0t|j|d q0|S )N)ra   rZ   rX   rU   rb   )rV   r   valueis_path_paramr\   rV   type_annotationrl   z0Cannot specify multiple FastAPI annotations for )fieldrl   )r8   r   r   r0   itemsanalyze_paramr   r   rW   r]   rs   rg   !add_non_field_param_to_dependencyr   r   rc   
field_infor   Bodyrq   add_param_to_fields)rX   ra   rZ   rU   rb   Zpath_param_namesZendpoint_signatureZsignature_paramsrl   rV   r   r   Zparam_detailsrh   rR   rR   rS   re   	  sT    
re   )rV   r   rl   rH   c                 C   s|   t |tr| |_dS t |tr(| |_dS t |tr<| |_dS t |trP| |_dS t |t	rd| |_
dS t |trx| |_dS d S )NT)r)   rB   request_param_namerD   websocket_param_namerA   http_connection_param_namerC   response_param_nameStarletteBackgroundTasksbackground_tasks_param_namer5   security_scopes_param_namer   rR   rR   rS   r   =  s&    





r   c                   @   s0   e Zd ZU eed< eej ed< ee ed< dS )ParamDetailsr   rW   r   N)	__name__
__module____qualname__r   __annotations__r   r   Dependsr   rR   rR   rR   rS   r   U  s   
r   )rV   r   r   r   rH   c                 C   s  d }d }t }t }|tjjur$|}|}t|tu rt|}|d }dd |dd  D }	dd |	D }
|
rr|
d }nd }t|trt	||d}|j
tu s|j
tu sJ d|jj d	| d
|tjjur|rJ d||_
qt|_
nt|tjr|}t|tjr6|d u sJ d| |d u s0J d| |}n4t|trj|d u sZJ d| |}trj||_|d ur|jd u rt|}||_t|ttttttfr|d u sJ d||d u sdJ d|n|d u rd|d u rd|tjjur|nt}|rtj|d}nNt|s*t|r:tj||d}n*t |dsVtj!||d}ntj"||d}d }|d ur|rt|tjsJ d|jj d| n*t|tj#rt$|dd d u rtj%j&|_'t(||| }t|tj)rt*  |j+st$|dd r| ,dd}n|j+p| }||_+t-| ||j
||j
ttfv |d}|r\t.|dsJ dnFt|tj"rt.|st/|st|j0t1rt$|dddksJ t2|||dS )Nr   c                 S   s    g | ]}t |ttjfr|qS rR   )rc   r:   r   r   r   argrR   rR   rS   r   n  s   z!analyze_param.<locals>.<listcomp>rw   c                 S   s&   g | ]}t |tjtjtjfr|qS rR   )rc   r   Paramr   r   r   rR   rR   rS   r   s  s   )r   r   `z1` default value cannot be set in `Annotated` for z). Set the default value with `=` instead.z*Path parameters cannot have default valueszGCannot specify `Depends` in `Annotated` and default value together for zaCannot specify a FastAPI annotation in `Annotated` and `Depends` as a default value together for zQCannot specify FastAPI annotations in `Annotated` and default value together for z"Cannot specify `Depends` for type z+Cannot specify FastAPI annotation for type )r   )r   r   zCannot use `z` for path param in_convert_underscores_-)rZ   ry   r   aliasrequiredr   )r   z1Path params must be of one of the supported typesshape)r   rW   r   )3r   r   r   r   rG   rE   rF   rc   r:   r   r   r   r   	__class__r   r   r   r   r   rY   r   r)   rB   rD   rA   rC   r   r5   Pathr'   r(   Filer   r   ZQueryr   r   
ParamTypesqueryr   r   FormrT   r   replacer7   r$   r%   ry   r9   r   )rV   r   r   r   r   rW   r   Zuse_annotationZannotated_argsZfastapi_annotationsZfastapi_specific_annotationsZfastapi_annotationdefault_valuer   Zuse_annotation_from_field_infor   rR   rR   rS   r   \  s   







r   )r   rl   rH   c                 C   s   | j }t|dd }|tjjkr,|j|  n\|tjjkrF|j|  nB|tjj	kr`|j
|  n(|tjjks|J d| j |j|  d S )Nr   z>non-body parameters must be in path, query, header or cookie: )r   r   r   r   rX   rm   rg   r   rn   headerro   cookierZ   rp   )r   rl   r   Zfield_info_inrR   rR   rS   r     s    

r   c                 C   s8   t | rt | S t | r"dS t| dd }t |S )NF__call__)r   	isroutineiscoroutinefunctionisclassr   ra   Zdunder_callrR   rR   rS   is_coroutine_callable  s    


r   c                 C   s$   t | rdS t| dd }t |S NTr   )r   isasyncgenfunctionr   r   rR   rR   rS   is_async_gen_callable  s    
r   c                 C   s$   t | rdS t| dd }t |S r   )r   isgeneratorfunctionr   r   rR   rR   rS   is_gen_callable"  s    
r   )ra   stack
sub_valuesrH   c                    sJ   t | r tt| f i |}nt| r:t| f i |}||I d H S r   )r   r/   r   r   r.   enter_async_context)ra   r   r   cmrR   rR   rS   solve_generator)  s
    r   c                   @   sb   e Zd ZU eeef ed< ee ed< ee	 ed< e
ed< eeedef ee f ef ed< dS )SolvedDependencyr   errorsbackground_tasksresponse.dependency_cacheN)r   r   r   r
   r   r   r   r   r   r   rC   r   r   rR   rR   rR   rS   r   3  s
   
r   )bodyr   r   dependency_overrides_providerr   )
requestrl   r   r   r   r   r   async_exit_stackembed_body_fieldsrH   c        	            s  i }	g }
|d u r$t  }|jd= d |_|p*i }|jD ]z}ttdtf |j|_tttdtf tt	 f |j
|_
|j}|}|r|jr|j}t|di ||}|j}t|||j|jd}t| ||||||||d	I d H }|j}||j |jr|
|j q2|jr|j
|v r||j
 }nft|s2t|rJt|||jdI d H }n:t|rl|f i |jI d H }nt|fi |jI d H }|jd ur||	|j< |j
|vr2|||j
< q2t|j | j \}}t|j!| j!\}}t|j"| j\}}t|j#| j$\}}|	| |	| |	| |	| |
|| | | 7 }
|j%rjt&|j%||dI d H \}}|	| |
| |j'r|| |	|j'< |j(rt)| t*r| |	|j(< n|j+rt)| t,r| |	|j+< |j-r|d u rt. }||	|j-< |j/r||	|j/< |j0rt1|jd|	|j0< t2|	|
|||d	S )
Nzcontent-length.dependency_overrides)rX   ra   rZ   rU   )	r   rl   r   r   r   r   r   r   r   )ra   r   r   )body_fieldsreceived_bodyr   )r`   )r   r   r   r   r   )3rC   headersstatus_coders   r   r   r   ra   r   r   rr   r   r   getrX   re   rZ   rU   solve_dependenciesr   updater   r   rd   rb   r   r   r   r   r   r;   request_params_to_argsrm   rn   ro   rp   cookiesrq   request_body_to_argsr   r   rc   rB   r   rD   r   r-   r   r   r5   r   )r   rl   r   r   r   r   r   r   r   r   r   rh   ra   Zuse_sub_dependantZoriginal_callZuse_pathZsolved_resultZsolvedZpath_valuesZpath_errorsZquery_valuesZquery_errorsheader_valuesZheader_errorsZcookie_valuesZcookie_errorsZbody_valuesZbody_errorsrR   rR   rS   r   <  s    














r   )r   r   r   locrH   c                 C   s~   |d u r,| j rd t|dgfS t| jg fS | j|||d\}}t|trTd |gfS t|trrt|dd}d |fS |g fS d S )N)r   rR   )r   Z
loc_prefix)	r   r!   r   r   validaterc   r   listr   )r   r   r   r   v_errors_Z
new_errorsrR   rR   rS    _validate_value_with_model_field  s    


r   )r   r   r   rH   c                 C   s   |p| j }t| r,t|ttfr,||}n||d }|d u stt| jtj	r`t|t
r`|dkstt| rt|dkr| jr~d S t| jS |S )N r   )r   r&   rc   r>   r=   getlistr   r   r   r   r   rx   r   r   r   )r   r   r   r   rR   rR   rS   _get_multidict_value  s(    

	
r   )rv   received_paramsrH   c                 C   s  i }g }| s||fS | d }| }d}t | dkrJt|jtrJt|j}d}i }t }|D ]}	d }
t|trt|	j	dd}|r|	j
|	jkr|	j
n|	jdd}
t|	||
d}|d ur|||	j< ||
p|	j
 ||	j qX| D ]\}}||vr|||< q|rJ|j	}t|tjsJ d	|jjf}t||||d
\}}|j|i|fS | D ]j}	t|	|}|	j	}t|tjsxJ d	|jj|	j
f}t|	|||d
\}}|r|| n
|||	j< qN||fS )Nr   Frw   Tr   r   r   )r   z"Params must be subclasses of Paramr   r   r   r   )rx   r)   ry   r9   r    setrc   r=   r   r   r   rZ   r   r   addr   r   r   r   r   r   rd   )rv   r   r   r   rz   r{   single_not_embedded_fieldZparams_to_processZprocessed_keysr   r   r   r   keyr   r   r   r   rR   rR   rS   r     sr    








r   c                 C   sb   | sdS dd | D }t |dkr&dS | d }t|jdd r@dS t|jtjr^t|jts^dS dS )NFc                 S   s   h | ]
}|j qS rR   )rZ   )r   r   rR   rR   rS   	<setcomp>0      z,_should_embed_body_fields.<locals>.<setcomp>rw   Tr   Zembed)	rx   r   r   rc   r   r   r)   ry   r9   )rv   Zbody_param_names_setrz   rR   rR   rS   _should_embed_body_fields+  s    r   )r   r   rH   c              
      sN  i }| d }|j }| D ]
}t||}t|tjrTt|rTt|trT| I d H }nt|rt|tjrt	|rt|t
sJ g  tg ttttf f d d fdd}t 4 I d H 0}|D ]}	|||	j qW d   I d H  q1 I d H s0    Y  t| d}|d ur|||j< q| D ]\}
}|
|vr,|||
< q,|S )Nr   )fnrH   c                    s   |  I d H }  | d S r   )rg   )r   resultresultsrR   rS   
process_fnZ  s    z&_extract_form_body.<locals>.process_fn)r   r   )r   r   rc   r   r   r"   r@   readr#   r,   r*   r   r	   r   anyioZcreate_task_groupZ
start_soonr+   r   r   )r   r   r   rz   Zfirst_field_infor   r   r   tgZ	sub_valuer   rR   r   rS   _extract_form_bodyA  sB    



<
r  )r   r   r   rH   c              	      s"  i }g }| sJ dt | dko$| }| d }|}| }|rPt|jtrPt|j}t|trjt||I d H }|rd}	t||||	d\}
}|j	|
i|fS | D ]}d|j
f}	d }|d urz||j
}W n$ ty   |t|	 Y qY n0 t||||	d\}
}|r|| q|
||j	< q||fS )Nz3request_body_to_args() should be called with fieldsrw   r   )r   r   r   )rx   r)   ry   r9   r    rc   r<   r  r   rZ   r   r   AttributeErrorrg   r!   rd   )r   r   r   r   r   r   rz   Zbody_to_processr{   r   r   r   r   r   rR   rR   rS   r   l  sB    





r   )ru   rZ   r   rH   c              	   C   s   | j s
dS | j d }|s|S d| }t| j |d}tdd | j D }|dd}|s\d|d	< td
d | j D rxtj}nNtdd | j D rtj}n2tj}dd | j D }	tt|	dkr|	d |d< t	d||d|f i |d}
|
S )a  
    Get a ModelField representing the request body for a path operation, combining
    all body parameters into a single field if necessary.

    Used to check if it's form data (with `isinstance(body_field, params.Form)`)
    or JSON and to generate the JSON Schema for a request body.

    This is **not** used to validate/parse the request body, that's done with each
    individual body parameter.
    Nr   ZBody_)rv   
model_namec                 s   s   | ]}|j rd V  qdS )TN)r   r   frR   rR   rS   	<genexpr>  r   z!get_body_field.<locals>.<genexpr>r   )r   r   r   c                 s   s   | ]}t |jtjV  qd S r   )rc   r   r   r   r  rR   rR   rS   r    r   c                 s   s   | ]}t |jtjV  qd S r   )rc   r   r   r   r  rR   rR   rS   r    r   c                 S   s"   g | ]}t |jtjr|jjqS rR   )rc   r   r   r   
media_typer  rR   rR   rS   r     s   z"get_body_field.<locals>.<listcomp>rw   r	  )rZ   ry   r   r   r   )
rq   r   anyr   r   r   r   rx   r   r7   )ru   rZ   r   Zfirst_paramr  Z	BodyModelr   ZBodyFieldInfo_kwargsZBodyFieldInfoZbody_param_media_typesZfinal_fieldrR   rR   rS   get_body_field  sB    
r  )N)r   
contextlibr   r   r   r   dataclassesr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r  Zfastapir   Zfastapi._compatr   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   Zfastapi.backgroundr-   Zfastapi.concurrencyr.   r/   Zfastapi.dependencies.modelsr0   r1   Zfastapi.loggerr2   Zfastapi.security.baser3   Zfastapi.security.oauth2r4   r5   Z$fastapi.security.open_id_connect_urlr6   Zfastapi.utilsr7   r8   Zpydanticr9   Zpydantic.fieldsr:   Zstarlette.backgroundr   Zstarlette.concurrencyr;   Zstarlette.datastructuresr<   r=   r>   r?   r@   Zstarlette.requestsrA   rB   Zstarlette.responsesrC   Zstarlette.websocketsrD   Ztyping_extensionsrE   rF   rG   rQ   rO   rT   r   r   r]   r_   r[   ZCacheKeyboolrt   r|   r}   r   r   r   r   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  rR   rR   rR   rS   <module>   s  <h
 


  
#
	

5 '	

" G
,/