def _oauth_signature(consumer_token, method, url, parameters={}, token=None):
 parts = urlparse.urlparse(url)
 (scheme, netloc, path) = parts[:3]
 normalized_url = (((scheme.lower() + '://') + netloc.lower()) + path)
 base_elems = []
 base_elems.append(method.upper())
 base_elems.append(normalized_url)
 base_elems.append('&'.join((('%s=%s' % (k, _oauth_escape(str(v)))) for (k, v) in sorted(parameters.items()))))
 base_string = '&'.join((_oauth_escape(e) for e in base_elems))
 key_elems = [escape.utf8(consumer_token['secret'])]
 key_elems.append(escape.utf8((token['secret'] if token else '')))
 key = '&'.join(key_elems)
 hash = hmac.new(key, escape.utf8(base_string), hashlib.sha1)
 return binascii.b2a_base64(hash.digest())[:(-1)]

def _oauth_signature ( consumer_token , method , url , parameters = { } , token = None ) : parts = urlparse . urlparse ( url ) ( scheme , netloc , path ) = parts [ : 3 ] normalized_url = ( ( ( scheme . lower ( ) + '://' ) + netloc . lower ( ) ) + path ) base_elems = [ ] base_elems . append ( method . upper ( ) ) base_elems . append ( normalized_url ) base_elems . append ( '&' . join ( ( ( '%s=%s' % ( k , _oauth_escape ( str ( v ) ) ) ) for ( k , v ) in sorted ( parameters . items ( ) ) ) ) ) base_string = '&' . join ( ( _oauth_escape ( e ) for e in base_elems ) ) key_elems = [ escape . utf8 ( consumer_token [ 'secret' ] ) ] key_elems . append ( escape . utf8 ( ( token [ 'secret' ] if token else '' ) ) ) key = '&' . join ( key_elems ) hash = hmac . new ( key , escape . utf8 ( base_string ) , hashlib . sha1 ) return binascii . b2a_base64 ( hash . digest ( ) ) [ : ( - 1 ) ]
calculates the hmac-sha1 oauth signature for the given request .