
    g
                         d Z ddlmZmZ ddlmZmZmZ 	 ddlZdZd Zd Zd Zd	 Zd
 Zd Zd Zy# e	$ r	 ddl
mZ Y %w xY w)zmoauthlib.utils ~~~~~~~~~~~~~~

This module contains utility methods used by various parts of the OAuth
spec.
    )absolute_importunicode_literals)quoteunicode_typeunquoteN>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789c                 4      fd} j                   |_         |S )zDecorator 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                 2    t        |       }  | g|i |S )N)filter_oauth_params)paramsargskwargstargets      0lib/third_party/oauthlib/oauth1/rfc5849/utils.pywrapperzfilter_params.<locals>.wrapper   s"     (F&*4*6**    )__doc__)r   r   s   ` r   filter_paramsr      s    + NN'/	.r   c           	          d }t        | t              r,t        t        |t        | j	                                           S t        t        ||             S )zARemoves all non oauth parameters from a dict or a list of params.c                 *    | d   j                  d      S )Nr   oauth_)
startswith)kvs    r   <lambda>z%filter_oauth_params.<locals>.<lambda>&   s    1((2r   )
isinstancedictlistfilteritems)r   is_oauths     r   r   r   $   s@    2(xflln!5677x())r   c           	      x    t        | t              st        dd| dt        |       dz         t	        | d      S )zEscape a unicode string in an OAuth-compatible fashion.

    Per `section 3.6`_ of the spec.

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

    z$Only unicode objects are escapable. zGot z	 of type .   ~)safe)r   r   
ValueErrortyper   us    r   escaper)   -   s>     
A|	$
;-.Q89 : : 
qt	r   c                 N    t        | t              st        d      t        |       S )Nz%Only unicode objects are unescapable.)r   r   r%   r   r'   s    r   unescaper+   =   s"    	A|	$
<
==	r   c                 ,    t        j                  |       S )z1A unicode-safe version of urllib2.parse_keqv_list)urllib2parse_keqv_list)ls    r   r.   r.   C        
	 	 	##r   c                 ,    t        j                  |       S )z1A unicode-safe version of urllib2.parse_http_list)r-   parse_http_listr'   s    r   r2   r2   I   r0   r   c                 @   dj                         }| dt        |       j                         j                  |      r:t        | t        |      d       }	 t	        t        |      j                               S t        d      # t        t        f$ r Y t        d      w xY w)z;Parse an OAuth authorization header into a list of 2-tupleszOAuth NzMalformed authorization header)	lowerlenr   r2   r   r.   r   
IndexErrorr%   )authorization_headerauth_schemer   s      r   parse_authorization_headerr9   O   s     ++3{+,224??L0[1A1BCDE/%(..011 	344 
# 
344s   !B BB)r   
__future__r   r   oauthlib.commonr   r   r   r-   ImportErrorurllib.requestrequestUNICODE_ASCII_CHARACTER_SETr   r   r)   r+   r.   r2   r9    r   r   <module>rA      s]   
 9 8 8# , 
* $$	5E  #"#s   2 A A 