
    i#                        d Z ddl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 ddlmZ ddlmZ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 e	 edddd           G d d                                  ZdS )z[This module contains a class that describes a single parameter of a request to the Bot API.    N)Sequence)	dataclass)final)InputStoryContent)	InputFile)
InputMediaInputPaidMedia)InputProfilePhotoInputProfilePhotoStatic)InputSticker)TelegramObject)to_timestamp)
StringEnum)UploadFileDictTF)repreqorderfrozenc                       e Zd ZU dZdZeed<   eed<   ee	         dz  ed<   e
dedz  fd            Ze
dedz  fd	            Zededeeee	         f         fd
            Zedededd fd            ZdS )RequestParametera  Instances 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_filesnamevaluer   r   Nr   returnc                     t          | j        t                    r| j        S | j        dS t          j        | j                  S )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)
isinstancer   strjsondumpsselfs    b/Users/shanyulin/my-agent/.venv/lib/python3.11/site-packages/telegram/request/_requestparameter.py
json_valuezRequestParameter.json_valueF   s?     dj#&& 	::4z$*%%%    c                 <      j         sdS  fd j         D             S )zA dict with the file data to upload, if any.

        .. versionchanged:: 21.5
            Content may now be a file handle.
        Nc                 8    i | ]}|j         pj        |j        S  )attach_namer   field_tuple).0
input_filer!   s     r"   
<dictcomp>z3RequestParameter.multipart_data.<locals>.<dictcomp>[   s8     
 
 
 #0ty:3I
 
 
r$   )r   r    s   `r"   multipart_datazRequestParameter.multipart_dataR   sC      	4
 
 
 
".
 
 
 	
r$   c                    t          | t          j                  rt          |           g fS t          | t          j                  r=|                                 }|                                rt          |          g fS |g fS t          | t                    r	| j	        g fS t          | t                    r| j        r
| j        | gfS d| gfS t          | t          t          z            rt          | j        t                    r|                                 }| j        j        r| j        j        |d<   n|                    dd           |                    dd          }t          |t                    r3|j        r|j        |d<   n|                    dd           || j        |gfS || j        gfS t          | t$                    rwt          | t&                    rdnd}t          t)          | |          x}t                    s|                                 g fS |                                 }|j        ||<   ||gfS t          | t*                    re| j        }t          t)          | |          x}t                    s|                                 g fS |                                 }|j        ||<   ||gfS t          | t.                    rGt          | j        t                    r-|                                 }| j        j        |d<   || j        gfS t          | t2                    r|                                 g fS | g fS )aX  Converts `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://<name> 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.
        Nmedia	thumbnailphoto	animationsticker)r   dtmdatetimer   	timedeltatotal_seconds
is_integerintr   r   r   
attach_urir   r	   r/   to_dictpopgetr
   r   getattrr   typer   r3   r   )r   secondsdatar0   attrr/   s         r"   !_value_and_input_files_from_inputz2RequestParameter._value_and_input_files_from_input`   s4   . eS\** 	+&&**eS]++ 	))++G!!## (7||R'' B;eZ(( 	#;?"eY'' 	! 1'%00%= eZ.899 	'jV_>`>` 	' ==??D{% ( % 6W$'''d33I)Y// 6' 0(1(<D%%HH[$///ek9555%+&&e.// 
	!(0GHHY77kDwud';';;eYGG +}}** ==??D)DJ%= e.// 
	!:Dwud';';;eYGG +}}** ==??D)DJ%= e\** 	)z%-/S/S 	) ==??D#m6DO%-((e^,, 	'==??B&&byr$   keyc                    t          |t          t          z            sxt          |t                    rcg }g }|D ]F}|                     |          \  }}||                    |           |                    |           Gt          |||r|nd          S |                     |          \  }}t          |||r|nd          S )zBuilds an instance of this class for a given key-value pair that represents the raw
        input as passed along from a method of :class:`telegram.Bot`.
        N)r   r   r   )r   r   bytesr   rC   appendextendr   )clsrD   r   param_valuesr   objparam_valuer+   s           r"   
from_inputzRequestParameter.from_input   s    
 %u-- 
	*UH2M2M 
	LK / /*-*O*OPS*T*T'Z* ''444"":....#:^++Z^    $'#H#H#O#O [KK5Y[[UY
 
 
 	
r$   )__name__
__module____qualname____doc__	__slots__r   __annotations__objectlistr   propertyr#   r   r-   staticmethodtuplerC   classmethodrM   r'   r$   r"   r   r   &   s         . 1I
IIIMMMi4''''	&C$J 	& 	& 	& X	& 
 5 
 
 
 X
 \\	vtI&	'\ \ \ \\| 
S 
 
4F 
 
 
 [
 
 
r$   r   )rQ   r5   r4   r   collections.abcr   dataclassesr   typingr   "telegram._files._inputstorycontentr   telegram._files.inputfiler   telegram._files.inputmediar   r	   !telegram._files.inputprofilephotor
   r   telegram._files.inputstickerr   telegram._telegramobjectr   telegram._utils.datetimer   telegram._utils.enumr   telegram._utils.typesr   r   r'   r$   r"   <module>rf      sm  & b a      $ $ $ $ $ $ ! ! ! ! ! !       @ @ @ @ @ @ / / / / / / A A A A A A A A X X X X X X X X 5 5 5 5 5 5 3 3 3 3 3 3 1 1 1 1 1 1 + + + + + + 0 0 0 0 0 0 
eD999k
 k
 k
 k
 k
 k
 k
 :9 k
 k
 k
r$   