#NEWLINE# def _normalize_params( params ) : #NEWLINE# #INDENT# '\n    Returns a normalized query string sorted first by key, then by value\n    excluding the ``realm`` and ``oauth_signature`` parameters\n    as specified here: http://oauth.net/core/1.0a/#rfc.section.9.1.1\n    \n    :param params:\n        :class:`dict` or :class:`list` of tuples.\n    ' #NEWLINE# if ( type ( params ) == dict ) : #NEWLINE# #INDENT# params = list ( params . items ( ) ) #NEWLINE# #UNINDENT# params = [ ( k , v ) for ( k , v ) in qs if ( k not in ( 'oauth_signature' , 'realm' ) ) ] #NEWLINE# params . sort ( ) #NEWLINE# qs = parse . urlencode ( params ) #NEWLINE# qs = qs . replace ( '+' , '%20' ) #NEWLINE# qs = qs . replace ( '%7E' , '~' ) #NEWLINE# return qs