L idZddlmZddlmZmZmZmZmZm Z m Z m Z ddl m Z mZerddlmZmZede edeedf Ze d eed eeeeffd Ze d ed edeffd Zd ee d eeee edeedfffdZd e d eefdZd eed efdZ dde e dfdeeddeededed e edeff dZy)aThis 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_CHECKINGAnyOptionalTypeVarUnioncastoverload) FileInput FilePathInput) InputFileTelegramObject_TrN)boundobjreturncyNrs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/_utils/files.py load_filer*s>Acyrrrs rrr.s+.rc|y |j}t|}||fS#t$rdtd|fcYSwxYw)ztIf the input is a file handle, read the data and name and return it. Otherwise, return the input unchanged. N)NNz"Union[bytes, InputFile, str, Path])readAttributeErrorr guess_file_name)rcontentsfilenames rrr2sZ  {E88:s#H X  ET>DDDEs $>>ct|dr9t|jtst |jjSy)zgIf the input is a file handle, read name and return it. Otherwise, return the input unchanged. nameN)hasattr isinstancer#intrrs rrrEs2sFJsxx$=CHH~""" rc^|yt|} |jS#t$rYywxYw)zw Checks if a given string is a file on local system. Args: obj (:obj:`str`): The string to check. F)ris_file Exception)rpaths r is_local_filer+Os8 { 9D||~ s  ,, file_inputrtg_typer!attach local_modec"ddlm}t|tr |j dr|s t d|St|tt fr_t|rRt |}|r|jjS|jd5}||||cdddS|St|tr ||||St|d r|td |||S|rt||r |jS|S#1swY|SxYw) 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)rzfile://zBSpecified file input is a file URI, but local mode is not enabled.rb)mode)r!r.Nrr)telegramrr%str startswith ValueErrorrr+absoluteas_uriopenbytesr$r file_id)r,r-r!r.r/rr* file_handles rparse_file_inputr=`sR#*c"z'<'rEsc& SSS:2 Tuk3dBCD A2e9Ax}e';!<A A .2.%b/. . )  8C=%{Ct CD DE&x}x .4&15" >i!112> d+, ->sm>  >  >  3 S ! >r