- Timestamp:
- Jun 24, 2008 4:59:50 PM (16 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- d26d52e
- Parents:
- 8f91e66
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_util.py
r8f91e66 r3e293e4 155 155 self.digest_bits(str().join([chr(x) for x in b])) 156 156 157 def print_soap(soap, out=sys.stdout, level=0, show_all=False):158 """Recursively print a soap element to out.159 160 This is printed as pseudo XML with a <x></x> block around each element and161 the element printed indented. If show_all is true, even empty elements are162 displayed.163 """164 165 indent = level* "\t"166 167 methods = [ method for method in dir(soap) \168 if method.startswith("get_element") and \169 callable(getattr(soap, method))]170 if len(methods) != 0:171 for m in methods:172 element = getattr(soap, m)();173 if element != None or show_all:174 # Element may be a list of repetitions of the same element. If175 # so set elements to be that list, otherwise create a one entry176 # tuple. In either case we're going to iterate over elements.177 if getattr(element,"__iter__", None) == None:178 elements = (element,)179 else:180 elements = element181 for e in elements:182 # attrs are the element attributes for this element and183 # they're printed in the framing XML rather than by the184 # recursive call.185 attrs = [ attr for attr in dir(e)\186 if attr.startswith("get_attribute") and \187 callable(getattr(e,attr))]188 print >> out, "%s<%s" % (indent, m[len("get_element_"):]),189 for a in attrs:190 print >>out, ' %s="%s"' % \191 (a[len("get_attribute_"):], getattr(e,a)()),192 print >>out, ">"193 print_soap(e, out, level+1)194 print >>out, "%s</%s>" % (indent, m[len("get_element_"):])195 else:196 print >> out, "%s%s" % (indent, soap)197 198 157 def pack_id(id): 199 158 """ 200 Return a dictionary with the field name set by the id type 159 Return a dictionary with the field name set by the id type. Handy for 160 creating dictionaries to be converted to messages. 201 161 """ 202 162 if isinstance(id, type(fedid())): return { 'fedid': id } … … 205 165 206 166 def pack_soap(container, name, contents): 167 """ 168 Convert the dictionary in contents into a tree of ZSI classes. 169 170 The holder classes are constructed from factories in container and assigned 171 to either the element or attribute name. This is used to recursively 172 create the SOAP message. 173 """ 207 174 if getattr(contents, "__iter__", None) != None: 208 175 obj = getattr(container, "new_%s" % name, None)() … … 220 187 return obj 221 188 else: return contents 189 190 def unpack_soap(element): 191 """ 192 Convert a tree of ZSI SOAP classes intro a hash. The inverse of pack_soap 193 194 Elements or elements that are empty are ignored. 195 """ 196 methods = [ m for m in dir(element) \ 197 if m.startswith("get_element") or m.startswith("get_attribute")] 198 if len(methods) > 0: 199 rv = { } 200 for m in methods: 201 if m.startswith("get_element_"): n = m.replace("get_element_","",1) 202 else: n = m.replace("get_attribute_", "", 1) 203 sub = getattr(element, m)() 204 if sub != None: 205 rv[n] = unpack_soap(sub) 206 return rv 207 elif getattr(element, "__iter__", None) != None: 208 return [unpack_soap(e) for e in element] 209 else: 210 return element;
Note: See TracChangeset
for help on using the changeset viewer.