3 ,[ @sdZddlmZmZddlmZmZmZmZy ddl Z Wne k rVddl j Z YnXdZ ddZdd Zd d Zd d ZddZddZddZdS)zn oauthlib.utils ~~~~~~~~~~~~~~ This module contains utility methods used by various parts of the OAuth spec. )absolute_importunicode_literals) bytes_typequote unicode_typeunquoteNZ>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|}|f||S)N)filter_oauth_params)paramsargskwargs)target/usr/lib/python3.6/utils.pywrapperszfilter_params..wrapper)__doc__)r rr )r r filter_paramss rcCs:dd}t|tr(tt|t|jStt||SdS)zARemoves all non oauth parameters from a dict or a list of params.cSs|djdS)NrZoauth_) startswith)Zkvr r r(sz%filter_oauth_params..N) isinstancedictlistfilteritems)r Zis_oauthr r rr&s rcCs.t|ts"tdd|t|ft|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 %s.~)Zsafe)rr ValueErrortyper)ur r rescape/s rcCst|tstdt|S)Nz%Only unicode objects are unescapable.)rrrr)rr r runescape?s rcCs tj|S)z1A unicode-safe version of urllib2.parse_keqv_list)urllib2parse_keqv_list)lr r rr Esr cCs tj|S)z1A unicode-safe version of urllib2.parse_http_list)rparse_http_list)rr r rr"Ksr"c Csldj}|dt|jj|r`t|t|d}ytt|jSttfk r^YnXtddS)z;Parse an OAuth authorization header into a list of 2-tupleszOAuth NzMalformed authorization header) lowerlenrr"rr r IndexErrorr)Zauthorization_headerZ auth_schemerr r rparse_authorization_headerQsr&)rZ __future__rrZoauthlib.commonrrrrr ImportErrorZurllib.requestZrequestZUNICODE_ASCII_CHARACTER_SETrrrrr r"r&r r r rs