3 ,î[¾ ã@sÔdZddlmZmZddlZddlZddlmZmZyddl m Z Wn e k rdddl m Z YnXyddl m Z Wn e k r–ddl m Z YnXdd„Zd d „Zd d „Zd d„Zdd„Zdd„Zdd„ZdS)zp oauthlib.utils ~~~~~~~~~~~~~~ This module contains utility methods used by various parts of the OAuth 2 spec. é)Úabsolute_importÚunicode_literalsN)Ú unicode_typeÚ urldecode)Úquote)ÚurlparsecCsJt|tƒs|dkr|St|tttfƒr:djdd„|DƒƒStd|ƒ‚dS)z5Convert a list of scopes to a space separated string.Nú cSsg|] }t|ƒ‘qS©)r)Ú.0Úsr r ú/usr/lib/python3.6/utils.pyú sz!list_to_scope..z8Invalid scope (%s), must be string, tuple, set, or list.)Ú isinstancerÚsetÚtupleÚlistÚjoinÚ ValueError)Úscoper r r Ú list_to_scopes rcCs<t|tttfƒrdd„|DƒS|dkr*dS|jƒjdƒSdS)z5Convert a space separated string to a list of scopes.cSsg|] }t|ƒ‘qSr )r)r r r r r r &sz!scope_to_list..Nr)rrrrÚstripÚsplit)rr r r Ú scope_to_list#s rcCs.ttt|ƒjƒƒ}d|kr*t|dƒ|d<|S)Nr)ÚdictrrÚqueryr)ÚuriZparamsr r r Úparams_from_uri-src CsNdddœ}t|ƒ\}}}}}}d|kr8|jddƒ\}}n|j|jƒƒ}||fS)zuExtract hostname and port from URI. Will use default port for HTTP and HTTPS if none is present in the URI. Z80Z443)ZHTTPZHTTPSú:é)rrÚgetÚupper) rZ default_portsZschZnetlocÚpathZparrZfraZportr r r Ú host_from_uri4sr"cCs$t|tƒstdƒ‚t|jdƒddS)ztEscape a string in an OAuth-compatible fashion. TODO: verify whether this can in fact be used for OAuth 2 z#Only unicode objects are escapable.zutf-8ó~)Zsafe)rrrrÚencode)Úur r r ÚescapeGs r&cCs8tjjƒ|}|j|j|jdddd}t|ƒS)z9Generate a age parameter for MAC authentication draft 00.éié éi@Bi@B)ÚdatetimeZnowZ microsecondsZsecondsZdaysr)Z issue_timeZtdZager r r Ú generate_ageRs r+cCstjjdƒrdS|jƒjdƒS)zCheck if the uri is over ssl.ZOAUTHLIB_INSECURE_TRANSPORTTzhttps://)ÚosÚenvironrÚlowerÚ startswith)rr r r Úis_secure_transportZs r0)Ú__doc__Z __future__rrr*r,Zoauthlib.commonrrZurllibrÚ ImportErrorZ urllib.parserrrrr"r&r+r0r r r r Ús&