a \`5 @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)quoteunquoteZ>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)paramsargskwargstargetA/usr/lib/python3.9/site-packages/oauthlib/oauth1/rfc5849/utils.pywrapperszfilter_params..wrapper)__doc__)r r r rr filter_paramss rcCs:dd}t|tr(tt|t|Stt||SdS)zARemoves all non oauth parameters from a dict or a list of params.cSs|ddS)NrZoauth_) startswith)Zkvr r r !z%filter_oauth_params..N) isinstancedictlistfilteritems)rZis_oauthr r r rs rcCs.t|ts"tdd|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  rcCst|tstdt|S)Nz%Only unicode objects are unescapable.)rrrrrr r r unescape8s r cCs t|S)z1A unicode-safe version of urllib2.parse_keqv_list)urllib2parse_keqv_list)lr r r r">sr"cCs t|S)z1A unicode-safe version of urllib2.parse_http_list)r!parse_http_listrr r r r$Dsr$c Csld}|dt||r`t|t|d}ztt|WSttfy^Yn0tddS)z;Parse an OAuth authorization header into a list of 2-tupleszOAuth NzMalformed authorization header) lowerlenrr$rr"r IndexErrorr)Zauthorization_headerZ auth_schemerr r r parse_authorization_headerJsr()r Zurllib.requestZrequestr!Zoauthlib.commonrrZUNICODE_ASCII_CHARACTER_SETrrrr r"r$r(r r r r s