Ë
    8ø»jÃ  ã                  óŒ   — 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
mZmZ erd dlmZ dd„Zdd„Zdd	„Zdd
„Zdd„Zdd„Zy)é    )ÚannotationsN)ÚTYPE_CHECKING)Úquote)Ú&ALREADY_COMPRESSED_MEDIA_TYPE_PREFIXESÚALREADY_COMPRESSED_MEDIA_TYPESÚ COMPRESSIBLE_MEDIA_TYPE_SUFFIXESÚCOMPRESSIBLE_MEDIA_TYPESÚOVERRIDABLE_DEFAULT_HEADERS)ÚHttpResponsec                ó&   — | j                  dd«      S )a  Convert a resource ID to URL-safe format by replacing forward slashes with tildes.

    Args:
        id: The resource identifier in format `resource_id` or `username/resource_id`.

    Returns:
        The resource identifier with `/` characters replaced by `~`.
    ú/ú~)Úreplace)Úids    úO/var/www/html/GAP/venv/lib/python3.12/site-packages/apify_client/_utils/http.pyÚ
to_safe_idr      s   € ð �:‰:�c˜3ÓÐó    c                óB   — | dv rt        d| › d�«      ‚t        | d¬«      S )a  Percent-encode a caller-supplied value so it stays a single URL path segment.

    Without this, a value carrying `/`, `?` or `#` would restructure the URL it is interpolated into: it could
    reach a different endpoint, append its own query parameters, or be silently truncated at a fragment.

    Args:
        value: The value to place in a single path segment, for example a key-value store record key.

    Returns:
        The percent-encoded value, which a URL parser can only read as one path segment.

    Raises:
        ValueError: If the value is empty, `.` or `..`, none of which can be carried in a path segment at all.
    >   ú..Ú ú.ú"z'" cannot be used as a URL path segment.r   )Úsafe)Ú
ValueErrorr   )Úvalues    r   Úto_path_segmentr      s.   € ð$ �ÑÜ˜1˜U˜GÐ#JÐKÓLÐLä�˜RÔ Ð r   c                óæ   — | sy| j                  dd«      d   j                  «       j                  «       }|t        v s|j	                  t
        «      ry|t        v xs |j                  t        «       S )a’  Decide whether a request body with the given content type is worth compressing.

    Images, audio, video and archives already carry their own compression. Running them through gzip or brotli
    burns CPU, holds a second full copy of the body in memory, and usually produces output slightly larger than
    the input. Formats that are raw despite such a media type, for example `image/bmp` or `audio/wav`, are still
    compressed. A body with no content type is assumed to be compressible.

    Args:
        content_type: The value of the `Content-Type` header, if any.

    Returns:
        `True` if the body should be compressed before it is sent.
    Tú;é   r   )	ÚsplitÚstripÚlowerr	   Úendswithr   r   Ú
startswithr   )Úcontent_typeÚ
media_types     r   Úis_compressible_content_typer'   7   su   € ñ Øð ×#Ñ# C¨Ó+¨AÑ.×4Ñ4Ó6×<Ñ<Ó>€JàÔ-Ñ-°×1DÑ1DÔEeÔ1fØð 	Ô4Ð4Òu¸
×8MÑ8MÔNtÓ8uðð r   c                óˆ   — | j                  «       }t        |t        «      r|S t        dt	        |«      j
                  › �«      ‚)a  Parse the API response as a dictionary and validate its type.

    Args:
        response: The HTTP response object from the API.

    Returns:
        The parsed response as a dictionary.

    Raises:
        ValueError: If the response is not a dictionary.
    z'The response is not a dictionary. Got: )ÚjsonÚ
isinstanceÚdictr   ÚtypeÚ__name__©ÚresponseÚdatas     r   Úresponse_to_dictr1   S   s<   € ð �=‰=‹?€Dä�$œÔØˆä
Ð>¼tÀD»z×?RÑ?RÐ>SÐTÓ
UÐUr   c                ó®   — | j                  «       }t        |t        «      r|S t        |t        «      r|gS t	        dt        |«      j                  › �«      ‚)zõParse the API response as a list and validate its type.

    Args:
        response: The HTTP response object from the API.

    Returns:
        The parsed response as a list.

    Raises:
        ValueError: If the response is not a list.
    z!The response is not a list. Got: )r)   r*   Úlistr+   r   r,   r-   r.   s     r   Úresponse_to_listr4   g   sM   € ð �=‰=‹?€Dä�$œÔØˆä�$œÔØˆvˆä
Ð8¼¸d»×9LÑ9LÐ8MÐNÓ
OÐOr   c           	     óî   — |D �cg c]  }|j                  «       t        v sŒ|‘Œ }}|rHt        j                  dj	                  |«      › d| › ddj	                  t        «      › d�t
        d¬«       yyc c}w )z:Warn if custom headers override important default headers.z, z headers of z— was overridden with an explicit value. A wrong header value can lead to API errors, it is recommended to use the default value for following headers: r   é   )ÚcategoryÚ
stacklevelN)Útitler
   ÚwarningsÚwarnÚjoinÚUserWarning)Ú
class_nameÚheadersÚkeyÚoverwrite_headerss       r   Úcheck_custom_headersrB   ~   s{   € à(/Ö^ °3·9±9³;ÔB]Ò3]šÐ^ÐÐ^áÜ�‰Ø�y‰yÐ*Ó+Ð,¨L¸¸ð E,à,0¯I©IÔ6QÓ,RÐ+SÐSTðVô !Øö	
ð ùò _s
   …A2¡A2)r   ÚstrÚreturnrC   )r   rC   rD   rC   )r%   z
str | NonerD   Úbool)r/   r   rD   r+   )r/   r   rD   r3   )r>   rC   r?   zdict[str, str]rD   ÚNone)Ú
__future__r   r:   Útypingr   Úurllib.parser   Úapify_client._constsr   r   r   r	   r
   Úapify_client.http_clientsr   r   r   r'   r1   r4   rB   © r   r   ú<module>rM      sC   ðÝ "ã Ý  Ý ÷õ ñ Ý6ó	 ó!ó0ó8Vó(Pô.
r   