def _toAny(self, value): if value is None: return any.to_any(value) result = any.to_any(None) if self.type_ == "char": result = CORBA.Any(CORBA.TypeCode(CORBA.CharSeq), str(value)) elif self.type_ == "octet": result = CORBA.Any(CORBA.TypeCode(CORBA.OctetSeq), str(value)) else: expectedType = getTypeMap(self.type_) expectedTypeCode = tcInternal.createTypeCode((tcInternal.tv_sequence, expectedType._d, 0)) # Coerce the value into the correct simple type, may thrown a TypeError if the # type cannot be coerced...let this propagate up in the hopes that it will get # logged somewhere result = CORBA.Any(expectedTypeCode, [to_pyvalue(item, self.type_) for item in value]) return result
def getPropertySet(self, kinds=("configure","property",), \ modes=("readwrite", "writeonly", "readonly"), \ action="external", \ includeNil=True, commandline=False): """ A useful utility function that extracts specified property types from the PRF file and turns them into a CF.PropertySet """ propertySet = [] # Simples if self.prf != None: for prop in self.prf.get_simple(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_value() is not None: if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) value = stringToComplex(prop.get_value(), type) else: type = prop.get_type() value = prop.get_value() dt = properties.to_tc_value(value, type) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Simple Sequences for prop in self.prf.get_simplesequence(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_values() is not None: seq = [] if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) for v in prop.get_values().get_value(): seq.append(stringToComplex(v, type)) expectedType = properties.getTypeCode(type) expectedTypeCode = tcInternal.createTypeCode( (tcInternal.tv_sequence, expectedType._d, 0)) dt = CORBA.Any(expectedTypeCode, [ properties._convertComplexToCFComplex( item, type) for item in seq ]) else: type = prop.get_type() for v in prop.get_values().get_value(): value = v seq.append(properties.to_pyvalue(value, type)) dt = any.to_any(seq) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Structures for prop in self.prf.get_struct(): if self.isMatch(prop, modes, kinds, (action, )): if (prop.get_simple() is not None) or (prop.get_simplesequence() is not None): fields = [] hasValue = False if prop.get_simple() is not None: for p in prop.get_simple(): if p.get_value() is not None: hasValue = True dt = properties.to_tc_value( p.get_value(), p.get_type()) fields.append( CF.DataType(id=str(p.get_id()), value=dt)) if prop.get_simplesequence() is not None: for p in prop.get_simplesequence(): if p.get_values() is not None: hasValue = True dt = properties.to_tc_value( p.get_values(), p.get_type()) fields.append( CF.DataType(id=str(p.get_id()), value=dt)) if not hasValue and not includeNil: continue dt = any.to_any(fields) else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Struct Sequence for prop in self.prf.get_structsequence(): if self.isMatch(prop, modes, kinds, (action, )): baseProp = [] if prop.get_struct() != None: fields = [] for internal_prop in prop.get_struct().get_simple(): fields.append( CF.DataType(id=str(internal_prop.get_id()), value=any.to_any(None))) for internal_prop in prop.get_struct( ).get_simplesequence(): fields.append( CF.DataType(id=str(internal_prop.get_id()), value=any.to_any(None))) for val in prop.get_structvalue(): baseProp.append(copy.deepcopy(fields)) for entry in val.get_simpleref(): val_type = None for internal_prop in prop.get_struct().get_simple( ): if str(internal_prop.get_id()) == entry.refid: val_type = internal_prop.get_type() for subfield in baseProp[-1]: if subfield.id == entry.refid: subfield.value = properties.to_tc_value( entry.get_value(), val_type) for entry in val.get_simplesequenceref(): val_type = None for internal_prop in prop.get_struct( ).get_simplesequence(): if str(internal_prop.get_id()) == entry.refid: val_type = internal_prop.get_type() for subfield in baseProp[-1]: if subfield.id == entry.refid: subfield.value = properties.to_tc_value( entry.get_values(), val_type) anybp = [] for bp in baseProp: anybp.append(properties.props_to_any(bp)) p = CF.DataType(id=str(prop.get_id()), value=any.to_any(anybp)) propertySet.append(p) return propertySet
def getPropertySet(self, kinds=("configure",), \ modes=("readwrite", "writeonly", "readonly"), \ action="external", \ includeNil=True): """ A useful utility function that extracts specified property types from the PRF file and turns them into a CF.PropertySet """ propertySet = [] # Simples for prop in self.prf.get_simple(): if self.isMatch(prop, modes, kinds, (action,)): if prop.get_value() is not None: if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) value = stringToComplex(prop.get_value(), type) else: type = prop.get_type() value = prop.get_value() dt = properties.to_tc_value(value, type) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Simple Sequences for prop in self.prf.get_simplesequence(): if self.isMatch(prop, modes, kinds, (action,)): if prop.get_values() is not None: seq = [] if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) for v in prop.get_values().get_value(): seq.append(stringToComplex(v, type)) expectedType = properties.getTypeCode(type) expectedTypeCode = tcInternal.createTypeCode( (tcInternal.tv_sequence, expectedType._d, 0)) dt = CORBA.Any(expectedTypeCode, [properties._convertComplexToCFComplex(item, type) for item in seq]) else: type = prop.get_type() for v in prop.get_values().get_value(): value = v seq.append(properties.to_pyvalue(value, type)) dt = any.to_any(seq) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Structures for prop in self.prf.get_struct(): if self.isMatch(prop, modes, kinds, (action,)): if prop.get_simple() is not None: fields = [] hasValue = False for s in prop.get_simple(): if s.get_value() is not None: hasValue = True dt = properties.to_tc_value(s.get_value(), s.get_type()) fields.append(CF.DataType(id=str(s.get_id()), value=dt)) if not hasValue and not includeNil: continue dt = any.to_any(fields) else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Structures for prop in self.prf.get_structsequence(): if self.isMatch(prop, modes, kinds, (action,)): baseProp = [] if prop.get_struct() != None: fields = [] for internal_prop in prop.get_struct().get_simple(): fields.append(CF.DataType(id=str(internal_prop.get_id()), value=any.to_any(None))) for val in prop.get_structvalue(): baseProp.append(copy.deepcopy(fields)) for entry in val.get_simpleref(): val_type = None for internal_prop in prop.get_struct().get_simple(): if str(internal_prop.get_id()) == entry.refid: val_type = internal_prop.get_type() for subfield in baseProp[-1]: if subfield.id == entry.refid: subfield.value = properties.to_tc_value(entry.get_value(), val_type) anybp = [] for bp in baseProp: anybp.append(properties.props_to_any(bp)) p = CF.DataType(id=str(prop.get_id()), value=any.to_any(anybp)) propertySet.append(p) # Struct Sequence return propertySet