ó
O'—^c           @@ sı   d  Z  d d l m Z m Z d d l Z d d l Z y d d l m Z Wn! e k
 rk d d l	 m Z n Xy d d l
 m
 Z
 Wn! e k
 r£ d d l	 m
 Z
 n Xd d l m Z m Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d S(   up   
oauthlib.utils
~~~~~~~~~~~~~~

This module contains utility methods used by various parts of the OAuth 2 spec.
i    (   t   absolute_importt   unicode_literalsN(   t   quote(   t   urlparse(   t   unicode_typet	   urldecodec         C@ sq   t  |  t ƒ s |  d k r |  St  |  t t t f ƒ r] d j g  |  D] } t | ƒ ^ qD ƒ St d |  ƒ ‚ d S(   u5   Convert a list of scopes to a space separated string.u    u8   Invalid scope (%s), must be string, tuple, set, or list.N(   t
   isinstanceR   t   Nonet   sett   tuplet   listt   joint
   ValueError(   t   scopet   s(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   list_to_scope   s
    &c         C@ s\   t  |  t t t f ƒ r5 g  |  D] } t | ƒ ^ q S|  d k rE d S|  j ƒ  j d ƒ Sd S(   u5   Convert a space separated string to a list of scopes.u    N(   R   R	   R
   R   R   R   t   stript   split(   R   R   (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   scope_to_list!   s
    c         C@ sB   t  t t |  ƒ j ƒ ƒ } d | k r> t | d ƒ | d <n  | S(   Nu   scope(   t   dictR   R   t   queryR   (   t   urit   params(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   params_from_uri+   s    c   	      C@ sx   i d d 6d d 6} t  |  ƒ \ } } } } } } d | k rY | j d d ƒ \ } } n | j | j ƒ  ƒ } | | f S(   uu   Extract hostname and port from URI.

    Will use default port for HTTP and HTTPS if none is present in the URI.
    u   80u   HTTPu   443u   HTTPSu   :i   (   R   R   t   gett   upper(	   R   t   default_portst   scht   netloct   patht   parR   t   frat   port(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   host_from_uri2   s    
c         C@ s7   t  |  t ƒ s t d ƒ ‚ n  t |  j d ƒ d d ƒS(   ut   Escape a string in an OAuth-compatible fashion.

    TODO: verify whether this can in fact be used for OAuth 2

    u#   Only unicode objects are escapable.u   utf-8t   safet   ~(   R   R   R   R   t   encode(   t   u(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   escapeE   s    c         C@ sD   t  j  j ƒ  |  } | j | j | j d d d d } t | ƒ S(   u9   Generate a age parameter for MAC authentication draft 00.i   i  i
   i   i@B i@B (   t   datetimet   nowt   microsecondst   secondst   daysR   (   t
   issue_timet   tdt   age(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   generate_ageP   s    c         C@ s)   t  j j d ƒ r t S|  j ƒ  j d ƒ S(   u   Check if the uri is over ssl.u   OAUTHLIB_INSECURE_TRANSPORTu   https://(   t   ost   environR   t   Truet   lowert
   startswith(   R   (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   is_secure_transportX   s    (   t   __doc__t
   __future__R    R   R0   R'   t   urllibR   t   ImportErrort   urllib.parseR   t   oauthlib.commonR   R   R   R   R   R!   R&   R/   R5   (    (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth2/rfc6749/utils.pyt   <module>   s&   	
	
				