L iL2dZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z m Z mZddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'e ddZ(ee)dZ*GddedejVZ,y)zEThis module contains an abstract class to make POST and GET requests.N)AbstractAsyncContextManager) HTTPStatus) TracebackType)FinalOptionalTypeVarUnionfinal) DEFAULT_NONE) DefaultValue) get_logger) TextEncoding)JSONDictODVInput) __version__) BadRequest ChatMigratedConflict Forbidden InvalidToken NetworkError RetryAfter TelegramError) RequestDataRT BaseRequest)bound) class_nameceZdZUdZdZdedZeee d< e Z ee de d< de d e fd Zd eeed eed eed dfdZeej,d eefdZej,ddZej,ddZede e e e fdedeedeedeedeedeed eee ee!ffdZ"ee e e e fdedeedeedeedeed e#f dZ$de e e e fdededeedeedeedeedeed e#fdZ%e&de#d efdZ'ej,de e e e fdededeedeedeedeedeed e(e)e#ffdZ*y) ra?Abstract interface class that allows python-telegram-bot to make requests to the Bot API. Can be implemented via different asyncio HTTP libraries. An implementation of this class must implement all abstract methods and properties. Instances of this class can be used as asyncio context managers, where .. code:: python async with request_object: # code is roughly equivalent to .. code:: python try: await request_object.initialize() # code finally: await request_object.shutdown() .. seealso:: :meth:`__aenter__` and :meth:`__aexit__`. Tip: JSON encoding and decoding is done with the standard library's :mod:`json` by default. To use a custom library for this, you can override :meth:`parse_json_payload` and implement custom logic to encode the keys of :attr:`telegram.request.RequestData.parameters`. .. seealso:: :wiki:`Architecture Overview `, :wiki:`Builder Pattern ` .. versionadded:: 20.0 zpython-telegram-bot vz" (https://python-telegram-bot.org) USER_AGENTNr selfreturncK |jd{|S7#t$r|jd{7wxYww)a'|async_context_manager| :meth:`initializes ` the Request. Returns: The initialized Request instance. Raises: :exc:`Exception`: If an exception is raised during initialization, :meth:`shutdown` is called in this case. N) initialize Exceptionshutdownr"s c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/request/_baserequest.py __aenter__zBaseRequest.__aenter__jsG //# # # $ --/ ! !  s.A  A A?AAexc_typeexc_valexc_tbc@K|jd{y7w)zB|async_context_manager| :meth:`shuts down ` the Request.N)r')r"r+r,r-s r) __aexit__zBaseRequest.__aexit__{smmos cy)aThis property must return the default read timeout in seconds used by this class. More precisely, the returned value should be the one used when :paramref:`post.read_timeout` of :meth:post` is not passed/equal to :attr:`DEFAULT_NONE`. .. versionadded:: 20.7 .. versionchanged:: 22.0 This property is now required to be implemented by subclasses. Returns: :obj:`float` | :obj:`None`: The read timeout in seconds. Nr r(s r) read_timeoutzBaseRequest.read_timeoutsc Kyw)zKInitialize resources used by this class. Must be implemented by a subclass.Nr r(s r)r%zBaseRequest.initializec Kyw)zMStop & clear resources used by this class. Must be implemented by a subclass.Nr r(s r)r'zBaseRequest.shutdownr4r5url request_datar1 write_timeoutconnect_timeout pool_timeoutc zK|j|d|||||d{}|j|}|dS7w)a_Makes a request to the Bot API handles the return code and parses the answer. Warning: This method will be called by the methods of :class:`telegram.Bot` and should *not* be called manually. Args: url (:obj:`str`): The URL to request. request_data (:class:`telegram.request.RequestData`, optional): An object containing information about parameters and files to upload for the request. read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a response from Telegram's server instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a write operation to complete (in terms of a network socket; i.e. POSTing a request or uploading a file) instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a connection attempt to a server to succeed instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a connection to become available instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. Returns: The JSON response of the Bot API. POSTr7methodr8r1r9r:r;Nresult)_request_wrapperparse_json_payload) r"r7r8r1r9r:r;r@ json_datas r)postzBaseRequest.posts\R,,%%'+%-  ++F3 "" s ;9;cLK|j|d||||d{S7w)aRetrieve the contents of a file by its URL. Warning: This method will be called by the methods of :class:`telegram.Bot` and should *not* be called manually. Args: url (:obj:`str`): The web location we want to retrieve. read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a response from Telegram's server instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a write operation to complete (in terms of a network socket; i.e. POSTing a request or uploading a file) instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a connection attempt to a server to succeed instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a connection to become available instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. Returns: :obj:`bytes`: The files contents. GET)r7r?r1r9r:r;N)rA)r"r7r1r9r:r;s r)retrievezBaseRequest.retrieves=L**%'+% +    s $"$r?c K |j|||||||d{\}} tj |cxkrdkr| S t |j d|d} d} |j| } | jdxs| } | jd }|rE|jd }|r t||jd }|r t|| d |z } |tjk(r t| }n|tjtjfvr t!| }nh|tj"k(r t%| }nI|tj&k(r t)| }n*|tj*k(r t| }n t| }| r|| |7}#t$rt$r} td| | d} ~ wwxYw#t$r d|d} Y{wxYw#t$r} | d | dz } | } Yd} ~ d} ~ wwxYww)aWraps the real implementation request method. Performs the following tasks: * Handle the various HTTP response codes. * Parse the Telegram server response. Args: url (:obj:`str`): The URL to request. method (:obj:`str`): HTTP method (i.e. 'POST', 'GET', etc.). request_data (:class:`telegram.request.RequestData`, optional): An object containing information about parameters and files to upload for the request. read_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a response from Telegram's server instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. write_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a write operation to complete (in terms of a network socket; i.e. POSTing a request or uploading a file) instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. connect_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a connection attempt to a server to succeed instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. pool_timeout (:obj:`float` | :obj:`None`, optional): If passed, specifies the maximum amount of time (in seconds) to wait for a connection to become available instead of the time specified during creating of this object. Defaults to :attr:`DEFAULT_NONE`. Returns: bytes: The payload part of the HTTP server response. Raises: TelegramError r>Nz&Unknown error in HTTP implementation: i+z ()zUnknown HTTPError ( description parametersmigrate_to_chat_id retry_afterz4. The server response contained unknown parameters: z. Parsing the server response z failed) do_requestrr&rrOKphrase ValueErrorrBgetrr FORBIDDENr NOT_FOUND UNAUTHORIZEDr BAD_REQUESTrCONFLICTr BAD_GATEWAY)r"r7r?r8r1r9r:r;codepayloadexcmessageparsing_exception response_datarKrLrM exceptions r)rAzBaseRequest._request_wrappers<Z Z"&//))+ /)#2#MD' ==D 'C 'N (  4#D)001D6;G6: _ 33Grsy&L 299F5.044   6 T' X- 8I  .GGI r2