§
    ­eîi`  ã                   ó‚  — d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZ erddlmZ ddlmZmZ  edd¬	¦  «        Zed
ee         deedz  ef         fd„¦   «         Zed
ededef         fd„¦   «         Zd
ddeedz  df         fd„Zd
e
dedz  fd„Zd
edz  defd„Z	 	 	 	 dddded         dz  dedz  dededdfd„ZdS )a¾  This module contains helper functions related to handling of files.

.. versionchanged:: 20.0
   Previously, the contents of this module were available through the (no longer existing)
   module ``telegram._utils.helpers``.

Warning:
    Contents of this module are intended to be used internally by the library and *not* by the
    user. Changes to this module are not considered breaking changes and may not be documented in
    the changelog.
é    )ÚPath)ÚIOÚTYPE_CHECKINGÚTypeVarÚcastÚoverload)Ú	FileInputÚFilePathInput)ÚAny)Ú	InputFileÚTelegramObjectÚ_Tz%bytes | InputFile | str | Path | None)ÚboundÚobjÚreturnNc                 ó   — d S ©N© ©r   s    úY/home/div/.hermes/hermes-agent/venv/lib/python3.11/site-packages/telegram/_utils/files.pyÚ	load_filer   ,   s   € Ø;>¸3ó    c                 ó   — d S r   r   r   s    r   r   r   0   s   € Ø+.¨3r   zFileInput | Nonec                 ó    — | €dS 	 |                       ¦   «         }n"# t          $ r dt          d| ¦  «        fcY S w xY wt          | ¦  «        }||fS )ztIf the input is a file handle, read the data and name and return it. Otherwise, return
    the input unchanged.
    N)NNzbytes | InputFile | str | Path)ÚreadÚAttributeErrorr   Úguess_file_name)r   ÚcontentsÚfilenames      r   r   r   4   sx   € ð €{ØˆzðAØ—8’8‘:”:ˆˆøÝð Að Að AØ•TÐ:¸CÑ@Ô@Ð@Ð@Ð@Ð@ðAøøøõ ˜sÑ#Ô#€Hà�XÐÐs   † ›:¹:c                 óŒ   — t          | d¦  «        r3t          | j        t          ¦  «        st	          | j        ¦  «        j        S dS )zgIf the input is a file handle, read name and return it. Otherwise, return
    the input unchanged.
    ÚnameN)ÚhasattrÚ
isinstancer!   Úintr   r   s    r   r   r   G   s?   € õ ˆs�FÑÔð #¥J¨s¬x½Ñ$=Ô$=ð #Ý�C”H‰~Œ~Ô"Ð"àˆ4r   c                 ót   — | €dS t          | ¦  «        }	 |                     ¦   «         S # t          $ r Y dS w xY w)zw
    Checks if a given string is a file on local system.

    Args:
        obj (:obj:`str`): The string to check.
    NF)r   Úis_fileÚ	Exception)r   Úpaths     r   Úis_local_filer)   Q   sN   € ð €{Øˆuå�‰9Œ9€DðØ�|Š|‰~Œ~ÐøÝð ð ð Øˆuˆuðøøøs   •) ©
7¶7FÚ
file_inputzFileInput | TelegramObjectÚtg_typer   r   ÚattachÚ
local_modezstr | InputFile | Anyc                 óž  — ddl m} t          | t          ¦  «        r(|                      d¦  «        r|st          d¦  «        ‚| S t          | t          t          z  ¦  «        r„t          | ¦  «        rst          | ¦  «        }|r&|                     ¦   «          	                    ¦   «         S | 
                    d¬¦  «        5 } ||||¬¦  «        cddd¦  «         S # 1 swxY w Y   | S t          | t          ¦  «        r || ||¬¦  «        S t          | d	¦  «        r |t          d
| ¦  «        ||¬¦  «        S |rt          | |¦  «        r| j        S | S )aÙ  
    Parses input for sending files:

    * For string input, if the input is an absolute path of a local file:

        * if ``local_mode`` is ``True``, adds the ``file://`` prefix. If the input is a relative
        path of a local file, computes the absolute path and adds the ``file://`` prefix.
        * if ``local_mode`` is ``False``, loads the file as binary data and builds an
          :class:`InputFile` from that

      Returns the input unchanged, otherwise.
    * :class:`pathlib.Path` objects are treated the same way as strings.
    * For IO and bytes input, returns an :class:`telegram.InputFile`.
    * If :attr:`tg_type` is specified and the input is of that type, returns the ``file_id``
      attribute.

    Args:
        file_input (:obj:`str` | :obj:`bytes` | :term:`file object` | :class:`~telegram.InputFile`            | Telegram media object): The input to parse.
        tg_type (:obj:`type`, optional): The Telegram media type the input can be. E.g.
            :class:`telegram.Animation`.
        filename (:obj:`str`, optional): The filename. Only relevant in case an
            :class:`telegram.InputFile` is returned.
        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`. Only relevant if an :class:`telegram.InputFile` is returned.
        local_mode (:obj:`bool`, optional): Pass :obj:`True` if the bot is running an api server
            in ``--local`` mode.

    Returns:
        :obj:`str` | :class:`telegram.InputFile` | :obj:`object`: The parsed input or the untouched
        :attr:`file_input`, in case it's no valid file input.
    r   )r   zfile://zBSpecified file input is a file URI, but local mode is not enabled.Úrb)Úmode)r   r,   Nr   r   )Útelegramr   r#   ÚstrÚ
startswithÚ
ValueErrorr   r)   ÚabsoluteÚas_uriÚopenÚbytesr"   r   Úfile_id)r*   r+   r   r,   r-   r   r(   Úfile_handles           r   Úparse_file_inputr;   b   sÐ  € ðR #Ð"Ð"Ð"Ð"Ð"å�*�cÑ"Ô"ð  z×'<Ò'<¸YÑ'GÔ'Gð Øð 	cÝÐaÑbÔbÐbØÐÝ�*�c¥D™jÑ)Ô)ð Ý˜Ñ$Ô$ð 	PÝ˜
Ñ#Ô#ˆDØð 0Ø—}’}‘”×-Ò-Ñ/Ô/Ð/Ø—’ �Ñ%Ô%ð P¨Ø �y °xÈÐOÑOÔOðPð Pð Pð Pñ Pô Pð Pð Pð Pð Pð Pð Pøøøð Pð Pð Pð Pð ÐÝ�*�eÑ$Ô$ð GØˆy˜¨h¸vÐFÑFÔFÐFÝˆz˜6Ñ"Ô"ð SØˆy�˜d JÑ/Ô/¸(È6ÐRÑRÔRÐRØð "•:˜j¨'Ñ2Ô2ð "ØÔ!Ð!ØÐs   Â=CÃCÃC)NNFF)Ú__doc__Úpathlibr   Útypingr   r   r   r   r   Útelegram._utils.typesr	   r
   r   r1   r   r   r   r8   Útupler2   r   r   Úboolr)   Útyper;   r   r   r   ú<module>rC      s  ðð&
ð 
ð Ð Ð Ð Ð Ð Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =à :Ð :Ð :Ð :Ð :Ð :Ð :Ð :àð 3ØÐÐÐÐÐà2Ð2Ð2Ð2Ð2Ð2Ð2Ð2à€WˆTÐ@ÐAÑAÔA€ð 
Ø >�2�e”9Ð >  s¨T¡z°5Ð'8Ô!9Ð >Ð >Ð >ñ 
„Ø >ð 
Ø .�2Ð .˜%  b œ/Ð .Ð .Ð .ñ 
„Ø .ðØ	ðà
ˆ3�‰:Ð>Ð>Ô?ðð ð ð ð&˜ð  s¨T¡zð ð ð ð ð�} tÑ+ð °ð ð ð ð ð& .2ØØØð>ð >Ø,ð>àÐ"Ô# dÑ*ð>ð �D‰jð>ð ð	>ð
 ð>ð ð>ð >ð >ð >ð >ð >r   