Ë
    †jí3  ã                   ó¤   — d Z ddlmZ ddl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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)ÚAnyN)ÚDefaultValue)Ú
get_logger)ÚHTTPVersionÚODVInputÚ	SocketOpt)ÚNetworkErrorÚTimedOut)ÚBaseRequest)ÚRequestDataÚHTTPXRequestc                   óÜ  — e Zd ZdZdZ	 	 	 	 	 	 	 	 	 	 ddededz  dedz  dedz  dedz  d	ed
ee	   dz  de
ej                  z  ej                  z  dz  dedz  dee
ef   dz  fd„Zede
fd„«       Zededz  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dz  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

    .. 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
                <https://www.python-httpx.org/advanced/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             <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Úread_timeoutÚwrite_timeoutÚconnect_timeoutÚpool_timeoutÚhttp_versionÚsocket_optionsÚproxyÚmedia_write_timeoutÚhttpx_kwargsc                 óÜ  — || _         |	| _        t        j                  ||||¬«      }t        j                  |¬«      }|dvrt        d«      ‚|dk(  }|| dœ}|rt        j                  |¬«      nd }||||dœ|¥|
xs i ¥| _        	 | j                  «       | _	        y # t        $ rE}d	t        |«      vrd
t        |«      vr‚ d
t        |«      v rt        d«      |‚t        d«      |‚d }~ww xY w)N©ÚconnectÚreadÚwriteÚpool)Úmax_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]"`.)r   r   ÚhttpxÚTimeoutÚLimitsÚ
ValueErrorÚAsyncHTTPTransportr   Ú_build_clientr   ÚImportErrorÚstrÚRuntimeError)Úselfr   r   r   r   r   r   r   r   r   r   r)   r*   r'   Úhttp_kwargsr+   Úexcs                    ú]/var/www/html/datingFans/myenv/lib/python3.12/site-packages/telegram/request/_httpxrequest.pyÚ__init__zHTTPXRequest.__init__‘   s<  € ð *ˆÔØ$7ˆÔ!Ü—-‘-Ø#ØØØô	
ˆô —‘Ø0ô
ˆð Ð2Ñ2ÜÐQÓRÐRà Ñ%ˆØ %°E°	Ñ:ˆñ
 ô ×$Ñ$Ø-õð ð 	ð ØØØ"ñ	
ð
 ð
ð Ò!˜rð
ˆÔð	Ø×-Ñ-Ó/ˆD�LøÜò 	Ø¤S¨£XÑ-°.ÌÈCËÑ2PØà¤ S£Ñ)Ü"ð5óð ðô ð1óð ðûð	ús   ÂB Â	C+Â&A C&Ã&C+Úreturnc                 ó   — | j                   S )zn
        :obj:`str`: Used HTTP version, see :paramref:`http_version`.

        .. versionadded:: 20.2
        )r   ©r5   s    r8   r   zHTTPXRequest.http_versionÏ   s   € ð ×!Ñ!Ð!ó    c                 óB   — | j                   j                  j                  S )zÐSee :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!   r<   s    r8   r   zHTTPXRequest.read_timeoutØ   s   € ð �|‰|×#Ñ#×(Ñ(Ð(r=   c                 ó@   — t        j                  di | j                  ¤ŽS )N© )r,   ÚAsyncClientr   r<   s    r8   r1   zHTTPXRequest._build_clientâ   s   € Ü× Ñ Ñ7 4×#6Ñ#6Ñ7Ð7r=   c              ƒ   ód   K  — | j                   j                  r| j                  «       | _         yy­w)z#See :meth:`BaseRequest.initialize`.N)r   Ú	is_closedr1   r<   s    r8   Ú
initializezHTTPXRequest.initializeå   s(   è ø€ à�<‰<×!Ò!Ø×-Ñ-Ó/ˆD�Lð "ù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   rC   Ú_LOGGERÚdebugÚacloser<   s    r8   ÚshutdownzHTTPXRequest.shutdownê   s9   è ø€ à�<‰<×!Ò!Ü�M‰MÐNÔOØà�l‰l×!Ñ!Ó#×#Ò#ú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| j                  }t        j                  ||||¬«      }
	 | j                   j                  ||d| j                   i|
||	¬«      ƒ d{  –—† }|j0                  |j2                  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!Nr   z
User-Agent)rK   rJ   Úheadersr)   ÚfilesÚdataz§Pool 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   rC   r4   Úmultipart_dataÚjson_parametersÚ
isinstancer   r)   r!   r    r#   r"   r   r,   r-   ÚrequestÚ
USER_AGENTÚTimeoutExceptionÚPoolTimeoutr   Ú	HTTPErrorr
   Ú	__class__Ú__name__Ústatus_codeÚcontent)r5   rJ   rK   rL   r   r   r   r   rO   rP   r)   ÚresÚerrs                r8   Ú
do_requestzHTTPXRequest.do_requestò   s¸  è ø€ ð �<‰<×!Ò!ÜÐFÓGÐGá/;�×+Ò+ÀˆÙ/;ˆ|×+Ò+Àˆô �l¤LÔ1ØŸ<™<×/Ñ/×4Ñ4ˆLÜ�o¤|Ô4Ø"Ÿl™l×2Ñ2×:Ñ:ˆOÜ�l¤LÔ1ØŸ<™<×/Ñ/×4Ñ4ˆLä�m¤\Ô2Ù>C˜DŸL™L×0Ñ0×6Ò6È×IbÑIbˆMä—-‘-Ø#ØØØô	
ˆð	RØŸ™×,Ñ,ØØØ% t§¡Ð7ØØØð -ó ÷ ˆCð4 �‰ §¡Ð+Ð+ð5ùô ×%Ñ%ò 		$Ü˜#œu×0Ñ0Ô1Üð9ôð ðô  Ð#ûÜ�‰ò 	Rô  ¨¯©×(>Ñ(>Ð'?¸rÀ#ÀÐGÓHÈcÐQûð	RüsH   ‚D)H Ä,0E; ÅE9ÅE; Å!H Å9E; Å;G=Æ.F<Æ<G=Ç&G8Ç8G=Ç=H )
é   ç      @rb   rb   g      ð?r%   NNg      4@N)r:   N)r[   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚintÚfloatr   r   r	   r3   r,   ÚProxyÚURLÚdictr   r9   Úpropertyr   r   rA   r1   rD   rI   r   ÚDEFAULT_NONEr   r   ÚtupleÚbytesr`   r@   r=   r8   r   r   )   sË  „ ñcðJ W€Ið %(Ø%(Ø&)Ø(+Ø%(Ø$)Ø7;Ø6:Ø,0Ø.2ñ<à!ð<ð ˜d‘lð<ð ˜t‘|ð	<ð
  ™ð<ð ˜d‘lð<ð "ð<ð # 9Ñ-°Ñ4ð<ð �U—[‘[Ñ  5§9¡9Ñ,¨tÑ3ð<ð # T™\ð<ð ˜3 ˜8‘n tÑ+ó<ð| ð"˜cò "ó ð"ð ð)˜e d™lò )ó ð)ð8˜u×0Ñ0ó 8ó0ó
$ð ,0Ø(3×(@Ñ(@Ø)4×)AÑ)AØ+6×+CÑ+CØ(3×(@Ñ(@ñ?,àð?,ð ð?,ð " DÑ(ð	?,ð
 ˜u‘oð?,ð   ‘ð?,ð " %™ð?,ð ˜u‘oð?,ð 
ˆs�EˆzÑ	ô?,r=   )re   Úcollections.abcr   Útypingr   r,   Útelegram._utils.defaultvaluer   Útelegram._utils.loggingr   Útelegram._utils.typesr   r   r	   Útelegram.errorr
   r   Útelegram.request._baserequestr   Útelegram.request._requestdatar   r[   rF   r   r@   r=   r8   ú<module>rx      sE   ðñ& Zå &Ý ã å 5Ý .ß BÑ Bß 1Ý 5Ý 5ñ �X˜~Ó
.€ôH,�;õ H,r=   