o
    h                     @   sP  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Zadddebdejcd ebd!eeeb  de8f
d"d#Zddejcd ebde8fd$d%Zeddd&dejcd'e
d(e	f d ebd)eeb d!eeeb  de8fd*d+Zfeee
d(e	f  eebd(f f Zgd,dd-d.e8d/ehd0eeeg  de8fd1d2Zid3ee dee fd4d5Zjd.e8dee fd6d7Zkd8e
d(e	f de jlfd9d:Zmd;e	d<eebe	f de	fd=d>Znd8e
d(e	f de	fd?d@ZodddAdBd ebd8e
d(e	f d)eeb d!eeeb  dCehde8fdDdEZpdebdFe	d.e8deeh fdGdHZqeG dIdJ dJZrdebd;e	dKe	dLehderf
dMdNZsdOed.e8ddfdPdQZtd8e
d(e	f dehfdRdSZud8e
d(e	f dehfdTdUZvd8e
d(e	f dehfdVdWZwd8e
d(e	f dXedYeebe	f de	fdZd[ZxeG d\d] d]Zydddddd^d_eeVeZf d.e8d`eeeebe	f eOf  daeeK dbeeX dcee	 ddeeee
d(e	f eeb f e	f  deedfehdeyfdgdhZzdOedKe	dieebe	f djeebd(f dee	ee	 f f
dkdlZ{	ddOedieebe	f dmeebdf de	fdndoZ|d3ee dpeeebe	f eRePf deeebe	f ee	 f fdqdrZ}d3ee dehfdsdtZ~duee dveOdeebe	f fdwdxZduee dveeeebe	f eOf  dfehdeeebe	f eeebe	f  f fdydzZd{e8d)ebdfehdee fd|d}ZdS )    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 d S  ttfyV   z,ddlm}  | s#J zddlm} |s.J W n ty@   tt	 t
t	d w W Y d S  tyU   tt t
td w w )Nr   )__version__z0.0.12)parse_options_header)python_multipartrI   ImportErrorAssertionError	multipartmultipart.multipartrJ   r2   error!multipart_incorrect_install_errorRuntimeErrormultipart_not_installed_error)rI   rJ    rT   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fastapi/dependencies/utils.pyensure_multipart_is_installed[   s(   



rV   )security_scopes
param_namedependspathrW   c                 C   s   |j sJ t||j || |dS )N)rY   
dependencyrZ   namerW   )r[   get_sub_dependantrX   rY   rZ   rW   rT   rT   rU   get_param_sub_dependantv   s   
r_   c                 C   s"   t | js	J dt| | j|dS )Nz;A parameter-less dependency must have a callable dependency)rY   r[   rZ   )callabler[   r]   )rY   rZ   rT   rT   rU   get_parameterless_sub_dependant   s   ra   )r\   rW   r[   .r\   c           	      C   s|   d }|pg }t | tjr| j}|| t |tr*g }t |ttfr$|}t||d}t	||||| j
d}|r<|j| |S )N)security_schemescopes)rZ   callr\   rW   	use_cache)
isinstancer   Securityrc   extendr3   r4   r6   r1   get_dependantre   security_requirementsappend)	rY   r[   rZ   r\   rW   security_requirementdependency_scopes
use_scopessub_dependantrT   rT   rU   r]      s,   

r]   Fskip_repeatsvisited	dependantrq   rr   c             
   C   s   |d u rg }| | j t| j | j | j | j | j | j	 | j
| jd}| jD ];}|r9|j|v r9q/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_paramsrj   re   rZ   rp   )rk   	cache_keyr0   rt   r   ru   rv   rw   rx   rj   re   rZ   dependenciesget_flat_dependantrh   )rs   rq   rr   flat_dependantro   flat_subrT   rT   rU   r{      s4   

r{   fieldsc                 C   s:   | s| S | d }t | dkrt|jtrt|j}|S | S )Nr      )lenr)   type_r9   r    )r~   first_fieldfields_to_extractrT   rT   rU   _get_flat_fields_from_params   s   
r   c                 C   sD   t | dd}t|j}t|j}t|j}t|j}|| | | S )NT)rq   )r{   r   rt   ru   rv   rw   )rs   r|   rt   ru   rv   rw   rT   rT   rU   get_flat_params   s   



r   rd   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 ))r\   kinddefault
annotation)inspect	Parameterr\   r   r   get_typed_annotationr   ).0paramglobalnsrT   rU   
<listcomp>   s    
z'get_typed_signature.<locals>.<listcomp>)r   	signaturegetattr
parametersvalues	Signature)rd   r   typed_paramstyped_signaturerT   r   rU   get_typed_signature   s   


	r   r   r   c                 C   s"   t | trt| } t| ||} | S N)rf   strr   r   )r   r   rT   rT   rU   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   )rd   r   r   r   rT   rT   rU   get_typed_return_annotation   s   

r   T)r\   rW   re   re   c                 C   s   t | }t|}|j}t||| ||d}| D ]Z\}	}
|	|v }t|	|
j|
j|d}|jd ur?t	|	|j| |d}|j
| qt|	|j|drT|jd u sSJ d|	q|jd us[J t|jjtjrk|j|j qt|j|d q|S )N)rd   r\   rZ   rW   re   )rX   r   valueis_path_paramr^   rX   type_annotationrs   z0Cannot specify multiple FastAPI annotations for )fieldrs   )r8   r   r   r0   itemsanalyze_paramr   r   rY   r_   rz   rk   !add_non_field_param_to_dependencyr   r   rf   
field_infor   Bodyrx   add_param_to_fields)rZ   rd   r\   rW   re   path_param_namesendpoint_signaturesignature_paramsrs   rX   r   r   param_detailsro   rT   rT   rU   ri   	  sR   
ri   r   c                 C   s|   t |tr
| |_dS t |tr| |_dS t |tr| |_dS t |tr(| |_dS t |t	r2| |_
dS t |tr<| |_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   rT   rT   rU   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   rY   r   N)	__name__
__module____qualname__r   __annotations__r   r   Dependsr   rT   rT   rT   rU   r   U  s   
 r   r   r   c                 C   s  d }d }t }t }|tjjur|}|}t|tu ryt|}|d }dd |dd  D }	dd |	D }
|
r9|
d }nd }t|trqt	||d}|j
tu s]|j
tu s]J d|jj d	| d
|tjjurm|riJ d||_
nt|_
nt|tjry|}t|tjr|d u sJ d| |d u sJ d| |}nt|tr|d u sJ d| |}tr||_|d ur|jd u rt|}||_t|ttttttfr|d u sJ d||d u sJ d|nD|d u r%|d u r%|tjjur|nt}|rtj|d}n't|st|rtj||d}nt |dstj!||d}ntj"||d}d }|d ur|rCt|tjsBJ d|jj d| nt|tj#rXt$|dd d u rXtj%j&|_'t(||| }t|tj)rht*  |j+szt$|dd rz| ,dd}n|j+p| }||_+t-| ||j
||j
ttfv |d}|rt.|dsJ dn#t|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 rT   )rf   r:   r   r   r   argrT   rT   rU   r   n  s    z!analyze_param.<locals>.<listcomp>r   c                 S   s&   g | ]}t |tjtjtjfr|qS rT   )rf   r   Paramr   r   r   rT   rT   rU   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_-)r\   r   r   aliasrequiredr   )r   z1Path params must be of one of the supported typesshape)r   rY   r   )3r   r   r   r   rG   rE   rF   rf   r:   r   r   r   r   	__class__r   r   r   r   r   r[   r   r)   rB   rD   rA   rC   r   r5   Pathr'   r(   Filer   r   Queryr   r   
ParamTypesqueryr   r   FormrV   r   replacer7   r$   r%   r   r9   r   )rX   r   r   r   r   rY   r   use_annotationannotated_argsfastapi_annotationsfastapi_specific_annotationsfastapi_annotationdefault_valuer   use_annotation_from_field_infor   rT   rT   rU   r   \  s  










r   r   c                 C   s   | j }t|dd }|tjjkr|j|  d S |tjjkr%|j|  d S |tjj	kr3|j
|  d S |tjjksAJ d| j |j|  d S )Nr   z>non-body parameters must be in path, query, header or cookie: )r   r   r   r   rZ   rt   rk   r   ru   headerrv   cookier\   rw   )r   rs   r   field_info_inrT   rT   rU   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   rd   dunder_callrT   rT   rU   is_coroutine_callable  s   



r   c                 C   $   t | rdS t| dd }t |S NTr   )r   isasyncgenfunctionr   r   rT   rT   rU   is_async_gen_callable     

r   c                 C   r   r   )r   isgeneratorfunctionr   r   rT   rT   rU   is_gen_callable"  r   r   stack
sub_valuesc                    sL   t | rtt| di |}nt| rt| di |}||I d H S )NrT   )r   r/   r   r   r.   enter_async_context)rd   r   r   cmrT   rT   rU   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   rT   rT   rT   rU   r   3  s   
 (r   )bodyr   r   dependency_overrides_providerr   requestr   r   r   r   r   async_exit_stackembed_body_fieldsc        	            s  i }	g }
|d u rt  }|jd= d |_|pi }|jD ]}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 q|jr|j
|v r||j
 }n0t|st|rt|||jdI d H }nt|r|d
i |jI d H }nt|fi |jI d H }|jd ur||	|j< |j
|vr|||j
< qt|j | j \}}t|j!| j!\}}t|j"| j\}}t|j#| j$\}}|	| |	| |	| |	| |
|| | | 7 }
|j%r/t&|j%||dI d H \}}|	| |
| |j'r8| |	|j'< |j(rHt)| t*rH| |	|j(< n|j+rWt)| t,rW| |	|j+< |j-rh|d u rct. }||	|j-< |j/rq||	|j/< |j0r~t1|jd|	|j0< t2|	|
|||d	S )Nzcontent-length.dependency_overrides)rZ   rd   r\   rW   )	r   rs   r   r   r   r   r   r   r   )rd   r   r   )body_fieldsreceived_bodyr   )rc   )r   r   r   r   r   rT   )3rC   headersstatus_coderz   r   r   r   rd   r   r   ry   r   r   getrZ   ri   r\   rW   solve_dependenciesr   updater   r   rh   re   r   r   r   r   r   r;   request_params_to_argsrt   ru   rv   rw   cookiesrx   request_body_to_argsr   r   rf   rB   r   rD   r   r-   r   r   r5   r   )r   rs   r   r   r   r   r   r   r   r   r   ro   rd   use_sub_dependantoriginal_calluse_pathsolved_resultsolvedpath_valuespath_errorsquery_valuesquery_errorsheader_valuesheader_errorscookie_valuescookie_errorsbody_valuesbody_errorsrT   rT   rU   r   <  s   
















r   r   locc                 C   sz   |d u r| j rd t|dgfS t| jg fS | j|||d\}}t|tr*d |gfS t|tr9t|dd}d |fS |g fS )N)r  rT   )r   
loc_prefix)	r   r!   r   r   validaterf   r   listr   )r   r   r   r  v_errors_
new_errorsrT   rT   rU    _validate_value_with_model_field  s   


r  r   c                 C   s   |p| j }t| rt|ttfr||}n||d }|d u s:t| jtj	r0t|t
r0|dks:t| rDt|dkrD| jr?d S t| jS |S )N r   )r   r&   rf   r>   r=   getlistr   r   r   r   r   r   r   r   r   )r   r   r   r   rT   rT   rU   _get_multidict_value  s"   

r  received_paramsc                 C   s  i }g }| s
||fS | d }| }d}d}t | dkr.t|jtr.t|j}d}t|jdd}i }t }	|D ]@}
d }t|t	rWt|
jd|}|rW|
j
|
jkrP|
j
n|
jdd}t|
||d}|d urg|||
j< |	|pm|
j
 |	|
j q5| D ]\}}||	vr|||< qz|r|j}t|tjsJ d	|jjf}t||||d
\}}|j|i|fS | D ]2}
t|
|}|
j}t|tjsJ d	|jj|
j
f}t|
|||d
\}}|r|| q|||
j< q||fS )Nr   FTr   r   r   r   )r   z"Params must be subclasses of Paramr   r   r   r  )r   r)   r   r9   r    r   r   setrf   r=   r   r\   r   r  addr   r   r   r   r   r  rh   )r~   r  r   r   r   r   single_not_embedded_fielddefault_convert_underscoresparams_to_processprocessed_keysr   r   r   r   keyr   r  r  r  rT   rT   rU   r     sx   






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 rT   )r\   )r   r   rT   rT   rU   	<setcomp>8  s    z,_should_embed_body_fields.<locals>.<setcomp>r   Tr   embed)	r   r   r   rf   r   r   r)   r   r9   )r~   body_param_names_setr   rT   rT   rU   _should_embed_body_fields3  s   r'  r   r   c              
      sD  i }| d }|j }| D ]}t||}t|tjr*t|r*t|tr*| I d H }n[t|rt|tjrt	|rt|t
s?J g  dtg ttttf f dd f fdd}t 4 I d H }|D ]	}	|||	j q`W d   I d H  n1 I d H szw   Y  t| d}|d ur|||j< q| D ]\}
}|
|vr|||
< q|S )Nr   fnrH   c                    s   |  I d H }  | d S r   )rk   )r(  resultresultsrT   rU   
process_fnb  s   z&_extract_form_body.<locals>.process_fn)r   r   )r   r  rf   r   r   r"   r@   readr#   r,   r*   r   r	   r   anyiocreate_task_group
start_soonr+   r   r   )r   r   r   r   first_field_infor   r   r,  tg	sub_valuer#  rT   r*  rU   _extract_form_bodyI  sP   


(
r4  c              	      s  i }g }| sJ dt | dko| }| d }|}| }|r)t|jtr)t|j}t|tr6t||I d H }|rKd}	t||||	d\}
}|j	|
i|fS | D ]=}d|j
f}	d }|d ursz||j
}W n tyr   |t|	 Y qMw t||||	d\}
}|r|| qM|
||j	< qM||fS )Nz3request_body_to_args() should be called with fieldsr   r   )r   r  r   )r   r)   r   r9   r    rf   r<   r4  r  r\   r   r   AttributeErrorrk   r!   rh   )r   r   r   r   r   r  r   body_to_processr   r  r  r  r   r   rT   rT   rU   r   t  sF   




r   r|   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 r<tj}n'tdd | j D rJtj}ntj}dd | j D }	tt|	dkrc|	d |d< t	d||d|d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   Body_)r~   
model_namec                 s   s    | ]}|j rd V  qdS )TN)r   r   frT   rT   rU   	<genexpr>  s    z!get_body_field.<locals>.<genexpr>r   )r   r   r   c                 s       | ]
}t |jtjV  qd S r   )rf   r   r   r   r9  rT   rT   rU   r;        c                 s   r<  r   )rf   r   r   r   r9  rT   rT   rU   r;    r=  c                 S   s"   g | ]}t |jtjr|jjqS rT   )rf   r   r   r   
media_typer9  rT   rT   rU   r     s    z"get_body_field.<locals>.<listcomp>r   r>  )r\   r   r   r   r   rT   )
rx   r   anyr   r   r   r   r   r  r7   )r|   r\   r   first_paramr8  	BodyModelr   BodyFieldInfo_kwargsBodyFieldInfobody_param_media_typesfinal_fieldrT   rT   rU   get_body_field  sB   
rF  )rH   Nr   )r   
contextlibr   r   r   r   dataclassesr   typingr   r   r	   r
   r   r   r   r   r   r   r   r   r   r.  fastapir   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,   fastapi.backgroundr-   fastapi.concurrencyr.   r/   fastapi.dependencies.modelsr0   r1   fastapi.loggerr2   fastapi.security.baser3   fastapi.security.oauth2r4   r5   $fastapi.security.open_id_connect_urlr6   fastapi.utilsr7   r8   pydanticr9   pydantic.fieldsr:   starlette.backgroundr   starlette.concurrencyr;   starlette.datastructuresr<   r=   r>   r?   r@   starlette.requestsrA   rB   starlette.responsesrC   starlette.websocketsrD   typing_extensionsrE   rF   rG   rS   rQ   rV   r   r   r_   ra   r]   CacheKeyboolr{   r   r   r   r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r  r  r   r'  r4  r   rF  rT   rT   rT   rU   <module>   s   <h

 




  

#
	


4

 '	




"	

~






O

+
.