<s> from __future__ import absolute_import , unicode_literals <EOL> """<STR_LIT>""" <EOL> try : <EOL> import urllib2 <EOL> except ImportError : <EOL> import urllib . request as urllib2 <EOL> from oauthlib . common import quote , unquote , bytes_type , unicode_type <EOL> UNICODE_ASCII_CHARACTER_SET = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def filter_params ( target ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( params , * args , ** kwargs ) : <EOL> params = filter_oauth_params ( params ) <EOL> return target ( params , * args , ** kwargs ) <EOL> wrapper . __doc__ = target . __doc__ <EOL> return wrapper <EOL> def filter_oauth_params ( params ) : <EOL> """<STR_LIT>""" <EOL> is_oauth = lambda kv : kv [ <NUM_LIT:0> ] . startswith ( "<STR_LIT>" ) <EOL> if isinstance ( params , dict ) : <EOL> return list ( filter ( is_oauth , list ( params . items ( ) ) ) ) <EOL> else : <EOL> return list ( filter ( is_oauth , params ) ) <EOL> def escape ( u ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( u , unicode_type ) : <EOL> raise ValueError ( '<STR_LIT>' + <EOL> '<STR_LIT>' % ( u , type ( u ) ) ) <EOL> return quote ( u , safe = b'<STR_LIT>' ) <EOL> def unescape ( u ) : <EOL> if not isinstance ( u , unicode_type ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return unquote ( u ) <EOL> def urlencode ( query ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( query , dict ) : <EOL> query = query . items ( ) <EOL> return "<STR_LIT:&>" . join ( [ '<STR_LIT:=>' . join ( [ escape ( k ) , escape ( v ) ] ) for k , v in query ] ) <EOL> def parse_keqv_list ( l ) : <EOL> """<STR_LIT>""" <EOL> return urllib2 . parse_keqv_list ( l ) <EOL> def parse_http_list ( u ) : <EOL> """<STR_LIT>""" <EOL> return urllib2 . parse_http_list ( u ) <EOL> def parse_authorization_header ( authorization_header ) : <EOL> """<STR_LIT>""" <EOL> auth_scheme = '<STR_LIT>' . lower ( ) <EOL> if authorization_header [ : len ( auth_scheme ) ] . lower ( ) . startswith ( auth_scheme ) : <EOL> items = parse_http_list ( authorization_header [ len ( auth_scheme ) : ] ) <EOL> try : <EOL> return list ( parse_keqv_list ( items ) . items ( ) ) <EOL> except ( IndexError , ValueError ) : <EOL> pass <EOL> raise ValueError ( '<STR_LIT>' ) </s>
