Index: fedd/fedd_util.py
===================================================================
--- fedd/fedd_util.py	(revision 4ed10aefdf7652c7ea1c9a8488706ceb7c9436b8)
+++ fedd/fedd_util.py	(revision f8582c9a024862e2f99c61a303029f0c7929d8b3)
@@ -192,5 +192,4 @@
 	if attr: obj = attr()
 	else:
-	    print dir(container)
 	    raise TypeError("%s does not have a new_%s attribute" % \
 		    (container, name))
@@ -233,57 +232,58 @@
     else: 
 	return element
+def apply_to_tags(e, map):
+    """
+    Map is an iterable of ordered pairs (tuples) that map a key to a function.
+    This function walks the given message and replaces any object with a key in
+    the map with the result of applying that function to the object.
+    """
+    dict_type = type(dict())
+    list_type = type(list())
+    str_type = type(str())
+
+    if isinstance(e, dict_type):
+	for k in e.keys():
+	    for tag, fcn in map:
+		if k == tag:
+		    if isinstance(e[k], list_type):
+			e[k] = [ fcn(b) for b in e[k]]
+		    else:
+			e[k] = fcn(e[k])
+		elif isinstance(e[k], dict_type):
+		    apply_to_tags(e[k], map)
+		elif isinstance(e[k], list_type):
+		    for ee in e[k]:
+			apply_to_tags(ee, map)
+    # Other types end the recursion - they should be leaves
+    return e
+
+# These are all just specializations of apply_to_tags
+def fedids_to_obj(e, tags=('fedid',)):
+    """
+    Turn the fedids in a message that are encoded as bitstrings into fedid
+    objects.
+    """
+    map = [ (t, lambda x: fedid(bits=x)) for t in tags]
+    return apply_to_tags(e, map)
 
 def encapsulate_binaries(e, tags):
     """Walk through a message and encapsulate any dictionary entries in 
     tags into a binary object."""
-    dict_type = type(dict())
-    list_type = type(list())
-    str_type = type(str())
-
-    if isinstance(e, dict_type):
-	for k in e.keys():
-	    if k in tags:
-		if isinstance(e[k], list_type):
-		    bin_list = []
-		    for ee in e[k]:
-			if getattr(ee, 'pack_xmlrpc', None):
-			    bin_list.append(Binary(ee.pack_xmlrpc()))
-			else:
-			    bin_list.append(Binary(ee))
-		    e[k] = bin_list
-		elif getattr(e[k],'pack_xmlrpc', None):
-		    e[k] = Binary(e[k].pack_xmlrpc())
-		else:
-		    e[k] = Binary(e[k])
-	    elif isinstance(e[k], dict_type):
-		encapsulate_binaries(e[k], tags)
-	    elif isinstance(e[k], list_type):
-		for ee in e[k]:
-		    encapsulate_binaries(ee, tags)
-    # Other types end the recursion - they should be leaves
-    return e
+
+    def to_binary(o):
+	pack = getattr(o, 'pack_xmlrpc', None)
+	if callable(pack): return Binary(pack())
+	else: return Binary(o)
+
+    map = [ (t, to_binary) for t in tags]
+    return apply_to_tags(e, map)
 
 def decapsulate_binaries(e, tags):
     """Walk through a message and encapsulate any dictionary entries in 
     tags into a binary object."""
-    dict_type = type(dict())
-    list_type = type(list())
-    str_type = type(str())
-
-    if isinstance(e, dict_type):
-	for k in e.keys():
-	    if k in tags:
-		if isinstance(e[k], list_type):
-		    e[k] = [ b.data for b in e[k]]
-		else:
-		    e[k] = e[k].data
-	    elif isinstance(e[k], dict_type):
-		decapsulate_binaries(e[k], tags)
-	    elif isinstance(e[k], list_type):
-		for ee in e[k]:
-		    decapsulate_binaries(ee, tags)
-    # Other types end the recursion - they should be leaves
-    return e
-
+
+    map = [ (t, lambda x: x.data) for t in tags]
+    return apply_to_tags(e, map)
+#end of tag specializations
 
 def strip_unicode(obj):
@@ -318,5 +318,5 @@
     Create a new certificate and derive a fedid from it.
 
-    The fedid and the certificte are returned as a tuple.
+    The fedid and the certificate are returned as a tuple.
     """
 
@@ -340,5 +340,4 @@
 	    if trace: call_out = trace
 	    else: 
-		log.debug("set to dev/null")
 		call_out = open("/dev/null", "w")
 
@@ -382,5 +381,5 @@
 	req = ps.Parse(typecode)
 
-	msg = method(unpack_soap(req), fedid)
+	msg = method(fedids_to_obj(unpack_soap(req)), fid)
 
 	resp = constructor()
@@ -397,6 +396,5 @@
     return handler
 
-def make_xmlrpc_handler(method, body_name, input_binaries=('fedid',), 
-	output_binaries=('fedid',)):
+def make_xmlrpc_handler(method, body_name):
     """
     Generate the handler code to unpack and pack SOAP requests and responses
@@ -405,17 +403,20 @@
     The code to marshall and unmarshall XMLRPC parameters to and from a fedd
     service is largely the same.  This helper creates such a handler.  The
-    parameters are the method name, the name of the body struct that contains
-    the response asn the list of fields that are encoded as Binary objects in
-    the input and in the output.  A handler is created that takes the params
-    response from an xm,lrpclib.loads on the incoming rpc and a fedid and
-    responds with a hash representing the struct ro be returned to the other
-    side.  On error None is returned.
+    parameters are the method name, and the name of the body struct that
+    contains the response.  A handler is created that takes the params response
+    from an xmlrpclib.loads on the incoming rpc and a fedid and responds with
+    a hash representing the struct ro be returned to the other side.  On error
+    None is returned.  Fedid fields are decapsulated from binary and converted
+    to fedid objects on input and encapsulated as Binaries on output.
     """
     def handler(params, fid):
-	p = decapsulate_binaries(params[0], input_binaries)
-	msg = method(p, fedid)
+	decap_fedids = (('fedid', lambda x: fedid(bits=x.data)),)
+
+	#p = decapsulate_binaries(params[0], input_binaries)
+	p = apply_to_tags(params[0], decap_fedids)
+	msg = method(p, fid)
 
 	if msg != None:
-	    return encapsulate_binaries({ body_name: msg }, output_binaries)
+	    return encapsulate_binaries({ body_name: msg }, ('fedid',))
 	else:
 	    return None
