a
    ù!f•
  ã                   @   s"   d Z ddlZddd„Zdd„ ZdS )	z4Assorted utilities shared between parts of apitools.é    Né<   c                 C   s2   d|  }|d }|t  | |¡7 }tdt||ƒƒS )aá  Calculate the 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.

    :type retry_attempt: integer
    :param retry_attempt: Retry attempt counter.

    :type max_wait: integer
    :param max_wait: Upper bound for wait time [seconds].

    :rtype: integer
    :returns: Number of seconds to wait before retrying request.
    é   g      @é   )ÚrandomÚuniformÚmaxÚmin)Zretry_attemptZmax_waitZ	wait_timeZ
max_jitter© r	   úV/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/streaming/util.pyÚcalculate_wait_for_retry   s    r   c                    sX   dˆvrt dˆ ƒ‚dd„ | D ƒ}|r8t dd |¡ ƒ‚dd„ ‰ t‡ ‡fd	d
„| D ƒƒS )aQ  Check that ``mime_type`` matches 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.

    :type accept_patterns: list of string
    :param accept_patterns: acceptable MIME types.

    :type mime_type: string
    :param mime_type: the MIME being checked

    :rtype: boolean
    :returns: True if the supplied MIME type matches at least one of the
              patterns, else False.
    ú/zInvalid MIME type: "%s"c                 S   s   g | ]}d |v r|‘qS )ú;r	   )Ú.0Úpr	   r	   r
   Ú
<listcomp>@   ó    z(acceptable_mime_type.<locals>.<listcomp>z.MIME patterns with parameter unsupported: "%s"z, c                 S   s$   t dd„ t|  d¡| d¡ƒD ƒƒS )z4Return True iff mime_type is acceptable for pattern.c                 s   s   | ]\}}|d |fv V  qdS )Ú*Nr	   )r   ÚacceptÚprovidedr	   r	   r
   Ú	<genexpr>H   r   z7acceptable_mime_type.<locals>._match.<locals>.<genexpr>r   )ÚallÚzipÚsplit)ÚpatternÚ	mime_typer	   r	   r
   Ú_matchF   s    ÿz$acceptable_mime_type.<locals>._matchc                 3   s   | ]}ˆ |ˆƒV  qd S )Nr	   )r   r   ©r   r   r	   r
   r   K   r   z'acceptable_mime_type.<locals>.<genexpr>)Ú
ValueErrorÚjoinÚany)Zaccept_patternsr   Zunsupported_patternsr	   r   r
   Úacceptable_mime_type+   s    ÿÿÿr    )r   )Ú__doc__r   r   r    r	   r	   r	   r
   Ú<module>   s   
