L i#dZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZddlmZmZdd lmZmZdd lmZdd lmZdd lmZdd lmZddlmZe eddddGddZy)z[This module contains a class that describes a single parameter of a request to the Bot API.N)Sequence) dataclass)Optionalfinal)InputStoryContent) InputFile) InputMediaInputPaidMedia)InputProfilePhotoInputProfilePhotoStatic) InputSticker)TelegramObject) to_timestamp) StringEnum)UploadFileDictTF)repreqorderfrozenceZdZUdZdZeed<eed<ee e ed<e deefdZ e dee fdZededeee e ffd Zed ededdfd Zy ) RequestParameteraInstances of this class represent a single parameter to be sent along with a request to the Bot API. .. versionadded:: 20.0 Warning: This class intended is to be used internally by the library and *not* by the user. Changes to this class are not considered breaking changes and may not be documented in the changelog. Args: name (:obj:`str`): The name of the parameter. value (:obj:`object` | :obj:`None`): The value of the parameter. Must be JSON-dumpable. input_files (list[:class:`telegram.InputFile`], optional): A list of files that should be uploaded along with this parameter. Attributes: name (:obj:`str`): The name of the parameter. value (:obj:`object` | :obj:`None`): The value of the parameter. input_files (list[:class:`telegram.InputFile` | :obj:`None`): A list of files that should be uploaded along with this parameter. ) input_filesnamevaluerrrreturnct|jtr |jS|jytj|jS)zThe JSON dumped :attr:`value` or :obj:`None` if :attr:`value` is :obj:`None`. The latter can currently only happen if :attr:`input_files` has exactly one element that must not be uploaded via an attach:// URI. N) isinstancerstrjsondumps)selfs h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/request/_requestparameter.py json_valuezRequestParameter.json_valueFs< djj# &::  :: zz$**%%c|jsy|jDcic]'}|jxs |j|j)c}Scc}w)zA dict with the file data to upload, if any. .. versionchanged:: 21.5 Content may now be a file handle. N)r attach_namer field_tuple)r! input_files r"multipart_datazRequestParameter.multipart_dataRsR#..  # # 0tyy:3I3I I   s,A c<t|tjr t|gfSt|tjr1|j }|j r t|gfS|gfSt|tr|jgfSt|tr |jr|j|gfSd|gfSt|ttfrt|jtr|j}|jjr|jj|d<n|j!dd|j#dd}t|tr>|jr|j|d<n|j!dd||j|gfS||jgfSt|t$rft|t&rdnd}tt)||x}ts|jgfS|j}|j||<||gfSt|t*r^|j,}tt)||x}ts|jgfS|j}|j||<||gfSt|t.rRt|j0tr8|j}|j0j|d<||j0gfSt|t2r|jgfS|gfS)aXConverts `value` into something that we can json-dump. Returns two values: 1. the JSON-dumpable value. May be `None` in case the value is an InputFile which must not be uploaded via an attach:// URI 2. A list of InputFiles that should be uploaded for this value Note that we handle files differently depending on whether attaching them via an URI of the form attach:// is documented to be allowed or not. There was some confusion whether this worked for all files, so that we stick to the documented ways for now. See https://github.com/tdlib/telegram-bot-api/issues/167 and https://github.com/tdlib/telegram-bot-api/issues/259 This method only does some special casing for our own helper class StringEnum, but not for general enums. This is because: * tg.constants currently only uses IntEnum as second enum type and json dumping that is no problem * if a user passes a custom enum, it's unlikely that we can actually properly handle it even with some special casing. Nmedia thumbnailphoto animationsticker)rdtmdatetimer timedelta total_seconds is_integerintrrr attach_urir r r+to_dictpopgetr r getattrrtyper r/r)rsecondsdatar,attrr+s r"!_value_and_input_files_from_inputz2RequestParameter._value_and_input_files_from_input`s. eS\\ *&* * eS]] +))+G!!#7|R''B;  eZ (;;? " eY '''%00%= ej.9 :z%++W`?a==?D{{%% % 6 6W $'d3I)Y/''(1(<(rcsd&b $!"@/AX531+0 eD9k k :k r$