o
    ß­j†  ã                   @   sè   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mZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ G dd„ deƒZG dd„ dƒZedƒZdedefdd„ZdS )é    )	ÚAnyÚBinaryIOÚCallableÚDictÚIterableÚOptionalÚTypeÚTypeVarÚcast)ÚPYDANTIC_V2Ú
CoreSchemaÚGetJsonSchemaHandlerÚJsonSchemaValueÚ"with_info_plain_validator_function)ÚURL)ÚAddress)ÚFormData)ÚHeaders)ÚQueryParams)ÚState)Ú
UploadFile)Ú	AnnotatedÚDocc                       sÀ  e Zd ZU dZeeedƒf ed< eee	 edƒf ed< eee
 edƒf ed< eeedƒf ed	< eee	 ed
ƒf ed< deeedƒf ddf‡ fdd„Z	d1dee
edƒf def‡ fdd„Zdee
edƒf ddf‡ fdd„Zd2‡ fdd„Zeded  deedef  fdd„ƒZeded  d edefd!d"„ƒZed#ed$edd fd%d&„ƒZes»ed'ee	ef ddfd(d)„ƒZed*ed+edefd,d-„ƒZed.ee d+eegef defd/d0„ƒZ ‡  Z!S )3r   aA  
    A file uploaded in a request.

    Define it as a *path operation function* (or dependency) parameter.

    If you are using a regular `def` function, you can use the `upload_file.file`
    attribute to access the raw standard Python file (blocking, not async), useful and
    needed for non-async code.

    Read more about it in the
    [FastAPI docs for Request Files](https://fastapi.tiangolo.com/tutorial/request-files/).

    ## Example

    ```python
    from typing import Annotated

    from fastapi import FastAPI, File, UploadFile

    app = FastAPI()


    @app.post("/files/")
    async def create_file(file: Annotated[bytes, File()]):
        return {"file_size": len(file)}


    @app.post("/uploadfile/")
    async def create_upload_file(file: UploadFile):
        return {"filename": file.filename}
    ```
    z,The standard Python file object (non-async).ÚfilezThe original file name.ÚfilenamezThe size of the file in bytes.ÚsizezThe headers of the request.Úheadersz2The content type of the request, from the headers.Úcontent_typeÚdatazA
                The bytes to write to the file.
                ÚreturnNc                 ƒ   ó   �t ƒ  |¡I dH S )zÆ
        Write some bytes to the file.

        You normally wouldn't use this from a file you read in a request.

        To be awaitable, compatible with async, this is run in threadpool.
        N)ÚsuperÚwrite)Úselfr   ©Ú	__class__© úS/var/www/html/CropPilot/venv/lib/python3.10/site-packages/fastapi/datastructures.pyr"   K   ó   €zUploadFile.writeéÿÿÿÿzL
                The number of bytes to read from the file.
                c                 ƒ   r    )z|
        Read some bytes from the file.

        To be awaitable, compatible with async, this is run in threadpool.
        N)r!   Úread)r#   r   r$   r&   r'   r*   _   s   €zUploadFile.readÚoffsetzO
                The position in bytes to seek to in the file.
                c                 ƒ   r    )z¾
        Move to a position in the file.

        Any next read or write will be done from that position.

        To be awaitable, compatible with async, this is run in threadpool.
        N)r!   Úseek)r#   r+   r$   r&   r'   r,   q   r(   zUploadFile.seekc                 ƒ   s   �t ƒ  ¡ I dH S )zm
        Close the file.

        To be awaitable, compatible with async, this is run in threadpool.
        N)r!   Úclose©r#   r$   r&   r'   r-   …   s   €zUploadFile.closeÚcls.c                 c   s   � | j V  d S ©N)Úvalidate)r/   r&   r&   r'   Ú__get_validators__�   s   €zUploadFile.__get_validators__Úvc                 C   s    t |tƒstdt|ƒ› �ƒ‚|S ©NzExpected UploadFile, received: )Ú
isinstanceÚStarletteUploadFileÚ
ValueErrorÚtype)r/   r3   r&   r&   r'   r1   ‘   s   
zUploadFile.validateÚ_UploadFile__input_valueÚ_c                 C   s&   t |tƒstdt|ƒ› �ƒ‚tt|ƒS r4   )r5   r6   r7   r8   r
   r   )r/   r9   r:   r&   r&   r'   Ú	_validate—   s   

zUploadFile._validateÚfield_schemac                 C   s   |  dddœ¡ d S ©NÚstringÚbinary)r8   Úformat)Úupdate)r/   r<   r&   r&   r'   Ú__modify_schema__Ÿ   s   zUploadFile.__modify_schema__Úcore_schemaÚhandlerc                 C   s
   dddœS r=   r&   )r/   rC   rD   r&   r&   r'   Ú__get_pydantic_json_schema__£   ó   
z'UploadFile.__get_pydantic_json_schema__Úsourcec                 C   ó
   t | jƒS r0   )r   r;   )r/   rG   rD   r&   r&   r'   Ú__get_pydantic_core_schema__©   rF   z'UploadFile.__get_pydantic_core_schema__)r)   )r   N)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__annotations__r   ÚstrÚintr   Úbytesr"   r*   r,   r-   Úclassmethodr   r   r   r   r2   r1   r;   r   r   rB   r   r   r   rE   rI   Ú__classcell__r&   r&   r$   r'   r      s’   
 !ÿÿÿÿÿÿþ
ö÷ÿÿÿþ
öÿÿÿþ
ö$ÿÿþÿÿþr   c                   @   s>   e Zd ZdZdefdd„Zdefdd„Zdedefd	d
„Z	dS )ÚDefaultPlaceholderz·
    You shouldn't use this class directly.

    It's used internally to recognize when a default value has been overwritten, even
    if the overridden default value was truthy.
    Úvaluec                 C   s
   || _ d S r0   ©rU   )r#   rU   r&   r&   r'   Ú__init__¸   ó   
zDefaultPlaceholder.__init__r   c                 C   rH   r0   )ÚboolrU   r.   r&   r&   r'   Ú__bool__»   rX   zDefaultPlaceholder.__bool__Úoc                 C   s   t |tƒo
|j| jkS r0   )r5   rT   rU   )r#   r[   r&   r&   r'   Ú__eq__¾   s   zDefaultPlaceholder.__eq__N)
rJ   rK   rL   rM   r   rW   rY   rZ   Úobjectr\   r&   r&   r&   r'   rT   °   s
    rT   ÚDefaultTyperU   r   c                 C   s   t | ƒS )zº
    You shouldn't use this function directly.

    It's used internally to recognize when a default value has been overwritten, even
    if the overridden default value was truthy.
    )rT   rV   r&   r&   r'   ÚDefaultÅ   s   r_   N)Útypingr   r   r   r   r   r   r   r	   r
   Úfastapi._compatr   r   r   r   r   Ústarlette.datastructuresr   r   r   r   r   r   r   r6   Útyping_extensionsr   r   rT   r^   r_   r&   r&   r&   r'   Ú<module>   s   ,  