• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/opal/ZSI/ZSI/TCapache.py

00001 #! /usr/bin/env python
00002 # $Header$
00003 '''Apache typecodes.
00004 '''
00005 
00006 from ZSI import _copyright, _child_elements, _get_idstr
00007 from ZSI.TC import TypeCode, Struct as _Struct, Any as _Any
00008 
00009 class Apache:
00010     NS = "http://xml.apache.org/xml-soap"
00011 
00012 class _Map(TypeCode):
00013     '''Apache's "Map" type.
00014     '''
00015     parselist = [ (Apache.NS, 'Map') ]
00016 
00017     def __init__(self, pname=None, aslist=0, **kw):
00018         TypeCode.__init__(self, pname, **kw)
00019         self.aslist = aslist
00020         self.tc = _Struct(None, [ _Any('key'), _Any('value') ], inline=1)
00021 
00022     def parse(self, elt, ps):
00023         self.checkname(elt, ps)
00024         if self.nilled(elt, ps): return None
00025         p = self.tc.parse
00026         if self.aslist:
00027             v = []
00028             for c in _child_elements(elt):
00029                 d = p(c, ps)
00030                 v.append((d['key'], d['value']))
00031         else:
00032             v = {}
00033             for c in _child_elements(elt):
00034                 d = p(c, ps)
00035                 v[d['key']] = d['value']
00036         return v
00037 
00038     def serialize(self, elt, sw, pyobj, name=None, **kw):
00039         objid = _get_idstr(pyobj)
00040         n = name or self.pname or ('E' + objid)
00041 
00042         # nillable
00043         el = elt.createAppendElement(self.nspname, n)
00044         if self.nillable is True and pyobj is None:
00045             self.serialize_as_nil(el)
00046             return None
00047 
00048         # other attributes
00049         self.set_attributes(el, pyobj)
00050 
00051         # soap href attribute
00052         unique = self.unique or kw.get('unique', False)
00053         if unique is False and sw.Known(orig or pyobj):
00054             self.set_attribute_href(el, objid)
00055             return None
00056 
00057         # xsi:type attribute 
00058         if kw.get('typed', self.typed) is True:
00059             self.set_attribute_xsi_type(el, **kw)
00060 
00061         # soap id attribute
00062         if self.unique is False:
00063             self.set_attribute_id(el, objid)
00064 
00065         if self.aslist:
00066             for k,v in pyobj:
00067                 self.tc.serialize(el, sw, {'key': k, 'value': v}, name='item')
00068         else:
00069             for k,v in pyobj.items():
00070                 self.tc.serialize(el, sw, {'key': k, 'value': v}, name='item')
00071 
00072 
00073 Apache.Map = _Map
00074 
00075 if __name__ == '__main__': print _copyright

Generated on Wed Oct 20 2010 11:12:16 for APBS by  doxygen 1.7.2