o
    ‘¸õaŸ  ã                   @   sl   d Z ddlZddlZddlmZmZ ddlmZ 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.
é    N)ÚquoteÚurlparse)Ú	urldecodec                 C   sF   t | tƒs	| du r| S t | tttfƒrd dd„ | D ƒ¡S td|  ƒ‚)z5Convert a list of scopes to a space separated string.Nú c                 S   ó   g | ]}t |ƒ‘qS © ©Ústr©Ú.0Úsr   r   ú?/usr/lib/python3/dist-packages/oauthlib/oauth2/rfc6749/utils.pyÚ
<listcomp>   ó    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   s8   t | tttfƒrdd„ | D ƒS | du rdS |  ¡  d¡S )z5Convert a space separated string to a list of scopes.c                 S   r   r   r   r
   r   r   r   r      r   z!scope_to_list.<locals>.<listcomp>Nr   )r   r   r   r   ÚstripÚsplitr   r   r   r   Úscope_to_list   s
   r   c                 C   s.   t tt| ƒjƒƒ}d|v rt|d ƒ|d< |S )Nr   )Údictr   r   Úqueryr   )ÚuriÚparamsr   r   r   Úparams_from_uri"   s   r    c           	      C   sT   dddœ}t | ƒ\}}}}}}d|v r| dd¡\}}||fS | | ¡ ¡}||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_uri)   s   þþr&   c                 C   s$   t | tƒs	tdƒ‚t|  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   Úescape<   s   
r*   c                 C   s8   t j  ¡ |  }|j|j|jd d  d  d }t|ƒS )z9Generate a age parameter for MAC authentication draft 00.é   i  i@B )ÚdatetimeZnowZmicrosecondsZsecondsZdaysr	   )Z
issue_timeZtdZager   r   r   Úgenerate_ageG   s   ÿÿr-   c                 C   s   t j d¡rdS |  ¡  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_transportO   s   r2   )Ú__doc__r,   r.   Zurllib.parser   r   Zoauthlib.commonr   r   r   r    r&   r*   r-   r2   r   r   r   r   Ú<module>   s    

