
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
,î[¾	  ã               @   sÔ   d Z ddlmZmZ ddlZddlZddlmZmZ yddl	m
Z
 W n  ek
rd   ddlm
Z
 Y nX yddlmZ W n  ek
r–   ddlmZ Y nX dd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )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)Úurlparsec             C   sJ   t | tƒs| dkr| S t | tttfƒr:djdd„ | D ƒƒS td|  ƒ‚dS )z5Convert a list of scopes to a space separated string.Nú c             S   s   g | ]}t |ƒ‘qS © )r   )Ú.0Úsr	   r	   ú/usr/lib/python3.6/utils.pyú
<listcomp>   s    z!list_to_scope.<locals>.<listcomp>z8Invalid scope (%s), must be string, tuple, set, or list.)Ú
isinstancer   ÚsetÚtupleÚlistÚjoinÚ
ValueError)Úscoper	   r	   r   Úlist_to_scope   s
    r   c             C   s<   t | tttfƒrdd„ | D ƒS | dkr*dS | jƒ jdƒS dS )z5Convert a space separated string to a list of scopes.c             S   s   g | ]}t |ƒ‘qS r	   )r   )r
   r   r	   r	   r   r   &   s    z!scope_to_list.<locals>.<listcomp>Nr   )r   r   r   r   ÚstripÚsplit)r   r	   r	   r   Úscope_to_list#   s
    r   c             C   s.   t tt| ƒjƒƒ}d|kr*t|d ƒ|d< |S )Nr   )Údictr   r   Úqueryr   )ÚuriZparamsr	   r	   r   Úparams_from_uri-   s    r   c       	      C   sN   dddœ}t | ƒ\}}}}}}d|kr8|jddƒ\}}n|j|jƒ ƒ}||fS )zuExtract hostname and port from URI.

    Will use default port for HTTP and HTTPS if none is present in the URI.
    Z80Z443)ZHTTPZHTTPSú:é   )r   r   ÚgetÚupper)	r   Zdefault_portsZschZnetlocÚpathZparr   ZfraZportr	   r	   r   Úhost_from_uri4   s    r"   c             C   s$   t | tƒstdƒ‚t| jdƒdd�S )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.zutf-8ó   ~)Zsafe)r   r   r   r   Úencode)Úur	   r	   r   ÚescapeG   s    
r&   c             C   s8   t j jƒ |  }|j|j|jd d  d  d }t|ƒS )z9Generate a age parameter for MAC authentication draft 00.é   i  é
   é   i@B i@B )ÚdatetimeZnowZmicrosecondsZsecondsZdaysr   )Z
issue_timeZtdZager	   r	   r   Úgenerate_ageR   s    r+   c             C   s   t jjdƒrdS | jƒ jdƒS )zCheck if the uri is over ssl.ZOAUTHLIB_INSECURE_TRANSPORTTzhttps://)ÚosÚenvironr   ÚlowerÚ
startswith)r   r	   r	   r   Úis_secure_transportZ   s    r0   )Ú__doc__Z
__future__r   r   r*   r,   Zoauthlib.commonr   r   Zurllibr   ÚImportErrorZurllib.parser   r   r   r   r"   r&   r+   r0   r	   r	   r	   r   Ú<module>   s&   

