L iwUdZddlZddlZddlZddlZddlmZmZm Z ddlm Z ddl m Z ddl mZddlmZddlmZmZmZmZmZmZmZdd lmZdd lmZdd lmZdd lm Z erdd l!m"Z"edddZ#eddZ$GddZ%iddddddddddddddddd dd!dd"dd#dd$d%d&d'd(d)d*d+d,d-d.d/d.d0d1d.d2Z&e'e(e)e(d3ffe*d4<y)5z Base class for Telegram Objects.N)IteratorMappingSized)contextmanager)deepcopy)chain)MappingProxyType) TYPE_CHECKINGAnyClassVarOptionalTypeVarUnioncast) to_timestamp) DefaultValue)JSONDict)warn)BotTele_coTelegramObjectT)bound covariantTele)rceZdZUdZdZeZeeee d<dZ e e de d<ddde e ddfd Zd edeffd Zdeffd Zd ededdffd Zd eddffd ZdefdZdedefdZdeeeeefffdZdeeefddfdZdedeeefdefdZede de fdZe d3de ede de dde e def dZ!e d3de ede de ddefd Z"e d3de ede#e de dde$ed!ffd"Z%e&de'de(e'fd#Z)d4d$Z*d4d%Z+de ddfd&Z,d'edefd(Z-d)ede(efd*Z. d5d)ed+ed,ed-edeeeeefff d.Z/defd/Z0d6d+ede fd0Z1d7d1Z2de dddfd2Z3xZ4S)8raBase class for most Telegram objects. Objects of this type are subscriptable with strings. See :meth:`__getitem__` for more details. The :mod:`pickle` and :func:`~copy.deepcopy` behavior of objects of this type are defined by :meth:`__getstate__`, :meth:`__setstate__` and :meth:`__deepcopy__`. Tip: Objects of this type can be serialized via Python's :mod:`pickle` module and pickled objects from one version of PTB are usually loadable in future versions. However, we can not guarantee that this compatibility will always be provided. At least a manual one-time conversion of the data may be needed on major updates of the library. .. versionchanged:: 20.0 * Removed argument and attribute ``bot`` for several subclasses. Use :meth:`set_bot` and :meth:`get_bot` instead. * Removed the possibility to pass arbitrary keyword arguments for several subclasses. * String representations objects of this type was overhauled. See :meth:`__repr__` for details. As this class doesn't implement :meth:`object.__str__`, the default implementation will be used, which is equivalent to :meth:`__repr__`. * Objects of this class (or subclasses) are now immutable. This means that you can't set or delete attributes anymore. Moreover, attributes that were formerly of type :obj:`list` are now of type :obj:`tuple`. Arguments: api_kwargs (dict[:obj:`str`, any], optional): |toapikwargsarg| .. versionadded:: 20.0 Attributes: api_kwargs (:obj:`types.MappingProxyType` [:obj:`str`, any]): |toapikwargsattr| .. versionadded:: 20.0 )_bot_frozen _id_attrs api_kwargs_TelegramObject__INIT_PARAMSN"_TelegramObject__INIT_PARAMS_CHECK)rrreturncVd|_d|_d|_t|xsi|_y)NF)rrrr r)selfrs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/_telegramobject.py__init__zTelegramObject.__init__[s* # -/#' -=j>NB-OothercDt||jr{|js%td|jjdd|js%td|jjdd|j|jk(St ||S)aCompares this object with :paramref:`other` in terms of equality. If this object and :paramref:`other` are `not` objects of the same class, this comparison will fall back to Python's default implementation of :meth:`object.__eq__`. Otherwise, both objects may be compared in terms of equality, if the corresponding subclass of :class:`TelegramObject` has defined a set of attributes to compare and the objects are considered to be equal, if all of these attributes are equal. If the subclass has not defined a set of attributes to compare, a warning will be issued. Tip: If instances of a class in the :mod:`telegram` module are comparable in terms of equality, the documentation of the class will state the attributes that will be used for this comparison. Args: other (:obj:`object`): The object to compare with. Returns: :obj:`bool` Objects of type z0 can not be meaningfully tested for equivalence.) stacklevel) isinstance __class__rr__name__super__eq__)r%r)r/s r&r2zTelegramObject.__eq__fs* eT^^ ,>>&t~~'>'>&?@$$  ??&u'?'?&@A((  >>U__4 4w~e$$r(cz|jr!t|j|jfSt|S)zBuilds a hash value for this object such that the hash of two objects is equal if and only if the objects are equal in terms of :meth:`__eq__`. Returns: :obj:`int` )rhashr/r1__hash__)r%r/s r&r5zTelegramObject.__hash__s2 >>89 9w!!r(keyvaluec|ddk(s t|ddst| ||ytd|d|jj d) zOverrides :meth:`object.__setattr__` to prevent the overriding of attributes. Raises: :exc:`AttributeError` r_rTN Attribute ` ` of class `z` can't be set!)getattrr1 __setattr__AttributeErrorr/r0)r%r6r7r/s r&r=zTelegramObject.__setattr__sW q6S=i > G U + #l4>>+B+B*C? S  r(c|ddk(s t|ddst| |ytd|d|jj d) zOverrides :meth:`object.__delattr__` to prevent the deletion of attributes. Raises: :exc:`AttributeError` rr9rTNr:r;z` can't be deleted!)r<r1 __delattr__r>r/r0)r%r6r/s r&r@zTelegramObject.__delattr__sV q6S=i > G  $ #l4>>+B+B*CCV W  r(c2|jdd|jsjddnt|jd<dj fdt j D}|jjd|dS) aGives a string representation of this object in the form ``ClassName(attr_1=value_1, attr_2=value_2, ...)``, where attributes are omitted if they have the value :obj:`None` or are empty instances of :class:`collections.abc.Sized` (e.g. :class:`list`, :class:`dict`, :class:`set`, :class:`str`, etc.). As this class doesn't implement :meth:`object.__str__`, the default implementation will be used, which is equivalent to :meth:`__repr__`. Returns: :obj:`str` F) recursiveinclude_privaterNz, c3K|]7}|0t|trt|dk(s |d|9yw)Nr=)r.rlen).0kas_dicts r& z*TelegramObject.__repr__..sO   &wqz51c'!*o6J c71:. !  s=A()) _get_attrsrpopdictjoinsortedkeysr/r0)r%contentsrIs @r&__repr__zTelegramObject.__repr__s //E5/I KK d +%)$9GL !99  GLLN+   ..))*!H:Q77r(itemc|dk(rd} t||S#t$r,}td|jjd|d|d}~wwxYw)a Objects of this type are subscriptable with strings, where ``telegram_object["attribute_name"]`` is equivalent to ``telegram_object.attribute_name``. Tip: This is useful for dynamic attribute lookup, i.e. ``telegram_object[arg]`` where the value of ``arg`` is determined at runtime. In all other cases, it's recommended to use the dot notation instead, i.e. ``telegram_object.attribute_name``. .. versionchanged:: 20.0 ``telegram_object['from']`` will look up the key ``from_user``. This is to account for special cases like :attr:`Message.from_user` that deviate from the official Bot API. Args: item (:obj:`str`): The name of the attribute to look up. Returns: :obj:`object` Raises: :exc:`KeyError`: If the object does not have an attribute with the appropriate name. from from_userr+z! don't have an attribute called `z`.N)r<r>KeyErrorr/r0)r%rUexcs r& __getitem__zTelegramObject.__getitem__sg2 6>D 4& & "4>>#:#:";<6  s  A 'AA c`|jdddd}t|j|d<|S)an Overrides :meth:`object.__getstate__` to customize the pickling process of objects of this type. The returned state does `not` contain the :class:`telegram.Bot` instance set with :meth:`set_bot` (if any), as it can't be pickled. Returns: state (dict[:obj:`str`, :obj:`object`]): The state of the object. TF)rCrB remove_botconvert_default_valuer)rMrOr)r%outs r& __getstate__zTelegramObject.__getstate__s;oo EdZ_  !1L r(statec &|jd|_td|jdi}|jdd}|j D]\}} t ||||j|t||_|r|jyy#t $rftt|j|dtr& t |d||n'#t $r|||<YnwxYw|jdrY|||<YwxYw)a6 Overrides :meth:`object.__setstate__` to customize the unpickling process of objects of this type. Modifies the object in-place. If any data was stored in the :attr:`api_kwargs` of the pickled object, this method checks if the class now has dedicated attributes for those keys and moves the values from :attr:`api_kwargs` to the dedicated attributes. This can happen, if serialized data is loaded with a new version of this library, where the new version was updated to account for updates of the Telegram Bot API. If on the contrary an attribute was removed from the class, the value is not discarded but made available via :attr:`api_kwargs`. Args: state (:obj:`dict`): The data to set as attributes of this object. Nzdict[str, object]rrFr9) _unfreezerrrNitemssetattrr>r.r<r/property startswith_apply_api_kwargsr r_freeze)r%rarfrozenr6vals r& __setstate__zTelegramObject.__setstate__s"  -uyyr/JK 9e,  &HC &c3' &. z**:6  LLN 5" &gdnnc4@(K.#i5*.*- 3.^^C("% 3 &s< B!!.DC! D!C2/D1C22DDDr%memodictc .|j}|jd|j}|j|}||t |<d|_|j dD]c}|dk(r |dk(r4t||ttt|j|B t||tt|||e|j r|j|j||j||S#t$rYwxYw)a@ Customizes how :func:`copy.deepcopy` processes objects of this type. The only difference to the default implementation is that the :class:`telegram.Bot` instance set via :meth:`set_bot` (if any) is not copied, but shared between the original and the copy, i.e.:: assert telegram_object.get_bot() is copy.deepcopy(telegram_object).get_bot() Args: memodict (:obj:`dict`): A dictionary that maps objects to their copies. Returns: :class:`telegram.TelegramObject`: The copied object. NFTrCrr)rset_botr/__new__idr_get_attrs_namesrer rrOrr<r>ri)r%rmbotclsresultrHs r& __deepcopy__zTelegramObject.__deepcopy__Jsii TnnS!#D&&t&< AI~L #3HT$//=RT\4]#^_ 8GD!,c#hN&&c1#--c2 $' (<(<(A(A(C$D!*-'#)rJ(*O"jjl [ UUZC3+<+<$<*cR [???C @s " CBCCc(|j||S)aConverts JSON data to a Telegram object. Args: data (dict[:obj:`str`, ...]): The JSON data. bot (:class:`telegram.Bot`, optional): The bot associated with this object. Defaults to :obj:`None`, in which case shortcut methods will not be available. .. versionchanged:: 21.4 :paramref:`bot` is now optional and defaults to :obj:`None` Returns: The Telegram object. )rxrt)rrurxrts r&de_jsonzTelegramObject.de_jsons ||3|//r(.c0tfd|DS)aConverts a list of JSON objects to a tuple of Telegram objects. .. versionchanged:: 20.0 * Returns a tuple instead of a list. * Filters out any :obj:`None` values. Args: data (list[dict[:obj:`str`, ...]]): The JSON data. bot (:class:`telegram.Bot`, optional): The bot associated with these object. Defaults to :obj:`None`, in which case shortcut methods will not be available. .. versionchanged:: 21.4 :paramref:`bot` is now optional and defaults to :obj:`None` Returns: A tuple of Telegram objects. c3BK|]}j|ywN)r)rGdrtrus r&rJz)TelegramObject.de_list..s7QS[[C(7s)tuplers` `r&de_listzTelegramObject.de_lists.7$777r(c#TK|j||jyw)zContext manager to temporarily unfreeze the object. For internal use only. Note: with to._unfrozen() as other_to: assert to is other_to N)rcrir%s r& _unfrozenzTelegramObject._unfrozens    s&(cd|_y)NTrrs r&rizTelegramObject._freezes  r(cd|_y)NFrrs r&rczTelegramObject._unfreezes  r(c zt|jD]}tt|j|dt rBt jt5t|d||j|dddjt||dxt|||j|y#1swYxYw)abLoops through the api kwargs and for every key that exists as attribute of the object (and is None), it moves the value from `api_kwargs` to the attribute. *Edits `api_kwargs` in place!* This method is currently only called in the unpickling process, i.e. not on "normal" init. This is because * automating this is tricky to get right: It should be called at the *end* of the __init__, preferably only once at the end of the __init__ of the last child class. This could be done via __init_subclass__, but it's hard to not destroy the signature of __init__ in the process. * calling it manually in every __init__ is tedious * There probably is no use case for it anyway. If you manually initialize a TO subclass, then you can pass everything as proper argument. Nr9T) listrRr.r<r/rf contextlibsuppressr>rerN)r%rr6s r&rhz TelegramObject._apply_api_kwargss  )* 8C'$..#t>##67 8BBs  B11B: attrcX|jjx}tvxr |t|vS)zJChecks whether `attr` is in the list of deprecated time period attributes.)r/r0_TIME_PERIOD_DEPRECATIONS)r%r class_names r&_is_deprecated_attrz"TelegramObject._is_deprecated_attrs8..11 1J &'Y+/3LZ3X+X Yr(rCcdjjddD}tdr$t|jj n|}|r|Sfd|DS)ay Returns the names of the attributes of this object. This is used to determine which attributes should be serialized when pickling the object. Args: include_private (:obj:`bool`): Whether to include private attributes. Returns: Iterator[:obj:`str`]: An iterator over the names of the attributes of this object. c3BK|]}|jD]}|ywr) __slots__)rGcss r&rJz2TelegramObject._get_attrs_names.. s Q1Q[[QQQQQsN__dict__c3fK|](}|jdrj|r|*yw)r9N)rgr)rGrr%s r&rJz2TelegramObject._get_attrs_names..s2 ??3'4+C+CD+I  s.1)r/__mro__hasattrrrrR)r%rC all_slots all_attrss` r&rszTelegramObject._get_attrs_namesshR 6 6s ;Q 7>dJ6OE)T]]//1 2U^    !  r(rBr]r^cvi}|j|D]e}|r tjt||dn t||d}|*|r"t |dr|j d||<X|||<^|ra|||<g|r&|j dr|jdd|d<|r|jdd|S) aThis method is used for obtaining the attributes of the object. Args: include_private (:obj:`bool`): Whether the result should include private variables. recursive (:obj:`bool`): If :obj:`True`, will convert any ``TelegramObjects`` (if found) in the attributes to a dictionary. Else, preserves it as an object itself. remove_bot (:obj:`bool`): Whether the bot should be included in the result. convert_default_value (:obj:`bool`): Whether :class:`telegram.DefaultValue` should be converted to its true value. This is necessary when converting to a dictionary for end users since DefaultValue is used in some classes that work with `tg.ext.defaults` (like `LinkPreviewOptions`) Returns: :obj:`dict`: A dict where the keys are attribute names and values are their values. roNto_dictTrBrXrWr)rsr get_valuer<rrgetrN)r%rCrBr]r^rxr6r7s r&rMzTelegramObject._get_attrss,(((I "C)&&wtS$'?@T3-    !: %  =DI %DI!S  " +.88K6DL  HHVT " r(cHtj|jS)zGives a JSON representation of object. .. versionchanged:: 20.0 Now includes all entries of :attr:`api_kwargs`. Returns: :obj:`str` )jsondumpsrrs r&to_jsonzTelegramObject.to_jsonGszz$,,.))r(c |j|}t}i}|jD]g\}}t|tt fr|s|j |1g}|D]}t|dr"|j|j|1t|tt fr>|j|D cgc]"} t| dr| j|n| $c} |j||||<t|tjrt|||<t|tjs|jx} jr t!| n| ||j#d<|j |j|D]}|j%||j'||j'|j%di|Scc} w)a:Gives representation of object as :obj:`dict`. .. versionchanged:: 20.0 * Now includes all entries of :attr:`api_kwargs`. * Attributes whose values are empty sequences are no longer included. Args: recursive (:obj:`bool`, optional): If :obj:`True`, will convert any TelegramObjects (if found) in the attributes to a dictionary. Else, preserves it as an object itself. Defaults to :obj:`True`. .. versionadded:: 20.0 Returns: :obj:`dict` rrr9r)rMrrdr.rraddrappendrdtmdatetimer timedelta total_seconds is_integerint removeprefixrNupdate) r%rBr_pop_keystimedelta_dictr6r7rkrUisecondss r&rzTelegramObject.to_dictRs$oo o2 !U!))+$ "JC%%/LL%! )DtY/ 4<<)<#DE#D5$-8 *.$%CJ!YBW I >]^ ^ 4( )CE3<<0'.CE3==1160C0C0E%EW$Q$Q$SCLY`s//45  S!I$ "L C GGCL  >" 377<,- Cs:'G& cH|j td|jS)zReturns the :class:`telegram.Bot` instance associated with this object. .. seealso:: :meth:`set_bot` .. versionadded: 20.0 Raises: RuntimeError: If no :class:`telegram.Bot` instance was set for this object. zDThis object has no bot associated with it. Shortcuts cannot be used.)r RuntimeErrorrs r&get_botzTelegramObject.get_bots* 99 V yyr(c||_y)zSets the :class:`telegram.Bot` instance associated with this object. .. seealso:: :meth:`get_bot` .. versionadded: 20.0 Arguments: bot (:class:`telegram.Bot` | :obj:`None`): The bot instance. N)r)r%rts r&rpzTelegramObject.set_bots  r(r)r"N)FFFT)T)r"r)5r0 __module__ __qualname____doc__rrr r r~__annotations__r!r typerr'objectboolr2rr5r=r@rTr[rOrr`rlrrw staticmethodr{ classmethodrrrrrrrrrrircrhrrsrMrrrrp __classcell__)r/s@r&rr,s-"H?I),M8CH%-=A$'7"89@;? Phx&8 PD P#%F#%t#%J "# "  s  6  d    s  t  #8##8J!!!Fd3c6k(:#:;$:$sF{"3::x070d3;.?0G0d(x *.  ']e_X&   80T']0(0%0T[00"IM8 ']8"&x.87?8 w| 880  $  8H882YYY   # >!& &* +++ + $ + c5f%% & +Z * *HHHT 8E? t r( ChatFullInfo)_message_auto_delete_time_slow_mode_delay Animation) _durationAudioVideo)r_start_timestamp VideoNoteVoicePaidMediaPreviewVideoChatEndedInputMediaVideoInputMediaAnimationInputMediaAudioInputPaidMediaVideoInlineQueryResultGif) _gif_durationInlineQueryResultMpeg4Gif)_mpeg4_durationInlineQueryResultVideo)_video_durationInlineQueryResultAudio)_audio_durationInlineQueryResultVoice)_voice_duration) _live_period) _open_period)r)_subscription_period)InlineQueryResultLocationPollLocationMessageAutoDeleteTimerChangedChatInviteLinkInputLocationMessageContent.r)+rrrrrrcollections.abcrrrrrzr itertoolsrtypesr typingr r r r rrrtelegram._utils.datetimertelegram._utils.defaultvaluertelegram._utils.typesrtelegram._utils.warningsrtelegramrrrrrrOr~rrr$r(r&rsu&' 44%"OOO15*) )#3t Dv-.J J \9E99 ^9 . 9  9  ^ 99n9~9>9~9>9.9 !5929 2!9"2#9$"3 !%C/#4/94U38_ 45r(