+#!/usr/bin/python2
+
+# Copyright (c) 2003 Intel Corporation
+# All rights reserved.
+#
+# Copyright (c) 2004-2006 The Trustees of Princeton University
+# All rights reserved.
+
+
import xmlrpclib
import xml.parsers.expat
import hmac
except KeyError, e:
return None
- msg= serialize_params(call_params)
- node_hmac= hmac.new(node_key,msg,sha).hexdigest()
+ params= serialize_params(call_params)
+ params.sort()
+ msg= "[" + "".join(params) + "]"
+ node_hmac= hmac.new(node_key,msg.encode('utf-8'),sha).hexdigest()
auth['value']= node_hmac
return auth
them into one long string encased in a set of braces.
"""
- # if there are no parameters, just return empty paren set
- if len(call_params) == 0:
- return "[]"
-
values= []
for param in call_params:
if isinstance(param,list) or isinstance(param,tuple):
- values= values + map(str,param)
+ values += serialize_params(param)
elif isinstance(param,dict):
- values= values + collapse_dict(param)
+ values += serialize_params(param.values())
+ elif isinstance(param,xmlrpclib.Boolean):
+ # bool was not a real type in Python <2.3 and had to be
+ # marshalled as a custom type in xmlrpclib. Make sure that
+ # bools serialize consistently.
+ if param:
+ values.append("True")
+ else:
+ values.append("False")
else:
- values.append( str(param) )
+ values.append(unicode(param))
- values.sort()
- values= "[" + string.join(values,"") + "]"
return values
-def collapse_dict( value ):
- """
- given a dictionary, return a list of all the keys and values as strings,
- in no particular order
- """
-
- item_list= []
-
- if not isinstance(value,dict):
- return item_list
-
- for key in value.keys():
- key_value= value[key]
- if isinstance(key_value,list) or isinstance(key_value,tuple):
- item_list= item_list + map(str,key_value)
- elif isinstance(key_value,dict):
- item_list= item_list + collapse_dict(key_value)
- else:
- item_list.append( str(key_value) )
-
- return item_list
-
-
-
def call_api_function( vars, function, user_params ):
"""
call the named api function with params, and return the