File: //opt/alt/python37/lib/python3.7/site-packages/google/oauth2/__pycache__/_client.cpython-37.pyc
B
��f�B � @ s� d Z ddlZddlmZ ddlZddlZddlmZ ddlm Z ddlm
Z
ddlmZ ddlmZ ddlm
Z
d Zd
ZdZdZd
d� Zdd� Zdd� Zd#dd�Zd$dd�Zd%dd�Zdd� Zd&dd�Zdd � Zd'd!d"�ZdS )(a OAuth 2.0 client.
This is a client for interacting with an OAuth 2.0 authorization server's
token endpoint.
For more information about the token endpoint, see
`Section 3.1 of rfc6749`_
.. _Section 3.1 of rfc6749: https://tools.ietf.org/html/rfc6749#section-3.2
� N)�_exponential_backoff)�_helpers)�
exceptions)�jwt)�metrics)� transportz!application/x-www-form-urlencodedzapplication/jsonz+urn:ietf:params:oauth:grant-type:jwt-bearer�
refresh_tokenc C sv |r|nd}t | t�r$tj| |d��yd�| d | �d��}W n" ttfk
r` t� | �}Y nX tj|| |d��dS )aX Translates an error response into an exception.
Args:
response_data (Mapping | str): The decoded response data.
retryable_error Optional[bool]: A boolean indicating if an error is retryable.
Defaults to False.
Raises:
google.auth.exceptions.RefreshError: The errors contained in response_data.
F)� retryablez{}: {}�error�error_descriptionN)
�
isinstance�strr �RefreshError�format�get�KeyError�
ValueError�json�dumps)�
response_data�retryable_errorZ
error_details� r �F/opt/alt/python37/lib/python3.7/site-packages/google/oauth2/_client.py�_handle_error_response, s
r c s� | t jkrdS y`|�d�pd}|�d�p*d}t|t�r@t|t�sDdS dddh� t� fd d
�||fD ��rldS W n tk
r� Y nX dS )a; Checks if a request can be retried by inspecting the status code
and response body of the request.
Args:
status_code (int): The response status code.
response_data (Mapping | str): The decoded response data.
Returns:
bool: True if the response is retryable. False otherwise.
Tr � r
FZinternal_failure�server_errorZtemporarily_unavailablec 3 s | ]}|� kV qd S )Nr )�.0�e)�retryable_error_descriptionsr r � <genexpr>g s z_can_retry.<locals>.<genexpr>)r ZDEFAULT_RETRYABLE_STATUS_CODESr r r
�any�AttributeError)�status_coder Z
error_descZ
error_coder )r r �
_can_retryI s
r# c C sB | � dd�}|dk r:t|t�r&t|�}t�� tj|d� S dS dS )z�Parses the expiry field from a response into a datetime.
Args:
response_data (Mapping): The JSON-parsed response data.
Returns:
Optional[datetime]: The expiration or ``None`` if no expiration was
specified.
�
expires_inN)�seconds)r r r
�intr �utcnow�datetime� timedelta)r r$ r r r �
_parse_expiryp s
r* FTc K s |rdt i}t�|��d�}ndti}tj�|��d�}|rJd�|�|d<