Ë
    8ø»jÝ,  ã                  óR  — d dl mZ d dlmZ d dlZd dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZmZ erd dlmZ d d	lmZ d d
lmZ ej2                  ej4                  ej6                  ej8                  fZ	  ed«       G d„ de«      «       Z ed«       G d„ de«      «       Zdd„Z y)é    )Úannotations)ÚTYPE_CHECKINGN)Úoverride)ÚDEFAULT_MAX_RETRIESÚ!DEFAULT_MIN_DELAY_BETWEEN_RETRIESÚDEFAULT_TIMEOUT_LONGÚDEFAULT_TIMEOUT_MAXÚDEFAULT_TIMEOUT_MEDIUMÚDEFAULT_TIMEOUT_SHORT)Ú
docs_group)Ú
HttpClientÚHttpClientAsync)Ú	timedelta)ÚClientStatistics)ÚHttpCompressorzHTTP clientsc                  óÖ   ‡ — e Zd ZdZdeeeeee	ddddœ
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Z
edˆ fd„«       Zedd„«       Zedd„«       Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zdd	„Zˆ xZS )ÚHttpx2HttpClientaë  Synchronous HTTP client for the Apify API built on top of [HTTPX2](https://github.com/pydantic/httpx2).

    This client wraps `httpx2.Client` and adds automatic retries with exponential backoff for rate-limited
    (HTTP 429) and server error (HTTP 5xx) responses.

    HTTPX2 applies a request timeout to each socket operation rather than to the request as a whole, so a response
    whose body arrives slowly keeps resetting it and can outlast both the requested timeout and `timeout_max`. The
    default Impit client enforces the same value as a deadline for the whole request, body included.

    Requires the `httpx2` extra: `pip install "apify-client[httpx2]"`. The `httpx2` package is Pydantic's maintained
    continuation of HTTPX.
    N©
ÚtokenÚtimeout_shortÚtimeout_mediumÚtimeout_longÚtimeout_maxÚmax_retriesÚmin_delay_between_retriesÚ
statisticsÚheadersÚhttp_compressorc       
        óŠ   •— t         ‰| �  |||||||||	|
¬«
       t        j                  dd| j                  gi¬«      | _        y)a  Initialize the HTTPX2-based synchronous HTTP client.

        Args:
            token: Apify API token for authentication.
            timeout_short: Default timeout for short-duration API operations (simple CRUD operations, ...).
            timeout_medium: Default timeout for medium-duration API operations (batch operations, listing, ...).
            timeout_long: Default timeout for long-duration API operations (long-polling, streaming, ...).
            timeout_max: Maximum timeout cap for any single request attempt, including tier and per-call timeouts.
            max_retries: Maximum number of retry attempts for failed requests.
            min_delay_between_retries: Minimum delay between retries (increases exponentially with each attempt).
            statistics: Statistics tracker for API calls. Created automatically if not provided.
            headers: Additional HTTP headers to include in all requests.
            http_compressor: Compressor used to compress request bodies. Defaults to `GzipHttpCompressor`.
        r   TÚresponse©Úfollow_redirectsÚevent_hooksN)ÚsuperÚ__init__Úhttpx2ÚClientÚ_clear_response_cookiesÚ_httpx2_client©Úselfr   r   r   r   r   r   r   r   r   r   Ú	__class__s              €úX/var/www/html/GAP/venv/lib/python3.12/site-packages/apify_client/http_clients/_httpx2.pyr%   zHttpx2HttpClient.__init__7   s\   ø€ ô8 	‰ÑØØ'Ø)Ø%Ø#Ø#Ø&?Ø!ØØ+ð 	ô 	
ô %Ÿm™mØ!Ø# d×&BÑ&BÐ%CÐDô
ˆÕó    c                óZ   •— t         ‰| �  |«      xs t        |t        j                  «      S ©N©r$   Úis_timeout_errorÚ
isinstancer&   ÚTimeoutException©r+   Úexcr,   s     €r-   r2   z!Httpx2HttpClient.is_timeout_errore   ó%   ø€ ä‰wÑ'¨Ó,ÒX´
¸3Ä×@WÑ@WÓ0XÐXr.   c                ó\   — t        |t        j                  «      xr t        |t        «       S r0   ©r3   r&   Ú	HTTPErrorÚ_PERMANENT_ERRORS©r+   r6   s     r-   Úis_retryable_transport_errorz-Httpx2HttpClient.is_retryable_transport_errori   ó'   € ô ˜#œv×/Ñ/Ó0Ò[¼ÀCÔIZÓ9[Ð5[Ð[r.   c                ó8   — | j                   j                  «        y)z,Close the underlying HTTPX2 connection pool.N)r)   Úclose©r+   s    r-   r@   zHttpx2HttpClient.closeq   s   € ð 	×Ñ×!Ñ!Õ#r.   c               ó”   — | j                   j                  |||||¬«      }t        ||«       | j                   j                  ||¬«      S ©N)ÚmethodÚurlr   ÚcontentÚtimeout)Ústream)r)   Úbuild_requestÚ_restore_explicit_cookie_headerÚsend©r+   rD   rE   r   rF   rG   rH   Úrequests           r-   Úsend_requestzHttpx2HttpClient.send_requestv   sV   € ð ×%Ñ%×3Ñ3ØØØØØð 4ó 
ˆô 	(¨°Ô9Ø×"Ñ"×'Ñ'¨¸Ð'Ó?Ð?r.   c                óL   — | j                   j                  j                  «        y©zWPrevent HTTPX2's shared cookie jar from leaking server cookies into later API requests.N)r)   ÚcookiesÚclear©r+   Ú	_responses     r-   r(   z(Httpx2HttpClient._clear_response_cookies‹   s   € à×Ñ×#Ñ#×)Ñ)Õ+r.   ©r   z
str | Noner   r   r   r   r   r   r   r   r   Úintr   r   r   zClientStatistics | Noner   zdict[str, str] | Noner   zHttpCompressor | NoneÚreturnÚNone©r6   Ú	ExceptionrW   Úbool©rW   rX   ©rD   ÚstrrE   r^   r   údict[str, str]rF   zbytes | NonerG   zfloat | NonerH   r[   rW   úhttpx2.Response©rT   r`   rW   rX   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r   r	   r   r   r%   r   r2   r=   r@   rN   r(   Ú__classcell__©r,   s   @r-   r   r   (   sD  ø„ ñð  !Ø#8Ø$:Ø"6Ø!4Ø.Ø/PØ.2Ø)-Ø15ñ,
ð ð,
ð !ð	,
ð
 "ð,
ð  ð,
ð ð,
ð ð,
ð $-ð,
ð ,ð,
ð 'ð,
ð /ð,
ð 
õ,
ð\ ôYó ðYð ò\ó ð\ð ò$ó ð$ð ð@ð ð@ð ð	@ð
  ð@ð ð@ð ð@ð ð@ð 
ò@ó ð@÷(,r.   r   c                  óÖ   ‡ — e Zd ZdZdeeeeee	ddddœ
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
ˆ fd„Z
edˆ fd„«       Zedd„«       Zedd„«       Ze	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Zdd	„Zˆ xZS )ÚHttpx2HttpClientAsyncañ  Asynchronous HTTP client for the Apify API built on top of [HTTPX2](https://github.com/pydantic/httpx2).

    This client wraps `httpx2.AsyncClient` and adds automatic retries with exponential backoff for rate-limited
    (HTTP 429) and server error (HTTP 5xx) responses.

    HTTPX2 applies a request timeout to each socket operation rather than to the request as a whole, so a response
    whose body arrives slowly keeps resetting it and can outlast both the requested timeout and `timeout_max`. The
    default Impit client enforces the same value as a deadline for the whole request, body included.

    Requires the `httpx2` extra: `pip install "apify-client[httpx2]"`. The `httpx2` package is Pydantic's maintained
    continuation of HTTPX.
    Nr   c       
        óŠ   •— t         ‰| �  |||||||||	|
¬«
       t        j                  dd| j                  gi¬«      | _        y)a  Initialize the HTTPX2-based asynchronous HTTP client.

        Args:
            token: Apify API token for authentication.
            timeout_short: Default timeout for short-duration API operations (simple CRUD operations, ...).
            timeout_medium: Default timeout for medium-duration API operations (batch operations, listing, ...).
            timeout_long: Default timeout for long-duration API operations (long-polling, streaming, ...).
            timeout_max: Maximum timeout cap for any single request attempt, including tier and per-call timeouts.
            max_retries: Maximum number of retry attempts for failed requests.
            min_delay_between_retries: Minimum delay between retries (increases exponentially with each attempt).
            statistics: Statistics tracker for API calls. Created automatically if not provided.
            headers: Additional HTTP headers to include in all requests.
            http_compressor: Compressor used to compress request bodies. Defaults to `GzipHttpCompressor`.
        r   Tr    r!   N)r$   r%   r&   ÚAsyncClientr(   Ú_httpx2_async_clientr*   s              €r-   r%   zHttpx2HttpClientAsync.__init__Ÿ   s^   ø€ ô8 	‰ÑØØ'Ø)Ø%Ø#Ø#Ø&?Ø!ØØ+ð 	ô 	
ô %+×$6Ñ$6Ø!Ø# d×&BÑ&BÐ%CÐDô%
ˆÕ!r.   c                óZ   •— t         ‰| �  |«      xs t        |t        j                  «      S r0   r1   r5   s     €r-   r2   z&Httpx2HttpClientAsync.is_timeout_errorÍ   r7   r.   c                ó\   — t        |t        j                  «      xr t        |t        «       S r0   r9   r<   s     r-   r=   z2Httpx2HttpClientAsync.is_retryable_transport_errorÑ   r>   r.   c              ƒ  óT   K  — | j                   j                  «       ƒ d{  –—†  y7 Œ­w)z9Close the underlying asynchronous HTTPX2 connection pool.N)rl   ÚacloserA   s    r-   rp   zHttpx2HttpClientAsync.acloseÙ   s    è ø€ ð ×'Ñ'×.Ñ.Ó0×0Ò0ús   ‚( &¡(c             ƒ  ó°   K  — | j                   j                  |||||¬«      }t        ||«       | j                   j                  ||¬«      ƒ d {  –—† S 7 Œ­wrC   )rl   rI   rJ   rK   rL   s           r-   rN   z"Httpx2HttpClientAsync.send_requestÞ   s`   è ø€ ð ×+Ñ+×9Ñ9ØØØØØð :ó 
ˆô 	(¨°Ô9Ø×.Ñ.×3Ñ3°GÀFÐ3ÓK×KÐKÐKús   ‚AAÁAÁAc              ƒ  óT   K  — | j                   j                  j                  «        y­wrP   )rl   rQ   rR   rS   s     r-   r(   z-Httpx2HttpClientAsync._clear_response_cookiesó   s   è ø€ à×!Ñ!×)Ñ)×/Ñ/Õ1ùs   ‚&(rU   rY   r\   r]   ra   )rb   rc   rd   re   r   r
   r   r	   r   r   r%   r   r2   r=   rp   rN   r(   rf   rg   s   @r-   ri   ri   �   sD  ø„ ñð  !Ø#8Ø$:Ø"6Ø!4Ø.Ø/PØ.2Ø)-Ø15ñ,
ð ð,
ð !ð	,
ð
 "ð,
ð  ð,
ð ð,
ð ð,
ð $-ð,
ð ,ð,
ð 'ð,
ð /ð,
ð 
õ,
ð\ ôYó ðYð ò\ó ð\ð ò1ó ð1ð ðLð ðLð ð	Lð
  ðLð ðLð ðLð ðLð 
òLó ðL÷(2r.   ri   c                ó¢   — t        d„ |j                  «       D «       d«      }|€| j                  j                  dd«       y|| j                  d<   y)a  Keep only cookies explicitly supplied for this request, never cookies from HTTPX2's shared jar.

    HTTPX2 drops the `Cookie` header when it builds a redirect request and rebuilds it from the jar, so an explicit
    cookie only reaches the first hop of a redirected request.
    c              3  óN   K  — | ]  \  }}|j                  «       d k(  sŒ|–— Œ y­w)ÚcookieN)Úlower)Ú.0ÚkeyÚvalues      r-   ú	<genexpr>z2_restore_explicit_cookie_header.<locals>.<genexpr>þ   s"   è ø€ Ò_¡j c¨5ÀsÇyÁyÃ{ÐV^ÓG^œEÑ_ùs   ‚%ž%Nru   )ÚnextÚitemsr   Úpop)rM   r   Úexplicit_cookies      r-   rJ   rJ   ø   sE   € ô Ñ_°G·M±M³OÔ_ÐaeÓf€OØÐØ�‰×Ñ˜H dÕ+à$3ˆ�‰˜Ò!r.   )rM   zhttpx2.Requestr   r_   rW   rX   )!Ú
__future__r   Útypingr   r&   Útyping_extensionsr   Úapify_client._constsr   r   r   r	   r
   r   Úapify_client._docsr   Úapify_client.http_clients._baser   r   Údatetimer   Úapify_client._statisticsr   Ú#apify_client.http_compressors._baser   ÚLocalProtocolErrorÚUnsupportedProtocolÚTooManyRedirectsÚHTTPStatusErrorr;   r   ri   rJ   © r.   r-   ú<module>r�      s²   ðÝ "å  ã Ý &÷÷ õ *ß GáÝ"å9ÝBð
 ×Ñà
×Ñà
×Ñð ×Ñð
Ð ð qñ ˆNÓôd,�zó d,ó ðd,ñN ˆNÓôd2˜Oó d2ó ðd2ôN
4r.   