U
    Rh                     @   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eed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< eeedf dd fddZd0ee
edf ed fddZee
edf dd fddZdd fddZeed  eedef  ddd Zeed  eed!d"d#Zeeed d$d%d&Zesheee	ef dd'd(d)Zeeeed*d+d,Zeee eegef ed-d.d/Z   Z!S )1r   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.Zheadersz2The content type of the request, from the headers.Zcontent_typezA
                The bytes to write to the file.
                N)datareturnc                    s   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__ <./venv/lib/python3.8/site-packages/fastapi/datastructures.pyr   K   s    zUploadFile.writezL
                The number of bytes to read from the file.
                )r   r   c                    s   t  |I dH S )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.readzO
                The position in bytes to seek to in the file.
                )offsetr   c                    s   t  |I dH S )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   s    zUploadFile.seekr   c                    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.)clsr   c                 c   s   | j V  d S N)validate)r,   r#   r#   r$   __get_validators__   s    zUploadFile.__get_validators__)r,   vr   c                 C   s    t |tstdt| |S NzExpected UploadFile, received: )
isinstanceStarletteUploadFile
ValueErrortype)r,   r0   r#   r#   r$   r.      s    
zUploadFile.validate)_UploadFile__input_value_r   c                 C   s&   t |tstdt| tt|S r1   )r2   r3   r4   r5   r
   r   )r,   r6   r7   r#   r#   r$   	_validate   s    
zUploadFile._validate)field_schemar   c                 C   s   | ddd d S Nstringbinary)r5   format)update)r,   r9   r#   r#   r$   __modify_schema__   s    zUploadFile.__modify_schema__)core_schemahandlerr   c                 C   s
   dddS r:   r#   )r,   r@   rA   r#   r#   r$   __get_pydantic_json_schema__   s    z'UploadFile.__get_pydantic_json_schema__)sourcerA   r   c                 C   s
   t | jS r-   )r   r8   )r,   rC   rA   r#   r#   r$   __get_pydantic_core_schema__   s    z'UploadFile.__get_pydantic_core_schema__)r%   )"__name__
__module____qualname____doc__r   r   r   __annotations__r   strintr   bytesr   r&   r(   r*   classmethodr   r   r   r   r/   r.   r8   r   r   r?   r   r   r   rB   rD   __classcell__r#   r#   r!   r$   r      sz   
! "  r   c                   @   s<   e Zd ZdZedddZedddZeed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 r-   rP   )r    rQ   r#   r#   r$   __init__   s    zDefaultPlaceholder.__init__r)   c                 C   s
   t | jS r-   )boolrQ   r+   r#   r#   r$   __bool__   s    zDefaultPlaceholder.__bool__)or   c                 C   s   t |to|j| jkS r-   )r2   rO   rQ   )r    rU   r#   r#   r$   __eq__   s    zDefaultPlaceholder.__eq__N)
rE   rF   rG   rH   r   rR   rS   rT   objectrV   r#   r#   r#   r$   rO      s   rO   DefaultType)rQ   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.
    )rO   rP   r#   r#   r$   Default   s    rY   N)typingr   r   r   r   r   r   r   r	   r
   Zfastapi._compatr   r   r   r   r   Zstarlette.datastructuresr   r   r   r   r   r   r   r3   Ztyping_extensionsr   r   rO   rX   rY   r#   r#   r#   r$   <module>   s   , 