HEX
Server: LiteSpeed
System: Linux us-phx-web629.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64
User: u756937133 (756937133)
PHP: 8.2.27
Disabled: passthru,chgrp
Upload Files
File: //opt/gsutil/third_party/apitools/apitools/base/py/__pycache__/util.cpython-39.pyc
a

�z�g!�@sdZddlZddlZddlZddlmZddlmmm	Z
ddlmmmZ
ddlmmmZddlmZddlmZddlmZejr�ddlmZnddlmZdd	gZd
Zdd�Zdd	�Zd
d�Zddd�Z ddd�Z!ddd�Z"dd�Z#dd�Z$dd�Z%dS)z4Assorted utilities shared between parts of apitools.�N)�http_client)�messages)�encoding_helper)�
exceptions)�Iterable�	DetectGae�	DetectGcez:/?#[]@!$&'()*+,;=cCs"tj�dd�}|�d�p |�d�S)z�Determine whether or not we're running on GAE.

    This is based on:
      https://developers.google.com/appengine/docs/python/#The_Environment

    Returns:
      True iff we're running on GAE.
    �SERVER_SOFTWARE�zDevelopment/zGoogle App Engine/)�os�environ�get�
startswith)�server_software�r�9/opt/gsutil/third_party/apitools/apitools/base/py/util.pyr-s	
�cCsrd�tj�dd��}z(t�t�i���tj|ddid��}Wnt	j
yRYdS0|��tj
kop|j�d�dkS)	z�Determine whether or not we're running on GCE.

    This is based on:
      https://cloud.google.com/compute/docs/metadata#runninggce

    Returns:
      True iff we're running on a GCE instance.
    z	http://{}�GCE_METADATA_ROOTzmetadata.google.internalzMetadata-Flavor�Google)�headersFzmetadata-flavor)�formatrrr
�urllib_request�build_opener�ProxyHandler�open�Request�urllib_error�URLError�getcoder�OKr)�metadata_url�orrrr;s	����cCs\t|tj�r$t�|�}t|�d��St|t�rDdd�|D�}t|�St�dt	|�f��dS)z)Normalize scope_spec to a set of strings.� cSsg|]}t�|��qSr)�six�
ensure_str)�.0�xrrr�
<listcomp>V�z#NormalizeScopes.<locals>.<listcomp>z5NormalizeScopes expected string or iterable, found %sN)
�
isinstancer"�string_typesr#�set�splitrr�TypecheckError�type)Z
scope_specrrr�NormalizeScopesPs

��r.cCsLt||�sH|dur>t|t�r.dt|�|f}ndt|�|f}t�|��|S)Nz"Type of arg is "%s", not one of %rzType of arg is "%s", not "%s")r(�tupler-rr,)�argZarg_type�msgrrr�	Typecheck]s

�
r2c
Cs|p|jpd}|jD]�}d|}d}d|}||vrDt}|�||�}||vrZt�d|��z||}Wn ty�t�d|��Yn0|dur�t�d|��z2t|tj	�s�t
|�}|�|t�|�
d�|��}Wqt�y
}	z t�d|||	f��WYd}	~	qd}	~	00q|S)	z(Determine the relative path for request.r
z{%s}z{+%s}zMissing path parameter %sz%Request missing required parameter %sN�utf_8z3Error setting required parameter %s to value %s: %s)�
relative_path�path_params�_RESERVED_URI_CHARS�replacer�InvalidUserInputError�KeyErrorr(r"r)�str�urllib_parse�quote�encode�	TypeError)
�
method_config�paramsr4�path�paramZparam_templateZreserved_charsZreserved_template�value�errr�ExpandRelativePathisJ
��
�����rE�<cCs2d|}|d}|t�||�7}tdt||��S)a�Calculates amount of time to wait before a retry attempt.

    Wait time grows exponentially with the number of attempts. A
    random amount of jitter is added to spread out retry attempts from
    different clients.

    Args:
      retry_attempt: Retry attempt counter.
      max_wait: Upper bound for wait time [seconds].

    Returns:
      Number of seconds to wait before retrying request.

    �g@�)�random�uniform�max�min)Z
retry_attemptZmax_waitZ	wait_timeZ
max_jitterrrr�CalculateWaitForRetry�srMcs\d�vrt�d���dd�|D�}|r<t�dd�|���dd��t��fd	d
�|D��S)a�Return True iff mime_type is acceptable for one of accept_patterns.

    Note that this function assumes that all patterns in accept_patterns
    will be simple types of the form "type/subtype", where one or both
    of these can be "*". We do not support parameters (i.e. "; q=") in
    patterns.

    Args:
      accept_patterns: list of acceptable MIME types.
      mime_type: the mime type we would like to match.

    Returns:
      Whether or not mime_type matches (at least) one of these patterns.
    �/zInvalid MIME type: "%s"cSsg|]}d|vr|�qS)�;r�r$�prrrr&�r'z&AcceptableMimeType.<locals>.<listcomp>z.MIME patterns with parameter unsupported: "%s"z, cSs0|dkrd}tdd�t|�d�|�d��D��S)z4Return True iff mime_type is acceptable for pattern.�*z*/*css|]\}}|d|fvVqdS)rRNr)r$�acceptZprovidedrrr�	<genexpr>�r'z>AcceptableMimeType.<locals>.MimeTypeMatches.<locals>.<genexpr>rN)�all�zipr+)�pattern�	mime_typerrr�MimeTypeMatches�s
�z+AcceptableMimeType.<locals>.MimeTypeMatchesc3s|]}�|��VqdS)Nr)r$rW�rYrXrrrT�s�z%AcceptableMimeType.<locals>.<genexpr>)rr8�GeneratedClientError�join�any)Zaccept_patternsrXZunsupported_patternsrrZr�AcceptableMimeType�s����r^cs�fdd�|D�S)z2Reverse parameter remappings for URL construction.csg|]}tj�|d�p|�qS))�	json_name)�encoding�GetCustomJsonFieldMappingrP��request_typerrr&�s�z!MapParamNames.<locals>.<listcomp>r)r@rcrrbr�
MapParamNames�s
�rdcCstt|�}|��D]^\}}tj||d�}|dur@|�|�||<|}t|tj�rtjt	|�t
|�d�pht
|�||<q|S)a�Perform any renames/remappings needed for URL construction.

    Currently, we have several ways to customize JSON encoding, in
    particular of field names and enums. This works fine for JSON
    bodies, but also needs to be applied for path and query parameters
    in the URL.

    This function takes a dictionary from param names to values, and
    performs any registered mappings. We also need the request type (to
    look up the mappings).

    Args:
      params: (dict) Map from param names to values
      request_type: (protorpc.messages.Message) request type for this API call

    Returns:
      A new dict of the same size, with all registered mappings applied.
    )�python_nameN)�dict�itemsr`ra�popr(r�Enum�GetCustomJsonEnumMappingr-r:)r@rc�
new_params�
param_namerCZfield_remappingrrr�MapRequestParams�s���rm)N)N)rF)&�__doc__rrIr"�	six.movesrZsix.moves.urllib.error�moves�urllib�errorrZsix.moves.urllib.parse�parser;Zsix.moves.urllib.request�requestr�apitools.base.protorpcliter�apitools.base.pyrr`r�PY3�collections.abcr�collections�__all__r6rrr.r2rErMr^rdrmrrrr�<module>s4�

'
$