3 L(ÌYSã@s�dZddlZddlZddlZddlZddlmZdZejed�Z dd„Z dd „Z d d „Z dd d„Z dd„Zddd„Zdd„Zdd„Zdd„ZdS)z-Helper functions for commonly used utilities.éN)Úurllibi,)Úsecondscs‡fdd„}|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&|jrtdƒ‚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. zMethod already has a docstring.)Ú__doc__Ú ValueErrorÚgetattrÚ__name__)ÚmethodZ source_method)Ú source_class©úC/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 tjjƒS)z_Returns the current UTC datetime. Returns: datetime: The current time in UTC. )ÚdatetimeÚutcnowr r r r r=srcCstj|jƒƒS)zÒConvert 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_secsFs rúutf-8cCs<t|tjƒr|j|ƒn|}t|tjƒr*|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)Ú isinstanceÚsixÚ text_typeÚencodeÚ binary_typerÚformat)rÚencodingÚresultr r r Úto_bytesRs rcCs<t|tjƒr|jdƒn|}t|tjƒr*|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)rrrÚdecoderrr)rrr r r Ú from_bytesls  r cspˆdkr g‰tjj|ƒ}tjj|jƒ}|j|ƒ‡fdd„tj|ƒDƒ}tjj|dd�}|j |d�}tjj |ƒ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 Ncsi|]\}}|ˆkr||“qSr r )Ú.0Úkeyr)Úremover r ú ¥sz update_query..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    r2cCs dj|ƒS)zôConverts 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_string°s r6cCs|sgS|jdƒS)zÙConverts 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_scopes½s r8cCs(t|ƒ}|dt|ƒ d}tj|ƒS)zïDecodes 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)rZ b64stringZpaddedr r r Úpadded_urlsafe_b64decodeÌs r>)r)N)rr<rrrZ six.movesrZCLOCK_SKEW_SECSÚ timedeltaZ CLOCK_SKEWr rrrr r2r6r8r>r r r r Ús       .