
    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    U/Users/shanyulin/my-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88:: 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?     sF #Jsx$=$= #CH~~""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99D||~~   uu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            rt          |           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*cDj)) $$ 	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hvFFFFz6"" SydJ//(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WT@AAA 
 >2e9 >sTz5'8!9 > > > 
 > 
 .2 .%b/ . . . 
 .	
3:>>?   & sTz    }t+     & .2> >,>"#d*> Dj> 	>
 > > > > > > >r   