ó
O'^c           @@ sş   d  Z  d d l m Z m Z y d d l Z Wn  e k
 rN d d l j Z n Xd d l m	 Z	 m
 Z
 m Z m Z d Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d S(   un   
oauthlib.utils
~~~~~~~~~~~~~~

This module contains utility methods used by various parts of the OAuth
spec.
i    (   t   absolute_importt   unicode_literalsN(   t   quotet   unquotet
   bytes_typet   unicode_typeu>   abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c         @ s     f d   }   j  | _  | S(   u§   Decorator which filters params to remove non-oauth_* parameters

    Assumes the decorated method takes a params dict or list of tuples as its
    first argument.
    c         @ s   t  |   }    |  | |  S(   N(   t   filter_oauth_params(   t   paramst   argst   kwargs(   t   target(    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   wrapper   s    (   t   __doc__(   R
   R   (    (   R
   s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   filter_params   s    c         C@ sN   d   } t  |  t  r7 t t | t |  j      St t | |    Sd S(   uA   Removes all non oauth parameters from a dict or a list of params.c         S@ s   |  d j  d  S(   Ni    u   oauth_(   t
   startswith(   t   kv(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   <lambda>'   t    N(   t
   isinstancet   dictt   listt   filtert   items(   R   t   is_oauth(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyR   %   s    	c         C@ sB   t  |  t  s2 t d d |  t |   f   n  t |  d d S(   uİ   Escape a unicode string in an OAuth-compatible fashion.

    Per `section 3.6`_ of the spec.

    .. _`section 3.6`: http://tools.ietf.org/html/rfc5849#section-3.6

    u$   Only unicode objects are escapable. u   Got %s of type %s.t   safet   ~(   R   R   t
   ValueErrort   typeR   (   t   u(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   escape.   s    c         C@ s(   t  |  t  s t d   n  t |   S(   Nu%   Only unicode objects are unescapable.(   R   R   R   R   (   R   (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   unescape>   s    c         C@ s   t  j |   S(   u1   A unicode-safe version of urllib2.parse_keqv_list(   t   urllib2t   parse_keqv_list(   t   l(    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyR    D   s    c         C@ s   t  j |   S(   u1   A unicode-safe version of urllib2.parse_http_list(   R   t   parse_http_list(   R   (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyR"   J   s    c         C@ s   d j    } |  t |   j    j |  rx t |  t |   } y t t |  j    SWqx t t f k
 rt qx Xn  t d   d S(   u;   Parse an OAuth authorization header into a list of 2-tuplesu   OAuth u   Malformed authorization headerN(	   t   lowert   lenR   R"   R   R    R   t
   IndexErrorR   (   t   authorization_headert   auth_schemeR   (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   parse_authorization_headerP   s    (   R   t
   __future__R    R   R   t   ImportErrort   urllib.requestt   requestt   oauthlib.commonR   R   R   R   t   UNICODE_ASCII_CHARACTER_SETR   R   R   R   R    R"   R(   (    (    (    s?   /tmp/pip-unpacked-wheel-eAx2J6/oauthlib/oauth1/rfc5849/utils.pyt   <module>   s   "							