
    YiA6                         S r SSKJr  SSKJrJrJr  SSKrSSKJ	r	  SSK
Jr  SSKJrJrJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  \" \S5      r " S S\5      rg)zSThis module contains methods to make POST and GET requests using the httpx library.    )
Collection)AnyOptionalUnionN)DefaultValue)
get_logger)HTTPVersionODVInput	SocketOpt)warn)NetworkErrorTimedOut)BaseRequest)RequestData)PTBDeprecationWarningHTTPXRequestc                   6   \ rS rSrSrSr           SS\S\\\	\
R                  \
R                  4      S\\   S\\   S	\\   S
\\   S\S\\\      S\\\	\
R                  \
R                  4      S\\   S\\\	\4      4S jjr\S\	4S j5       r\S\\   4S j5       rS\
R.                  4S jrSS jrSS jrS\R8                  \R8                  \R8                  \R8                  4S\	S\	S\\   S\\   S\\   S	\\   S
\\   S\\\ 4   4S jjr!Sr"g)r   *   a
  Implementation of :class:`~telegram.request.BaseRequest` using the library
`httpx <https://www.python-httpx.org>`_.

.. versionadded:: 20.0

Args:
    connection_pool_size (:obj:`int`, optional): Number of connections to keep in the
        connection pool. Defaults to ``1``.

        Note:
            Independent of the value, one additional connection will be reserved for
            :meth:`telegram.Bot.get_updates`.
    proxy_url (:obj:`str`, optional): Legacy name for :paramref:`proxy`, kept for backward
        compatibility. Defaults to :obj:`None`.

        .. deprecated:: 20.7
    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             <https://www.encode.io/httpcore/async/#httpcore.AsyncConnectionPool.__init__>`_.

        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 <https://www.python-httpx.org/api/#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_timeoutNconnection_pool_size	proxy_urlread_timeoutwrite_timeoutconnect_timeoutpool_timeouthttp_versionsocket_optionsproxymedia_write_timeouthttpx_kwargsc                 N   Ub  U	b  [        S5      eUb  Un	[        [        SS5      SS9  Xpl        Xl        [
        R                  " UUUUS9n[
        R                  " UUS9nUS;  a  [        S	5      eUS
:H  nX(       + S.nU(       a  [
        R                  " US9OS nUU	UUS.UEU=(       d    0 EU l	         U R                  5       U l        g ! [         aK  nS[        U5      ;  a  S[        U5      ;  a  e S[        U5      ;   a  [        S5      Ue[        S5      UeS nAff = f)Nz>The parameters `proxy_url` and `proxy` are mutually exclusive.z20.7z=The parameter `proxy_url` is deprecated. Use `proxy` instead.   )
stacklevelconnectreadwritepool)max_connectionsmax_keepalive_connections)1.12z2.0z2`http_version` must be either '1.1', '2.0' or '2'.r.   )http1http2)r    )timeoutr!   limits	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]"`.)
ValueErrorr   r   r   r   httpxTimeoutLimitsAsyncHTTPTransportr   _build_clientr   ImportErrorstrRuntimeError)selfr   r   r   r   r   r   r   r    r!   r"   r#   r2   r3   r0   http_kwargsr4   excs                     I/app/.venv/lib/python3.13/site-packages/telegram/request/_httpxrequest.py__init__HTTPXRequest.__init__   sx     U%6]^^ E%[ 	 *$7!--#	
 0&:

 22QRR% %	:
  $$-  	 "	

 
 !r
	--/DL 	SX-.C2PS)"5  1 	s   9C 
D$ADD$returnc                     U R                   $ )zV
:obj:`str`: Used HTTP version, see :paramref:`http_version`.

.. versionadded:: 20.2
)r   r>   s    rA   r   HTTPXRequest.http_version   s     !!!    c                 B    U R                   R                  R                  $ )zSee :attr:`BaseRequest.read_timeout`.

Returns:
    :obj:`float` | :obj:`None`: The default read timeout in seconds as passed to
        :paramref:`HTTPXRequest.read_timeout`.
)r   r2   r)   rF   s    rA   r   HTTPXRequest.read_timeout   s     ||##(((rH   c                 B    [         R                  " S0 U R                  D6$ )N )r6   AsyncClientr   rF   s    rA   r:   HTTPXRequest._build_client   s      74#6#677rH   c                 n   #    U R                   R                  (       a  U R                  5       U l         gg7f)z#See :meth:`BaseRequest.initialize`.N)r   	is_closedr:   rF   s    rA   
initializeHTTPXRequest.initialize   s'     <<!!--/DL "s   35c                    #    U R                   R                  (       a  [        R                  S5        gU R                   R	                  5       I Sh  vN   g N7f)z!See :meth:`BaseRequest.shutdown`.z2This HTTPXRequest is already shut down. Returning.N)r   rP   _LOGGERdebugacloserF   s    rA   shutdownHTTPXRequest.shutdown   s8     <<!!MMNOll!!###s   AAAAurlmethodrequest_datac           	      R  #    U R                   R                  (       a  [        S5      eU(       a  UR                  OSnU(       a  UR                  OSn	[        U[        5      (       a   U R                   R                  R                  n[        U[        5      (       a   U R                   R                  R                  n[        U[        5      (       a   U R                   R                  R                  n[        U[        5      (       a3  U(       d   U R                   R                  R                  OU R                  n[        R                  " UUUUS9n
 U R                   R                  UUSU R                   0U
UU	S9I Sh  vN nUR0                  UR2                  4$  N! [        R"                   a5  n[        U[        R$                  5      (       a
  ['        SS9Ue[&        UeSnAf[        R(                   a+  n[+        SUR,                  R.                   S	U 35      UeSnAff = f7f)
z#See :meth:`BaseRequest.do_request`.z%This HTTPXRequest is not initialized!Nr'   z
User-Agent)rZ   rY   headersr2   filesdatazPool 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.)messagezhttpx.z: )r   rP   r=   multipart_datajson_parameters
isinstancer   r2   r)   r(   r+   r*   r   r6   r7   request
USER_AGENTTimeoutExceptionPoolTimeoutr   	HTTPErrorr   	__class____name__status_codecontent)r>   rY   rZ   r[   r   r   r   r   r^   r_   r2   reserrs                rA   
do_requestHTTPXRequest.do_request   s     <<!!FGG/;++/;|++ lL11<<//44Lo|44"ll22::OlL11<<//44Lm\22>CDLL0066IbIbM--#	
	R,,%t7 -  C4 ++5 %% 		$#u00119  # 	R (>(>'?r#GHcQ	RsH   EH'-F ?F F H'F H$20G""H$9&HH$$H')   N      @rr   rr   g      ?r.   NNg      4@N)rD   N)#rj   
__module____qualname____firstlineno____doc__	__slots__intr   r   r<   r6   ProxyURLfloatr	   r   r   dictr   rB   propertyr   r   rM   r:   rQ   rW   r   DEFAULT_NONEr   r
   tuplebytesro   __static_attributes__rL   rH   rA   r   r   *   s   bH WI %&BF(+),+.(+$):>>B/315J!J E#u{{EII"=>?J uo	J
  J "%J uoJ "J !I!67J c5;;		9:;J &e_J tCH~.JX "c " " )huo ) )8u00 80
$ /3(3(@(@)4)A)A+6+C+C(3(@(@?,?, ?, {+	?,
 uo?,  ?, "%?, uo?, 
sEz	?, ?,rH   )rv   collections.abcr   typingr   r   r   r6   telegram._utils.defaultvaluer   telegram._utils.loggingr   telegram._utils.typesr	   r
   r   telegram._utils.warningsr   telegram.errorr   r   telegram.request._baserequestr   telegram.request._requestdatar   telegram.warningsr   rj   rT   r   rL   rH   rA   <module>r      sN   & Z & ' '  5 . B B ) 1 5 5 3 X~
.U,; U,rH   