
    > /i=1                         d Z ddlmZmZmZmZ ddlZddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ  e
ed      Z G d de      Zy)zSThis module contains methods to make POST and GET requests using the httpx library.    )
CollectionOptionalTupleUnionN)DefaultValue)
get_logger)HTTPVersionODVInput	SocketOpt)warn)NetworkErrorTimedOut)BaseRequest)RequestData)PTBDeprecationWarningHTTPXRequestc                      e Zd ZdZdZ	 	 	 	 	 	 	 	 	 ddedeeee	j                  e	j                  f      dee   dee   dee   d	ee   d
edeee      deeee	j                  e	j                  f      fdZedefd       Zedee   fd       Zde	j(                  fdZddZddZdej2                  ej2                  ej2                  ej2                  fdededee   dee   dee   dee   d	ee   deeef   fdZy)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``.
        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

    )_client_client_kwargs_http_versionNconnection_pool_size	proxy_urlread_timeoutwrite_timeoutconnect_timeoutpool_timeouthttp_versionsocket_optionsproxyc
                    ||	t        d      ||}	t        dt        d       || _        t	        j
                  ||||      }
t	        j                  ||      }|dvrt        d      |d	k(  }|| d
}|rt	        j                  |      nd }|
|	||d|| _        	 | j                         | _
        y # t        $ rF}dt        |      vrdt        |      vr|dt        |      v rt        d      |t        d      |d }~ww xY w)Nz>The parameters `proxy_url` and `proxy` are mutually exclusive.zPThe parameter `proxy_url` is deprecated since version 20.7. 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   )timeoutproxies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   httpxTimeoutLimitsAsyncHTTPTransportr   _build_clientr   ImportErrorstrRuntimeError)selfr   r   r   r   r   r   r   r   r   r.   r0   r,   http_kwargsr1   excs                   T/srv/sistema/bot/venv/lib/python3.12/site-packages/telegram/request/_httpxrequest.py__init__zHTTPXRequest.__init__x   sa     U%6]^^ E%	 *--#	
 0&:

 22QRR% %E	:
  $$-  	 "	

 
	--/DL 	SX-.C2P	S)"5  1 	s    B6 6	D?AD  Dreturnc                     | j                   S )zn
        :obj:`str`: Used HTTP version, see :paramref:`http_version`.

        .. versionadded:: 20.2
        )r   r;   s    r>   r   zHTTPXRequest.http_version   s     !!!    c                 B    | j                   j                  j                  S )zSee :attr:`BaseRequest.read_timeout`.

        Returns:
            :obj:`float` | :obj:`None`: The default read timeout in seconds as passed to
                :paramref:`HTTPXRequest.read_timeout`.
        )r   r.   r%   rB   s    r>   r   zHTTPXRequest.read_timeout   s     ||##(((rC   c                 @    t        j                  di | j                  S )N )r3   AsyncClientr   rB   s    r>   r7   zHTTPXRequest._build_client   s      74#6#677rC   c                 d   K   | j                   j                  r| j                         | _         yyw)z#See :meth:`BaseRequest.initialize`.N)r   	is_closedr7   rB   s    r>   
initializezHTTPXRequest.initialize   s(     <<!!--/DL "s   .0c                    K   | j                   j                  rt        j                  d       y| j                   j	                          d{    y7 w)z!See :meth:`BaseRequest.shutdown`.z2This HTTPXRequest is already shut down. Returning.N)r   rI   _LOGGERdebugacloserB   s    r>   shutdownzHTTPXRequest.shutdown   s9     <<!!MMNOll!!###s   A
AAAurlmethodrequest_datac                   K   | j                   j                  rt        d      |r|j                  nd}|r|j                  nd}	t        |t              r | j                   j                  j                  }t        |t              r | j                   j                  j                  }t        |t              r | j                   j                  j                  }t        |t              r$|s | j                   j                  j                  nd}t        j                  ||||      }
	 | j                   j                  ||d| j                  i|
||	       d{   }|j.                  |j0                  fS 7 # t        j                   $ r3}t        |t        j"                        rt%        d      |t$        |d}~wt        j&                  $ r+}t)        d	|j*                  j,                   d
|       |d}~ww xY ww)z#See :meth:`BaseRequest.do_request`.z%This HTTPXRequest is not initialized!N   r#   z
User-Agent)rQ   rP   headersr.   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   rI   r:   multipart_datajson_parameters
isinstancer   r.   r%   r$   r'   r&   r3   r4   request
USER_AGENTTimeoutExceptionPoolTimeoutr   	HTTPErrorr   	__class____name__status_codecontent)r;   rP   rQ   rR   r   r   r   r   rV   rW   r.   reserrs                r>   
do_requestzHTTPXRequest.do_request   s     <<!!FGG/;++/;|++ lL1<<//44Lo|4"ll22::OlL1<<//44Lm\2
 ?DDLL0066M--#	
	R,,%t7 -  C4 ++5 %% 		$#u0019  # 	R (>(>'?r#GHcQ	RsH   DG6"0E1 E/E1 G6/E1 1G3.F22G3&G..G33G6)	   N      @ri   ri   g      ?r*   NN)r@   N)rb   
__module____qualname____doc__	__slots__intr   r   r9   r3   ProxyURLfloatr	   r   r   r?   propertyr   r   rG   r7   rJ   rO   r   DEFAULT_NONEr   r
   r   bytesrg   rF   rC   r>   r   r   )   s   JX ?I %&BF(+),+.(+$):>>BF!F E#u{{EII"=>?F uo	F
  F "%F uoF "F !I!67F c5;;		9:;FP "c " " )huo ) )8u00 80
$ /3(3(@(@)4)A)A+6+C+C(3(@(@C,C, C, {+	C,
 uoC,  C, "%C, uoC, 
sEz	C,rC   )rl   typingr   r   r   r   r3   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   rb   rL   r   rF   rC   r>   <module>r~      sK   & Z 5 5  5 . B B ) 1 5 5 3 X~
.},; },rC   