a
    w=ic                     @   s   d Z ddlZddlZddlZddlZddlZddlmZ ejddZ	dd Z
dd	 Zd
d ZdddZdd ZdddZdd Zdd Zdd Zdd Zdd ZdS )z-Helper functions for commonly used utilities.    N)urllib   )secondsc                    s    fdd}|S )a0  Decorator that copies a method's docstring from another class.

    Args:
        source_class (type): The class that has the documented method.

    Returns:
        Callable: A decorator that will copy the docstring of the same
            named method in the source class to the decorated method.
    c                    s&   | j rtdt | j}|j | _ | S )a"  Decorator implementation.

        Args:
            method (Callable): The method to copy the docstring to.

        Returns:
            Callable: the same method passed in with an updated docstring.

        Raises:
            ValueError: if the method already has a docstring.
        zMethod already has a docstring.)__doc__
ValueErrorgetattr__name__)methodZsource_methodsource_class e/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/google/auth/_helpers.py	decorator,   s
    z!copy_docstring.<locals>.decoratorr   )r   r   r   r
   r   copy_docstring!   s    r   c                   C   s
   t j  S )z_Returns the current UTC datetime.

    Returns:
        datetime: The current time in UTC.
    )datetimeutcnowr   r   r   r   r   C   s    r   c                 C   s   t |  S )zConvert a datetime object to the number of seconds since the UNIX epoch.

    Args:
        value (datetime): The datetime to convert.

    Returns:
        int: The number of seconds since the UNIX epoch.
    )calendartimegmutctimetuplevaluer   r   r   datetime_to_secsL   s    	r   utf-8c                 C   s<   t | tjr| |n| }t |tjr*|S td| dS )a@  Converts a string value to bytes, if necessary.

    Unfortunately, ``six.b`` is insufficient for this task since in
    Python 2 because it does not modify ``unicode`` objects.

    Args:
        value (Union[str, bytes]): The value to be converted.
        encoding (str): The encoding to use to convert unicode to bytes.
            Defaults to "utf-8".

    Returns:
        bytes: The original value converted to bytes (if unicode) or as
            passed in if it started out as bytes.

    Raises:
        ValueError: If the value could not be converted to bytes.
    z%{0!r} could not be converted to bytesN)
isinstancesix	text_typeencodebinary_typer   format)r   encodingresultr   r   r   to_bytesX   s    r!   c                 C   s<   t | tjr| dn| }t |tjr*|S td| dS )aV  Converts bytes to a string value, if necessary.

    Args:
        value (Union[str, bytes]): The value to be converted.

    Returns:
        str: The original value converted to unicode (if bytes) or as passed in
            if it started out as unicode.

    Raises:
        ValueError: If the value could not be converted to unicode.
    r   z'{0!r} could not be converted to unicodeN)r   r   r   decoder   r   r   )r   r    r   r   r   
from_bytesq   s    r#   c                    sp    du rg  t j| }t j|j}||  fddt|D }t jj|dd}|j	|d}t j
|S )a  Updates a URL's query parameters.

    Replaces any current values if they are already present in the URL.

    Args:
        url (str): The URL to update.
        params (Mapping[str, str]): A mapping of query parameter
            keys to values.
        remove (Sequence[str]): Parameters to remove from the query string.

    Returns:
        str: The URL with updated query parameters.

    Examples:

        >>> url = 'http://example.com?a=1'
        >>> update_query(url, {'a': '2'})
        http://example.com?a=2
        >>> update_query(url, {'b': '3'})
        http://example.com?a=1&b=3
        >> update_query(url, {'b': '3'}, remove=['a'])
        http://example.com?b=3

    Nc                    s   i | ]\}}| vr||qS r   r   ).0keyr   remover   r   
<dictcomp>   s   z update_query.<locals>.<dictcomp>T)doseq)query)r   parseurlparseparse_qsr*   updater   	iteritems	urlencode_replace
urlunparse)urlparamsr'   partsZquery_paramsZ	new_queryZ	new_partsr   r&   r   update_query   s    

r6   c                 C   s
   d | S )zConverts scope value to a string suitable for sending to OAuth 2.0
    authorization servers.

    Args:
        scopes (Sequence[str]): The sequence of scopes to convert.

    Returns:
        str: The scopes formatted as a single string.
     )joinZscopesr   r   r   scopes_to_string   s    
r:   c                 C   s   | sg S |  dS )zConverts stringifed scopes value to a list.

    Args:
        scopes (Union[Sequence, str]): The string of space-separated scopes
            to convert.
    Returns:
        Sequence(str): The separated scopes.
    r7   )splitr9   r   r   r   string_to_scopes   s    	r<   c                 C   s(   t | }|dt| d   }t|S )zDecodes base64 strings lacking padding characters.

    Google infrastructure tends to omit the base64 padding characters.

    Args:
        value (Union[str, bytes]): The encoded value.

    Returns:
        bytes: The decoded value
       =   )r!   lenbase64urlsafe_b64decode)r   Z	b64stringpaddedr   r   r   padded_urlsafe_b64decode   s    rC   c                 C   s   t | dS )au  Encodes base64 strings removing any padding characters.

    `rfc 7515`_ defines Base64url to NOT include any padding
    characters, but the stdlib doesn't do that by default.

    _rfc7515: https://tools.ietf.org/html/rfc7515#page-6

    Args:
        value (Union[str|bytes]): The bytes-like value to encode

    Returns:
        Union[str|bytes]: The encoded value
    r=   )r@   urlsafe_b64encoderstripr   r   r   r   unpadded_urlsafe_b64encode   s    rF   c                   C   s
   t jdkS )zCheck if the Python interpreter is Python 2 or 3.

    Returns:
        bool: True if the Python interpreter is Python 3 and False otherwise.
    )   r   )sysversion_infor   r   r   r   is_python_3   s    rJ   )r   )N)r   r@   r   r   rH   r   Z	six.movesr   	timedeltaZREFRESH_THRESHOLDr   r   r   r!   r#   r6   r:   r<   rC   rF   rJ   r   r   r   r   <module>   s$   "	

-