<s> from __future__ import absolute_import , unicode_literals <EOL> """<STR_LIT>""" <EOL> try : <EOL> from urlparse import urlparse , urlunparse <EOL> except ImportError : <EOL> from urllib . parse import urlparse , urlunparse <EOL> from . import utils <EOL> from oauthlib . common import extract_params , urlencode <EOL> @ utils . filter_params <EOL> def prepare_headers ( oauth_params , headers = None , realm = None ) : <EOL> """<STR_LIT>""" <EOL> headers = headers or { } <EOL> authorization_header_parameters_parts = [ ] <EOL> for oauth_parameter_name , value in oauth_params : <EOL> escaped_name = utils . escape ( oauth_parameter_name ) <EOL> escaped_value = utils . escape ( value ) <EOL> part = '<STR_LIT>' . format ( escaped_name , escaped_value ) <EOL> authorization_header_parameters_parts . append ( part ) <EOL> authorization_header_parameters = '<STR_LIT:U+002CU+0020>' . join ( <EOL> authorization_header_parameters_parts ) <EOL> if realm : <EOL> authorization_header_parameters = ( '<STR_LIT>' % realm + <EOL> authorization_header_parameters ) <EOL> authorization_header = '<STR_LIT>' % authorization_header_parameters <EOL> full_headers = { } <EOL> full_headers . update ( headers ) <EOL> full_headers [ '<STR_LIT>' ] = authorization_header <EOL> return full_headers <EOL> def _append_params ( oauth_params , params ) : <EOL> """<STR_LIT>""" <EOL> merged = list ( params ) <EOL> merged . extend ( oauth_params ) <EOL> merged . sort ( key = lambda i : i [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) ) <EOL> return merged <EOL> def prepare_form_encoded_body ( oauth_params , body ) : <EOL> """<STR_LIT>""" <EOL> return _append_params ( oauth_params , body ) <EOL> def prepare_request_uri_query ( oauth_params , uri ) : <EOL> """<STR_LIT>""" <EOL> sch , net , path , par , query , fra = urlparse ( uri ) <EOL> query = urlencode ( _append_params ( oauth_params , extract_params ( query ) or [ ] ) ) <EOL> return urlunparse ( ( sch , net , path , par , query , fra ) ) </s>
