3 L(YS@sdZddlZddlZddlZddlZddlmZdZejedZ ddZ dd Z d d Z dd dZ ddZdddZddZddZddZdS)z-Helper functions for commonly used utilities.N)urllibi,)secondscsfdd}|S)a0Decorator 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. cs&|jrtdt|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. zMethod already has a docstring.)__doc__ ValueErrorgetattr__name__)methodZ source_method) source_classC/private/tmp/pip-build-nl73fm5q/google-auth/google/auth/_helpers.py decorator's  z!copy_docstring..decoratorr )r r r )r r copy_docstrings r cCs tjjS)z_Returns the current UTC datetime. Returns: datetime: The current time in UTC. )datetimeutcnowr r r r r=srcCstj|jS)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. )calendartimegm utctimetuple)valuer r r datetime_to_secsFs rutf-8cCs<t|tjr|j|n|}t|tjr*|Stdj|dS)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) isinstancesix text_typeencode binary_typerformat)rencodingresultr r r to_bytesRs rcCs<t|tjr|jdn|}t|tjr*|Stdj|dS)aVConverts 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. zutf-8z'{0!r} could not be converted to unicodeN)rrrdecoderrr)rrr r r from_bytesls  r cspdkr gtjj|}tjj|j}|j|fddtj|D}tjj|dd}|j |d}tjj |S)aUpdates 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 Ncsi|]\}}|kr||qSr r ).0keyr)remover r sz update_query..T)doseq)query) rparseurlparseparse_qsr&updater iteritems urlencode_replace urlunparse)urlparamsr#partsZ query_paramsZ new_queryZ new_partsr )r#r update_querys    r2cCs dj|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)scopesr r r scopes_to_strings r6cCs|sgS|jdS)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. r3)split)r5r r r string_to_scopess r8cCs(t|}|dt| d}tj|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 =)rlenbase64urlsafe_b64decode)rZ b64stringZpaddedr r r padded_urlsafe_b64decodes r>)r)N)rr<rrrZ six.movesrZCLOCK_SKEW_SECS timedeltaZ CLOCK_SKEWr rrrr r2r6r8r>r r r r s       .