o a5 @s`dZddlmZddlmZmZdZddZddZ d d Z d d Z d dZ ddZ ddZdS)zn oauthlib.utils ~~~~~~~~~~~~~~ This module contains utility methods used by various parts of the OAuth spec. N)quoteunquote>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789csfdd}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. cst|}|g|Ri|S)N)filter_oauth_params)paramsargskwargstarget?/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/utils.pywrapperszfilter_params..wrapper)__doc__)r r r r r filter_paramss rcCs6dd}t|trtt|t|Stt||S)zARemoves all non oauth parameters from a dict or a list of params.cSs|ddS)Nroauth_) startswith)kvr r r !sz%filter_oauth_params..) isinstancedictlistfilteritems)ris_oauthr r r rs rcCs.t|tstdd|t|t|ddS)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. zGot {!r} of type {}.~)safe)rstr ValueErrorformattyperur r r escape(s  r"cCst|ts tdt|S)Nz%Only unicode objects are unescapable.)rrrrr r r r unescape8s r#cC t|S)z1A unicode-safe version of urllib2.parse_keqv_list)urllib2parse_keqv_list)lr r r r&> r&cCr$)z1A unicode-safe version of urllib2.parse_http_list)r%parse_http_listr r r r r)Dr(r)c Csnd}|dt||r3t|t|d}z tt|WSttfy2Ytdwtd)z;Parse an OAuth authorization header into a list of 2-tupleszOAuth NzMalformed authorization header) lowerlenrr)rr&r IndexErrorr)authorization_header auth_schemerr r r parse_authorization_headerJsr/)rurllib.requestrequestr%oauthlib.commonrrUNICODE_ASCII_CHARACTER_SETrrr"r#r&r)r/r r r r s