import CosPropertyService import types import ilu import pythonutils class UndefinedProperty: def __repr__(self): return "" ## the special 'undefined' object used to indicate the non-existance of a ## property. Undefined = UndefinedProperty() def PropList2Dict(proplist): dict = {} for prop in proplist: dict[prop.property_name] = InputAny(prop.property_value) return dict def Dict2PropList(dict): proplist = [] for (key, value) in dict.items(): proplist.append(CosPropertyService.Property(key, OutputAny(value))) return proplist def OutputAny(pAny): if pAny == Undefined: return [CosPropertyService.anyType.Any_undefined, 0] elif pAny == None: return [CosPropertyService.anyType.Any_void, 0] elif type(pAny) == types.IntType: return [CosPropertyService.anyType.Any_long, pAny] elif type(pAny) == types.LongType: return [CosPropertyService.anyType.Any_long, pAny] elif type(pAny) == types.FloatType: return [CosPropertyService.anyType.Any_float, pAny] elif type(pAny) == types.InstanceType: if pAny.__class__ == CosPropertyService.TMimeObject: pAny.aBody = OutputAny(pAny.aBody) return [CosPropertyService.anyType.Any_MimeObject, pAny] elif pAny.IluTypeName() == "CosPropertyService.PropertySet": return [CosPropertyService.anyType.Any_PropertySet, pAny] else: return [CosPropertyService.anyType.Any_Object, {"aSBH" : pAny.IluSBH(), "aType" : pAny.IluTypeName()}] elif type(pAny) == types.StringType: return [CosPropertyService.anyType.Any_string, pAny] elif type(pAny) == types.DictType: proplist = Dict2PropList(pAny) return [CosPropertyService.anyType.Any_Properties, proplist] elif type(pAny) == types.ListType: anylist = [] for i in pAny: anylist.append(OutputAny(i)) return [CosPropertyService.anyType.Any_sequenceAny, anylist] else: print "Unknown type: ", pAny raise TypeError def InputAny(pAny): arm = pAny[0] value = pAny[1] if arm == CosPropertyService.anyType.Any_undefined: return Undefined elif arm == CosPropertyService.anyType.Any_void: return None elif arm == CosPropertyService.anyType.Any_Object: sobjtype = value["aType"] parts = string.splitfields(sobjtype, ".") module = parts[0] klass = parts[1] objclass = pythonutils.find_class(module, klass) if type(objclass) == types.ClassType: inst = ilu.ObjectOfSBH(objclass, value["aSBH"]) ## print inst return inst raise ValueError, "not a class type:" + sobjtype elif arm == CosPropertyService.anyType.Any_PropertySet: return CosPropertySetClientImpl(value) elif arm == CosPropertyService.anyType.Any_Properties: dict = PropList2Dict(value) return dict elif arm == CosPropertyService.anyType.Any_sequenceAny: anylist = [] for i in value: anylist.append(InputAny(i)) return anylist elif arm == CosPropertyService.anyType.Any_MimeObject: return CosPropertyService.TMimeObject(value.aContent_Type, InputAny(value.aBody)) else: return value