
    g,                          d Z ddlZddlZddlZddlmZ ddlZddlZddlm	Z	  ej                  dd      Zd Zd	 Zd
 Zd ZddZd ZddZd Zd Zd Zd Zd Zy)z-Helper functions for commonly used utilities.    N)Message)
exceptions   -   )minutessecondsc                       f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                     | j                   rt        j                  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:
            google.auth.exceptions.InvalidOperation: if the method already has a docstring.
        zMethod already has a docstring.)__doc__r   InvalidOperationgetattr__name__)methodsource_methodsource_classs     q/var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/google/auth/_helpers.py	decoratorz!copy_docstring.<locals>.decorator*   s@     >>--.OPPfoo>&..     )r   r   s   ` r   copy_docstringr      s    ( r   c                 @    t               }| |d<   |j                         S )a  Parse a 'content-type' header value to get just the plain media-type (without parameters).

    This is done using the class Message from email.message as suggested in PEP 594
        (because the cgi is now deprecated and will be removed in python 3.13,
        see https://peps.python.org/pep-0594/#cgi).

    Args:
        header_value (str): The value of a 'content-type' header as a string.

    Returns:
        str: A string with just the lowercase media-type from the parsed 'content-type' header.
            If the provided content-type is not parsable, returns 'text/plain',
            the default value for textual files.
    zcontent-type)r   get_content_type)header_valuems     r   parse_content_typer   A   s&     		A$An	r   c                      t         j                   j                  t         j                  j                        } | j	                  d      } | S )z_Returns the current UTC datetime.

    Returns:
        datetime: The current time in UTC.
    N)tzinfo)datetimenowtimezoneutcreplace)r   s    r   utcnowr#   W   s;     



 1 1 5 5
6C
++T+
"CJr   c                 H    t        j                  | j                               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values    r   datetime_to_secsr*   g   s     ??5--/00r   c                     t        | t              r| j                  |      n| }t        |t              r|S t	        j
                  dj                  |             )a  Converts a string value to bytes, if necessary.

    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:
        google.auth.exceptions.InvalidValue: If the value could not be converted to bytes.
    z%{0!r} could not be converted to bytes)
isinstancestrencodebytesr   InvalidValueformat)r)   encodingresults      r   to_bytesr4   s   sM     (2%'=U\\(#5F&% %%3::5A
 	
r   c                     t        | t              r| j                  d      n| }t        |t              r|S t	        j
                  dj                  |             )ao  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:
        google.auth.exceptions.InvalidValue: If the value could not be converted to unicode.
    utf-8z'{0!r} could not be converted to unicode)r,   r/   decoder-   r   r0   r1   )r)   r3   s     r   
from_bytesr8      sM     '1&>U\\'"EF&#%%5<<UC
 	
r   c                    |g }t         j                  j                  |       }t         j                  j                  |j                        }|j                  |       |j                         D ci c]  \  }}||vs|| }}}t         j                  j                  |d      }|j                  |      }t         j                  j                  |      S c c}}w )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

    T)doseq)query)
urllibparseurlparseparse_qsr;   updateitems	urlencode_replace
urlunparse)	urlparamsremovepartsquery_paramskeyr)   	new_query	new_partss	            r   update_queryrM      s    2 ~ LL!!#&E<<((5L &2%7%7%9!sES=NU
L  &&|4&@IY/I<<""9--s   1C>Cc                 $    dj                  |       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scopess    r   scopes_to_stringrS      s     88Fr   c                 ,    | sg S | j                  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.
    rO   )splitrQ   s    r   string_to_scopesrV      s     	<<r   c                 l    t        |       }|dt        |       dz  z  z   }t        j                  |      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
       =   )r4   lenbase64urlsafe_b64decode)r)   	b64stringpaddeds      r   padded_urlsafe_b64decoder_      s8     I#i.1!455F##F++r   c                 J    t        j                  |       j                  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
    rX   )r[   urlsafe_b64encoderstripr(   s    r   unpadded_urlsafe_b64encoderc      s      ##E*11$77r   c                  (    t         j                  dkD  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   r   )sysversion_infor   r   r   is_python_3rg     s     f$$r   )r6   )N)r   r[   r%   r   email.messager   re   r<   google.authr   	timedeltaREFRESH_THRESHOLDr   r   r#   r*   r4   r8   rM   rS   rV   r_   rc   rg   r   r   r   <module>rl      st    4    ! 
  " 'H&&q"= D, 	1
0
,*.Z
, 8"%r   