
    YiM                     p    S r SSKrSSKJrJrJr  SSKJr  SSKJ	r	J
r
  SSKJr  SSKJr  Sr " S	 S
5      rg)zDThis module contains an object that represents a Telegram InputFile.    N)IOOptionalUnion)uuid4)guess_file_name	load_file)TextEncoding)
FieldTuplezapplication/octet-streamc            	           \ rS rSrSrSr   SS\\\   \\	4   S\
\	   S\S\4S	 jjr\S
\4S j5       r\S
\
\	   4S j5       rSrg)	InputFile    a
  This object represents a Telegram InputFile.

.. versionchanged:: 20.0

    * The former attribute ``attach`` was renamed to :attr:`attach_name`.
    * Method ``is_image`` was removed. If you pass :obj:`bytes` to :paramref:`obj` and would
      like to have the mime type automatically guessed, please pass :paramref:`filename`
      in addition.

Args:
    obj (:term:`file object` | :obj:`bytes` | :obj:`str`): An open file descriptor or the files
        content as bytes or string.

        Note:
            If :paramref:`obj` is a string, it will be encoded as bytes via
            :external:obj:`obj.encode('utf-8') <str.encode>`.

        .. versionchanged:: 20.0
            Accept string input.
    filename (:obj:`str`, optional): Filename for this InputFile.
    attach (:obj:`bool`, optional): Pass :obj:`True` if the parameter this file belongs to in
        the request to Telegram should point to the multipart data via an ``attach://`` URI.
        Defaults to `False`.
    read_file_handle (:obj:`bool`, optional): If :obj:`True` and :paramref:`obj` is a file
        handle, the data will be read from the file handle on initialization of this object.
        If :obj:`False`, the file handle will be passed on to the
        :attr:`networking backend <telegram.request.BaseRequest.do_request>` which will have
        to handle the reading. Defaults to :obj:`True`.

        Tip:
            If you upload extremely large files, you may want to set this to :obj:`False` to
            avoid reading the complete file into memory. Additionally, this may be supported
            better by the networking backend (in particular it is handled better by
            the default :class:`~telegram.request.HTTPXRequest`).

        Important:
            If you set this to :obj:`False`, you have to ensure that the file handle is still
            open when the request is made. In particular, the following snippet can *not* work
            as expected.

            .. code-block:: python

                with open('file.txt', 'rb') as file:
                    input_file = InputFile(file, read_file_handle=False)

                # here the file handle is already closed and the upload will fail
                await bot.send_document(chat_id, input_file)

        .. versionadded:: 21.5


Attributes:
    input_file_content (:obj:`bytes` | :class:`IO`): The binary content of the file to send.
    attach_name (:obj:`str`): Optional. If present, the parameter this file belongs to in
        the request to Telegram should point to the multipart data via a an URI of the form
        ``attach://<attach_name>`` URI.
    filename (:obj:`str`): Filename for the file to be sent.
    mimetype (:obj:`str`): The mimetype inferred from the file to be sent.

)attach_namefilenameinput_file_contentmimetypeNobjr   attachread_file_handlec                 F   [        U[        5      (       a  Xl        Oy[        U[        5      (       a%  UR	                  [
        R                  5      U l        O?U(       a  [        U5      u  oPl        U=(       d    UnOXl        U=(       d    [        U5      nU(       a  S[        5       R                  -   OS U l        U(       a+  [        R                  " USS9S   =(       d    [        U l        O[        U l        U=(       d    U R                  R!                  SS5      U l        g )NattachedF)strictr   /.)
isinstancebytesr   strencoder	   UTF_8r   r   r   hexr   	mimetypes
guess_type_DEFAULT_MIME_TYPEr   replacer   )selfr   r   r   r   reported_filenames         D/app/.venv/lib/python3.13/site-packages/telegram/_files/inputfile.py__init__InputFile.__init__`   s     c5!!?B#S!!&)jj1C1C&DD#9B3664#4H&)#7?3#7HFL*uw{{*BRV$$Xe<Q?UCU M /DM%H)>)>sC)H    returnc                 H    U R                   U R                  U R                  4$ )zField tuple representing the contents of the file for upload to the Telegram servers.

.. versionchanged:: 21.5
    Content may now be a file handle.

Returns:
    tuple[:obj:`str`, :obj:`bytes` | :class:`IO`, :obj:`str`]:
)r   r   r   r$   s    r&   field_tupleInputFile.field_tuple}   s     }}d55t}}DDr)   c                 F    U R                   (       a  SU R                    3$ S$ )zuURI to insert into the JSON data for uploading the file. Returns :obj:`None`, if
:attr:`attach_name` is :obj:`None`.
z	attach://N)r   r,   s    r&   
attach_uriInputFile.attach_uri   s%    
 261A1A4++,-KtKr)   )NFT)__name__
__module____qualname____firstlineno____doc__	__slots__r   r   r   r   r   boolr'   propertyr
   r-   r0   __static_attributes__ r)   r&   r   r       s    ;z NI
 #'!%I2e9eS()I 3-I 	I
 I: 	EZ 	E 	E LHSM L Lr)   r   )r6   r    typingr   r   r   uuidr   telegram._utils.filesr   r   telegram._utils.stringsr	   telegram._utils.typesr
   r"   r   r;   r)   r&   <module>rA      s4   & K  & &  < 0 ,/ nL nLr)   