§
    «eîiÆ=  ã                   ó¶   — d Z ddlZddlmZ ddlmZ ddlmZ ddl	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mZmZ e
rddlmZ  G d„ de¦  «        ZdS )z?This module contains an object that represents a Telegram File.é    N)Ú	b64decode)ÚPath)ÚTYPE_CHECKINGÚBinaryIO)Údecrypt)ÚTelegramObject)ÚDEFAULT_NONE)Úis_local_file)ÚFilePathInputÚJSONDictÚODVInput)ÚFileCredentialsc                   ó¦  ‡ — e Zd ZdZdZ	 	 dddœdedededz  dedz  d	edz  f
ˆ fd
„Zdefd„Z	de
de
fd„Z	 deeeedœdedz  dee         dee         dee         dee         defd„Zeeeedœdedee         dee         dee         dee         ddfd„Z	 deeeedœdedz  dee         dee         dee         dee         defd„Zdd„Zˆ xZS )ÚFilea´  
    This object represents a file ready to be downloaded. The file can be e.g. downloaded with
    :attr:`download_to_drive`. It is guaranteed that the link will be valid for at least 1 hour.
    When the link expires, a new one can be requested by calling :meth:`telegram.Bot.get_file`.

    Objects of this class are comparable in terms of equality. Two objects of this class are
    considered equal, if their :attr:`file_unique_id` is equal.

    .. versionchanged:: 20.0
        ``download`` was split into :meth:`download_to_drive` and :meth:`download_to_memory`.

    Note:
        * Maximum file size to download is
          :tg-const:`telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD`.
        * If you obtain an instance of this class from :attr:`telegram.PassportFile.get_file`,
          then it will automatically be decrypted as it downloads when you call e.g.
          :meth:`download_to_drive`.

    Args:
        file_id (:obj:`str`): Identifier for this file, which can be used to download
            or reuse the file.
        file_unique_id (:obj:`str`): Unique identifier for this file, which
            is supposed to be the same over time and for different bots.
            Can't be used to download or reuse the file.
        file_size (:obj:`int`, optional): File size in bytes, if known.
        file_path (:obj:`str`, optional): File path. Use e.g. :meth:`download_to_drive` to get the
            file.

    Attributes:
        file_id (:obj:`str`): Identifier for this file, which can be used to download
            or reuse the file.
        file_unique_id (:obj:`str`): Unique identifier for this file, which
            is supposed to be the same over time and for different bots.
            Can't be used to download or reuse the file.
        file_size (:obj:`int`): Optional. File size in bytes, if known.
        file_path (:obj:`str`): Optional. File path. Use e.g. :meth:`download_to_drive` to get the
            file.
    )Ú_credentialsÚfile_idÚ	file_pathÚ	file_sizeÚfile_unique_idN©Ú
api_kwargsr   r   r   r   r   c                ó  •— t          ¦   «                              |¬¦  «         t          |¦  «        | _        t          |¦  «        | _        || _        || _        d | _        | j        f| _        |  	                    ¦   «          d S )Nr   )
ÚsuperÚ__init__Ústrr   r   r   r   r   Ú	_id_attrsÚ_freeze)Úselfr   r   r   r   r   Ú	__class__s         €úX/home/div/.hermes/hermes-agent/venv/lib/python3.11/site-packages/telegram/_files/file.pyr   zFile.__init__U   ss   ø€ õ 	‰Œ×Ò JÐÑ/Ô/Ð/õ   ™LœLˆŒÝ#& ~Ñ#6Ô#6ˆÔà%.ˆŒØ%.ˆŒà48ˆÔàÔ-Ð/ˆŒà�Š‰Œˆˆˆó    Úreturnc           	      óø   — t          j        t          | j        ¦  «        ¦  «        }t          j        t          j        |j        |j        t          j        |j	        ¦  «        |j
        |j        ¦  «        ¦  «        S )zPConvert any UTF-8 char in :obj:`File.file_path` into a url encoded ASCII string.)Úurllib_parseÚurlsplitr   r   Ú
urlunsplitÚSplitResultÚschemeÚnetlocÚquoteÚpathÚqueryÚfragment)r   Úsress     r    Ú_get_encoded_urlzFile._get_encoded_urlm   sc   € åÔ$¥S¨¬Ñ%8Ô%8Ñ9Ô9ˆÝÔ&ÝÔ$Ø”˜Tœ[­,Ô*<¸T¼YÑ*GÔ*GÈÌÐUYÔUbñô ñ
ô 
ð 	
r!   Úbufc                 ó€   — t          t          | j        j        ¦  «        t          | j        j        ¦  «        |¦  «        S ©N)r   r   r   ÚsecretÚhash)r   r0   s     r    Ú_prepare_decryptzFile._prepare_decryptv   s1   € Ý•y Ô!2Ô!9Ñ:Ô:½IÀdÔFWÔF\Ñ<]Ô<]Ð_bÑcÔcÐcr!   ©Úread_timeoutÚwrite_timeoutÚconnect_timeoutÚpool_timeoutÚcustom_pathr7   r8   r9   r:   c             ƒ   ó   K  — | j         st          d¦  «        ‚t          | j         ¦  «        }|rdn|                      ¦   «         }|r—| j        r�t          | j         ¦  «        }|                      |                     ¦   «         ¦  «        }	|�t          |¦  «        }
n,t          t          |j	        ¦  «        dz   |j
        z   ¦  «        }
|
                     |	¦  «         |
S |�8|r6t          j        | j         t          |¦  «        ¦  «         t          |¦  «        S |rt          |¦  «        }n<|rt          | j         ¦  «        S t          t          | j         ¦  «        j
        ¦  «        }|                      ¦   «         j                             |||||¬¦  «        ƒ d{V —†}	| j        r|                      |	¦  «        }	|                     |	¦  «         |S )aó  
        Download this file. By default, the file is saved in the current working directory with
        :attr:`file_path` as file name. If :paramref:`custom_path` is supplied as a :obj:`str` or
        :obj:`pathlib.Path`, it will be saved to that path.

        Note:
            If :paramref:`custom_path` isn't provided and :attr:`file_path` is the path of a
            local file (which is the case when a Bot API Server is running in local mode), this
            method will just return the path.

            The only exception to this are encrypted files (e.g. a passport file). For these, a
            file with the prefix `decrypted_` will be created in the same directory as the
            original file in order to decrypt the file without changing the existing one
            in-place.

        .. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`

        .. versionchanged:: 20.0

            * :paramref:`custom_path` parameter now also accepts :class:`pathlib.Path` as argument.
            * Returns :class:`pathlib.Path` object in cases where previously a :obj:`str` was
              returned.
            * This method was previously called ``download``. It was split into
              :meth:`download_to_drive` and :meth:`download_to_memory`.

        .. versionchanged:: 21.7
            Raises :exc:`RuntimeError` if :attr:`file_path` is not set. Note that files without
            a :attr:`file_path` could never be downloaded, as this attribute is mandatory for that
            operation.

        Args:
            custom_path (:class:`pathlib.Path` | :obj:`str` , optional): The path where the file
                will be saved to. If not specified, will be saved in the current working directory
                with :attr:`file_path` as file name or the :attr:`file_id` if :attr:`file_path`
                is not set.

        Keyword Args:
            read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
            write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
            connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
            pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

        Returns:
            :class:`pathlib.Path`: Returns the Path object the file was downloaded to.

        Raises:
            RuntimeError: If :attr:`file_path` is not set.

        ú9No `file_path` available for this file. Can not download.Nz/decrypted_r6   )r   ÚRuntimeErrorr
   r/   r   r   r5   Ú
read_bytesr   ÚparentÚnameÚwrite_bytesÚshutilÚcopyfileÚget_botÚrequestÚretrieve)r   r;   r7   r8   r9   r:   Ú
local_fileÚurlÚfile_to_decryptr0   r+   Úfilenames               r    Údownload_to_drivezFile.download_to_drivey   sê  è è € ðD Œ~ð 	\ÝÐZÑ[Ô[Ð[å" 4¤>Ñ2Ô2ˆ
Ø Ð=ˆdˆd d×&;Ò&;Ñ&=Ô&=ˆð ð 	˜$Ô+ð 	Ý" 4¤>Ñ2Ô2ˆOØ×'Ò'¨×(BÒ(BÑ(DÔ(DÑEÔEˆCØÐ&Ý˜KÑ(Ô(��å�C Ô 6Ñ7Ô7¸-ÑGÈ/ÔJ^Ñ^Ñ_Ô_�Ø×Ò˜SÑ!Ô!Ð!ØˆKàÐ" zÐ"ÝŒO˜DœN­C°Ñ,<Ô,<Ñ=Ô=Ð=Ý˜Ñ$Ô$Ð$àð 	7Ý˜KÑ(Ô(ˆHˆHØð 	7Ý˜œÑ'Ô'Ð'å�D ¤Ñ0Ô0Ô5Ñ6Ô6ˆHà—L’L‘N”NÔ*×3Ò3ØØ%Ø'Ø+Ø%ð 4ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð Ôð 	-Ø×'Ò'¨Ñ,Ô,ˆCØ×Ò˜SÑ!Ô!Ð!Øˆr!   Úoutc             ƒ   ó¼  K  — | j         st          d¦  «        ‚t          | j         ¦  «        }|rdn|                      ¦   «         }|rt	          | j         ¦  «        nd}|r|                     ¦   «         }	n7|                      ¦   «         j                             |||||¬¦  «        ƒ d{V —†}	| j	        r|  
                    |	¦  «        }	|                     |	¦  «         dS )aÕ  
        Download this file into memory. :paramref:`out` needs to be supplied with a
        :obj:`io.BufferedIOBase`, the file contents will be saved to that object using the
        :obj:`out.write<io.BufferedIOBase.write>` method.

        .. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`

        Hint:
            If you want to immediately read the data from ``out`` after calling this method, you
            should call ``out.seek(0)`` first. See also :meth:`io.IOBase.seek`.

        .. versionadded:: 20.0

        .. versionchanged:: 21.7
            Raises :exc:`RuntimeError` if :attr:`file_path` is not set. Note that files without
            a :attr:`file_path` could never be downloaded, as this attribute is mandatory for that
            operation.

        Args:
            out (:obj:`io.BufferedIOBase`): A file-like object. Must be opened for writing in
                binary mode.

        Keyword Args:
            read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
            write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
            connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
            pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

        Raises:
            RuntimeError: If :attr:`file_path` is not set.
        r=   Nr6   )r   r>   r
   r/   r   r?   rE   rF   rG   r   r5   Úwrite)
r   rM   r7   r8   r9   r:   rH   rI   r+   r0   s
             r    Údownload_to_memoryzFile.download_to_memoryã   s  è è € ð` Œ~ð 	\ÝÐZÑ[Ô[Ð[å" 4¤>Ñ2Ô2ˆ
Ø Ð=ˆdˆd d×&;Ò&;Ñ&=Ô&=ˆØ'1Ð;�t�D”NÑ#Ô#Ð#°tˆØð 		Ø—/’/Ñ#Ô#ˆCˆCàŸš™œÔ.×7Ò7ØØ)Ø+Ø /Ø)ð 8ñ ô ð ð ð ð ð ð ˆCð Ôð 	-Ø×'Ò'¨Ñ,Ô,ˆCØ�	Š	�#‰Œˆˆˆr!   c             ƒ   óè  K  — | j         st          d¦  «        ‚|€t          ¦   «         }t          | j         ¦  «        r't	          | j         ¦  «                             ¦   «         }nI|                      ¦   «         j                             |  	                    ¦   «         ||||¬¦  «        ƒ d{V —†}| j
        r)|                     |                      |¦  «        ¦  «         n|                     |¦  «         |S )a  Download this file and return it as a bytearray.

        .. versionchanged:: 21.7
            Raises :exc:`RuntimeError` if :attr:`file_path` is not set. Note that files without
            a :attr:`file_path` could never be downloaded, as this attribute is mandatory for that
            operation.

        Args:
            buf (:obj:`bytearray`, optional): Extend the given bytearray with the downloaded data.

        Keyword Args:
            read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. versionadded:: 20.0
            write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. versionadded:: 20.0
            connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. versionadded:: 20.0
            pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
                :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
                :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

                .. versionadded:: 20.0

        Returns:
            :obj:`bytearray`: The same object as :paramref:`buf` if it was specified. Otherwise a
            newly allocated :obj:`bytearray`.

        Raises:
            RuntimeError: If :attr:`file_path` is not set.

        r=   Nr6   )r   r>   Ú	bytearrayr
   r   r?   rE   rF   rG   r/   r   Úextendr5   )r   r0   r7   r8   r9   r:   Ú
bytes_datas          r    Údownload_as_bytearrayzFile.download_as_bytearray'  s  è è € ðb Œ~ð 	\ÝÐZÑ[Ô[Ð[àˆ;Ý‘+”+ˆCå˜œÑ(Ô(ð 		Ý˜dœnÑ-Ô-×8Ò8Ñ:Ô:ˆJˆJà#Ÿ|š|™~œ~Ô5×>Ò>Ø×%Ò%Ñ'Ô'Ø)Ø+Ø /Ø)ð  ?ñ  ô  ð ð ð ð ð ð ˆJð Ôð 	#Ø�JŠJ�t×,Ò,¨ZÑ8Ô8Ñ9Ô9Ð9Ð9à�JŠJ�zÑ"Ô"Ð"Øˆ
r!   Úcredentialsr   c                 ó   — || _         dS )z‘Sets the passport credentials for the file.

        Args:
            credentials (:class:`telegram.FileCredentials`): The credentials.
        N)r   )r   rV   s     r    Úset_credentialszFile.set_credentialsn  s   € ð (ˆÔÐÐr!   )NNr2   )rV   r   r"   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   Úintr   r   r/   Úbytesr5   r	   r   r   Úfloatr   rL   r   rP   rR   rU   rX   Ú__classcell__)r   s   @r    r   r   %   s§  ø€ € € € € ð%ð %ðN€Ið !%Ø $ðð '+ðð ð àðð ðð ˜‘:ð	ð
 ˜‘:ðð ˜t‘Oðð ð ð ð ð ð0
 #ð 
ð 
ð 
ð 
ðd Eð d¨eð dð dð dð dð
 -1ðhð )5Ø)5Ø+7Ø(4ðhð hð hà" TÑ)ðhð ˜u”oð	hð
   ”ðhð " %œðhð ˜u”oðhð 
ðhð hð hð hð\ )5Ø)5Ø+7Ø(4ðBð Bð BàðBð ˜u”oð	Bð
   ”ðBð " %œðBð ˜u”oðBð 
ðBð Bð Bð BðL !%ðEð )5Ø)5Ø+7Ø(4ðEð Eð Eà˜ÑðEð ˜u”oð	Eð
   ”ðEð " %œðEð ˜u”oðEð 
ðEð Eð Eð EðN(ð (ð (ð (ð (ð (ð (ð (r!   r   )r\   rC   Úurllib.parseÚparser$   Úbase64r   Úpathlibr   Útypingr   r   Útelegram._passport.credentialsr   Útelegram._telegramobjectr   Útelegram._utils.defaultvaluer	   Útelegram._utils.filesr
   Útelegram._utils.typesr   r   r   Útelegramr   r   © r!   r    ú<module>rn      s#  ðð& FÐ Eà €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *à 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø /Ð /Ð /Ð /Ð /Ð /Ø CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ CÐ Càð )Ø(Ð(Ð(Ð(Ð(Ð(ðO(ð O(ð O(ð O(ð O(ˆ>ñ O(ô O(ð O(ð O(ð O(r!   