L i!4dZddlmZddlmZmZmZddlZddlm Z ddl m Z ddl m Z mZmZddlmZmZdd lmZdd lmZe ed ZGd d eZy) zSThis module contains methods to make POST and GET requests using the httpx library.) Collection)AnyOptionalUnionN) DefaultValue) get_logger) HTTPVersionODVInput SocketOpt) NetworkErrorTimedOut) BaseRequest) RequestData HTTPXRequestceZdZdZdZ ddedeedeedeedeed ed ee e d ee e e je jfd eed eee effdZede fdZedeefdZde j,fdZddZddZdej6ej6ej6ej6fde de deedeedeedeedeedeeeffdZ y)raImplementation of :class:`~telegram.request.BaseRequest` using the library `httpx `_. .. versionadded:: 20.0 .. versionchanged:: 22.0 Removed the deprecated parameter ``proxy_url``. Use :paramref:`proxy` instead. Args: connection_pool_size (:obj:`int`, optional): Number of connections to keep in the connection pool. Defaults to ``256``. .. versionchanged:: 22.4 Set the default to ``256``. Stopped applying to ``httpx.Limits.max_keepalive_connections``. Now only applies to ``httpx.Limits.max_connections``. See `Resource Limits `_ 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. This value is used unless a different value is passed to :meth:`do_request`. Defaults to ``5``. 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). This value is used unless a different value is passed to :meth:`do_request`. Defaults to ``5``. Hint: This timeout is used for all requests except for those that upload media/files. For the latter, :paramref:`media_write_timeout` is used. 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. This value is used unless a different value is passed to :meth:`do_request`. Defaults to ``5``. 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. This value is used unless a different value is passed to :meth:`do_request`. Defaults to ``1``. Warning: With a finite pool timeout, you must expect :exc:`telegram.error.TimedOut` exceptions to be thrown when more requests are made simultaneously than there are connections in the connection pool! http_version (:obj:`str`, optional): If ``"2"`` or ``"2.0"``, HTTP/2 will be used instead of HTTP/1.1. Defaults to ``"1.1"``. .. versionadded:: 20.1 .. versionchanged:: 20.2 Reset the default version to 1.1. .. versionchanged:: 20.5 Accept ``"2"`` as a valid value. socket_options (Collection[:obj:`tuple`], optional): Socket options to be passed to the underlying `library `_. Note: The values accepted by this parameter depend on the operating system. This is a low-level parameter and should only be used if you are familiar with these concepts. .. versionadded:: 20.7 proxy (:obj:`str` | ``httpx.Proxy`` | ``httpx.URL``, optional): The URL to a proxy server, a ``httpx.Proxy`` object or a ``httpx.URL`` object. For example ``'http://127.0.0.1:3128'`` or ``'socks5://127.0.0.1:3128'``. Defaults to :obj:`None`. Note: * The proxy URL can also be set via the environment variables ``HTTPS_PROXY`` or ``ALL_PROXY``. See `the docs of httpx`_ for more info. * HTTPS proxies can be configured by passing a ``httpx.Proxy`` object with a corresponding ``ssl_context``. * For Socks5 support, additional dependencies are required. Make sure to install PTB via :command:`pip install "python-telegram-bot[socks]"` in this case. * Socks5 proxies can not be set via environment variables. .. _the docs of httpx: https://www.python-httpx.org/environment_variables/#proxies .. versionadded:: 20.7 media_write_timeout (:obj:`float` | :obj:`None`, optional): Like :paramref:`write_timeout`, but used only for requests that upload media/files. This value is used unless a different value is passed to :paramref:`do_request.write_timeout` of :meth:`do_request`. Defaults to ``20`` seconds. .. versionadded:: 21.0 httpx_kwargs (dict[:obj:`str`, Any], optional): Additional keyword arguments to be passed to the `httpx.AsyncClient `_ constructor. Warning: This parameter is intended for advanced users that want to fine-tune the behavior of the underlying ``httpx`` client. The values passed here will override all the defaults set by ``python-telegram-bot`` and all other parameters passed to :class:`HTTPXRequest`. The only exception is the :paramref:`media_write_timeout` parameter, which is not passed to the client constructor. No runtime warnings will be issued about parameters that are overridden in this way. .. versionadded:: 21.6 )_client_client_kwargs _http_version_media_write_timeoutNconnection_pool_size read_timeout write_timeoutconnect_timeout pool_timeout http_versionsocket_optionsproxymedia_write_timeout httpx_kwargsc ||_| |_tj||||} tj|} |dvr t d|dk(} | | d}|rtj |nd}| || |d|| xsi|_ |j|_ y#t$rE}d t|vrd t|vrd t|vr td |td |d}~wwxYw) Nconnectreadwritepool)max_connections)1.12z2.0z2`http_version` must be either '1.1', '2.0' or '2'.r')http1http2)r)timeoutrlimits transportz httpx[http2]z httpx[socks]z\To use Socks5 proxies, PTB must be installed via `pip install "python-telegram-bot[socks]"`.zTTo use HTTP/2, PTB must be installed via `pip install "python-telegram-bot[http2]"`.) rrhttpxTimeoutLimits ValueErrorAsyncHTTPTransportr _build_clientr ImportErrorstr RuntimeError)selfrrrrrrrrrrr+r,r) http_kwargsr-excs d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/request/_httpxrequest.py__init__zHTTPXRequest.__init__s<*$7!--#   0  2 2QR R% %E :   $ $-  "    !r   --/DL SX-.C2PS)"51  sB C+&AC&&C+returnc|jS)zn :obj:`str`: Used HTTP version, see :paramref:`http_version`. .. versionadded:: 20.2 )rr7s r:rzHTTPXRequest.http_versions!!!cB|jjjS)zSee :attr:`BaseRequest.read_timeout`. Returns: :obj:`float` | :obj:`None`: The default read timeout in seconds as passed to :paramref:`HTTPXRequest.read_timeout`. )rr+r#r>s r:rzHTTPXRequest.read_timeouts||##(((r?c@tjdi|jS)N)r. AsyncClientrr>s r:r3zHTTPXRequest._build_clients  74#6#677r?cdK|jjr|j|_yyw)z#See :meth:`BaseRequest.initialize`.N)r is_closedr3r>s r: initializezHTTPXRequest.initializes( << ! !--/DL "s.0cK|jjrtjdy|jj d{y7w)z!See :meth:`BaseRequest.shutdown`.z2This HTTPXRequest is already shut down. Returning.N)rrE_LOGGERdebugacloser>s r:shutdownzHTTPXRequest.shutdowns9 << ! ! MMN O ll!!###sA A A Aurlmethod request_datacK|jjr td|r |jnd}|r |jnd} t |t r |jjj}t |t r |jjj}t |t r |jjj}t |t r.|s |jjjn |j}tj||||} |jj||d|j i| || d{} | j0| j2fS7#tj"$r3} t | tj$r t'd| t&| d} ~ wtj($r+} t+d| j,j.d | | d} ~ wwxYww) z#See :meth:`BaseRequest.do_request`.z%This HTTPXRequest is not initialized!Nr!z User-Agent)rMrLheadersr+filesdatazPool timeout: All connections in the connection pool are occupied. Request was *not* sent to Telegram. Consider adjusting the connection pool size or the pool timeout.)messagezhttpx.z: )rrEr6multipart_datajson_parameters isinstancerr+r#r"r%r$rr.r/request USER_AGENTTimeoutException PoolTimeoutr HTTPErrorr __class____name__ status_codecontent) r7rLrMrNrrrrrQrRr+reserrs r: do_requestzHTTPXRequest.do_requests << ! !FG G/; ++/;|++ lL 1<<//44L o| 4"ll22::O lL 1<<//44L m\ 2>CDLL0066IbIbM--#   R ,,%t7 -C4 ++5%% $#u0019   # R  (>(>'?r#GHc Q  RsHD)H,0E;E9E;!H9E;;G=.F<<G=&G88G==H) @rdrdg?r'NNg4@N)r<N)!r] __module__ __qualname____doc__ __slots__intrfloatr rr rr5r.ProxyURLdictrr;propertyrrrCr3rFrKr DEFAULT_NONErr tuplebytesrbrBr?r:rr)scJWI%((+),+.(+$):>>B/315<!<uo<  < "% < uo <"<!I!67<c5;; 9:;<&e_<tCH~.<|"c"")huo))8u0080 $/3(3(@(@)4)A)A+6+C+C(3(@(@?, ?,?,{+ ?, uo ?,   ?,"%?,uo?, sEz ?,r?)rgcollections.abcrtypingrrrr.telegram._utils.defaultvaluertelegram._utils.loggingrtelegram._utils.typesr r r telegram.errorr r telegram.request._baserequestrtelegram.request._requestdatarr]rHrrBr?r:rzsH&Z&'' 5.BB155 X~ .H,;H,r?