o
    y¨Êh¾	  ã                   @   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 zddl	m
Z
 W n ey1   ddlm
Z
 Y nw zddlmZ W n eyI   ddlmZ Y nw 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   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 © ©r   ©Ú.0Úsr
   r
   úO/var/www/html/env/lib/python3.10/site-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.
    Ú80Ú443)ÚHTTPÚHTTPSú:é   )r   r   ÚgetÚupper)	r    Údefault_portsÚschÚnetlocÚpathÚparr   ÚfraÚportr
   r
   r   Úhost_from_uri4   s   þþr2   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ó   ~)Úsafe)r   r   r   r   Úencode)Úur
   r
   r   ÚescapeG   s   
r7   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 )ÚdatetimeÚnowÚmicrosecondsÚsecondsÚdaysr   )Ú
issue_timeÚtdÚager
   r
   r   Úgenerate_ageR   s   ÿÿrA   c                 C   s   t j d¡rdS |  ¡  d¡S )zCheck if the uri is over ssl.ÚOAUTHLIB_INSECURE_TRANSPORTTzhttps://)ÚosÚenvironr)   ÚlowerÚ
startswith)r    r
   r
   r   Úis_secure_transportZ   s   rG   )Ú__doc__Ú
__future__r   r   r9   rC   Úoauthlib.commonr   r   Úurllibr   ÚImportErrorÚurllib.parser   r   r   r"   r2   r7   rA   rG   r
   r
   r
   r   Ú<module>   s,   ÿÿ

