def _add_enum(vartree, member, props): """ Helper for :meth:`_populate_from_xml`. """ name = member.attrib['name'] typ = member.attrib['type'] cvt = {'double': float, 'long': int, 'string': str}[typ] args = {} if typ == 'string': args['default_value'] = member.text.decode('string_escape') else: args['default_value'] = cvt(member.text) desc = props.get('description') if desc: args['desc'] = desc.decode('string_escape') values = props.get('enumValues') if values: if typ == 'string': values = values.decode('string_escape') args['values'] = [cvt(val.strip(' "')) for val in values.split(',')] aliases = props.get('enumAliases') if aliases: aliases = aliases.decode('string_escape') args['aliases'] = [val.strip(' "') for val in aliases.split(',')] units = props.get('units') if units: args['units'] = get_translation(units) vartree.add(name, Enum(**args))
def __init__(self, iotype, client, rpath, typ): ProxyMixin.__init__(self, client, rpath) self._type = typ default = self._value = [typ(val.strip(' "')) for val in self._valstr.split(',')] desc = client.get(rpath+'.description') if typ == float: as_units = client.get(rpath+'.units') if as_units: om_units = get_translation(as_units) else: om_units = None if typ != str: if client.get(rpath+'.hasUpperBound') == 'true': high = typ(client.get(rpath+'.upperBound')) else: high = None if client.get(rpath+'.hasLowerBound') == 'true': low = typ(client.get(rpath+'.lowerBound')) else: low = None if typ == float: List.__init__(self, trait=Float, iotype=iotype, desc=desc, value=default, low=low, high=high, units=om_units) elif typ == int: List.__init__(self, trait=Int, iotype=iotype, desc=desc, value=default, low=low, high=high) else: List.__init__(self, trait=Str, iotype=iotype, desc=desc, value=default)
def __init__(self, iotype, client, rpath): ProxyMixin.__init__(self, client, rpath) default = float(self._valstr) desc = client.get(rpath + '.description') as_units = client.get(rpath + '.units') if as_units: om_units = get_translation(as_units) else: om_units = None if client.get(rpath + '.hasUpperBound') == 'true': high = float(client.get(rpath + '.upperBound')) else: high = None if client.get(rpath + '.hasLowerBound') == 'true': low = float(client.get(rpath + '.lowerBound')) else: low = None Float.__init__(self, default_value=default, iotype=iotype, desc=desc, low=low, high=high, units=om_units)
def _add_enum(vartree, member, props): """ Helper for :meth:`_populate_from_xml`. """ name = member.attrib['name'] typ = member.attrib['type'] cvt = {'double':float, 'long':int, 'string':str}[typ] args = {} if typ == 'string': args['default_value'] = member.text.decode('string_escape') else: args['default_value'] = cvt(member.text) desc = props.get('description') if desc: args['desc'] = desc.decode('string_escape') values = props.get('enumValues') if values: if typ == 'string': values = values.decode('string_escape') args['values'] = [cvt(val.strip(' "')) for val in values.split(',')] aliases = props.get('enumAliases') if aliases: aliases = aliases.decode('string_escape') args['aliases'] = [val.strip(' "') for val in aliases.split(',')] units = props.get('units') if units: args['units'] = get_translation(units) vartree.add(name, Enum(**args))
def _add_array(vartree, member, props): """ Helper for :meth:`_populate_from_xml`. """ name = member.attrib['name'] typ = member.attrib['type'] cvt = {'double[]': float, 'long[]': int, 'string[]': str}[typ] if props.get('lockResize') == 'false' and props.get( 'numDimensions') == '1': objtyp = 'List' else: objtyp = 'Array' text = member.text or '' args = {} if objtyp == 'Array': args['dtype'] = cvt if text.startswith('bounds['): dims, rbrack, rest = text[7:].partition(']') dims = [int(val.strip(' "')) for val in dims.split(',')] junk, lbrace, rest = rest.partition('{') data, rbrace, rest = rest.partition('}') value = numpy.array([ cvt(val.strip(' "')) for val in data.split(',') ]).reshape(dims) elif text: value = numpy.array( [cvt(val.strip(' "')) for val in text.split(',')]) else: value = numpy.array([]) args['default_value'] = value else: args['trait'] = { 'double[]': Float, 'long[]': Int, 'string[]': Str }[typ] if text: value = [cvt(val.strip(' "')) for val in text.split(',')] args['value'] = value desc = props.get('description') if desc: args['desc'] = desc.decode('string_escape') units = props.get('units') if units: args['units'] = get_translation(units) low = props.get('hasLowerBound') if low == 'true': args['low'] = cvt(props.get('lowerBound')) high = props.get('hasUpperBound') if high == 'true': args['high'] = cvt(props.get('upperBound')) if objtyp == 'Array': vartree.add(name, Array(**args)) else: vartree.add(name, List(**args))
def _add_array(vartree, member, props): """ Helper for :meth:`_populate_from_xml`. """ name = member.attrib['name'] typ = member.attrib['type'] cvt = {'double[]':float, 'long[]':int, 'string[]':str}[typ] if props.get('lockResize') == 'false' and props.get('numDimensions') == '1': objtyp = 'List' else: objtyp = 'Array' text = member.text or '' args = {} if objtyp == 'Array': args['dtype'] = cvt if text.startswith('bounds['): dims, rbrack, rest = text[7:].partition(']') dims = [int(val.strip(' "')) for val in dims.split(',')] junk, lbrace, rest = rest.partition('{') data, rbrace, rest = rest.partition('}') value = numpy.array([cvt(val.strip(' "')) for val in data.split(',')]).reshape(dims) elif text: value = numpy.array([cvt(val.strip(' "')) for val in text.split(',')]) else: value = numpy.array([]) args['default_value'] = value else: args['trait'] = {'double[]':Float, 'long[]':Int, 'string[]':Str}[typ] if text: value = [cvt(val.strip(' "')) for val in text.split(',')] args['value'] = value desc = props.get('description') if desc: args['desc'] = desc.decode('string_escape') units = props.get('units') if units: args['units'] = get_translation(units) low = props.get('hasLowerBound') if low == 'true': args['low'] = cvt(props.get('lowerBound')) high = props.get('hasUpperBound') if high == 'true': args['high'] = cvt(props.get('upperBound')) if objtyp == 'Array': vartree.add(name, Array(**args)) else: vartree.add(name, List(**args))
def __init__(self, iotype, client, rpath, typ): ProxyMixin.__init__(self, client, rpath) self._type = typ default = self._parse(self._valstr) desc = client.get(rpath + '.description') if typ == float: as_units = client.get(rpath + '.units') if as_units: om_units = get_translation(as_units) else: om_units = None if typ != str: if client.get(rpath + '.hasUpperBound') == 'true': high = typ(client.get(rpath + '.upperBound')) else: high = None if client.get(rpath + '.hasLowerBound') == 'true': low = typ(client.get(rpath + '.lowerBound')) else: low = None if typ == float: Array.__init__(self, dtype=typ, iotype=iotype, desc=desc, default_value=default, low=low, high=high, units=om_units) elif typ == int: Array.__init__(self, dtype=typ, iotype=iotype, desc=desc, default_value=default, low=low, high=high) else: # FIXME: This will pickle, but not unpickle. # Probabably don't want fixed max-length string storage anyway. Array.__init__(self, dtype=typ, iotype=iotype, desc=desc, default_value=default)
def _add_float(vartree, member, props): """ Helper for :meth:`_populate_from_xml`. """ name = member.attrib['name'] args = {} args['default_value'] = float(member.text) desc = props.get('description') if desc: args['desc'] = desc.decode('string_escape') units = props.get('units') if units: args['units'] = get_translation(units) low = props.get('hasLowerBound') if low == 'true': args['low'] = float(props.get('lowerBound')) high = props.get('hasUpperBound') if high == 'true': args['high'] = float(props.get('upperBound')) vartree.add(name, Float(**args))
def __init__(self, iotype, client, rpath, typ, valstrs): ProxyMixin.__init__(self, client, rpath) om_units = None if typ == 'PHXDouble': self._from_string = float self._to_string = _float2str as_units = client.get(rpath + '.units') if as_units: om_units = get_translation(as_units) elif typ == 'PHXLong': self._from_string = int self._to_string = str elif typ == 'PHXString': self._from_string = self._null self._to_string = self._null else: raise NotImplementedError('EnumProxy for %r' % typ) default = self._from_string(self._valstr) desc = client.get(rpath + '.description') enum_values = [] for valstr in valstrs.split(','): enum_values.append(self._from_string(valstr.strip(' "'))) enum_aliases = [] aliases = self._client.get(rpath + '.enumAliases') if aliases: for alias in aliases.split(','): enum_aliases.append(alias.strip(' "')) if enum_aliases: if len(enum_aliases) != len(enum_values): raise ValueError("Aliases %r don't match values %r" % (enum_aliases, enum_values)) Enum.__init__(self, default_value=default, iotype=iotype, desc=desc, values=enum_values, aliases=enum_aliases, units=om_units)
def __init__(self, iotype, client, rpath): ProxyMixin.__init__(self, client, rpath) default = self._value = float(self._valstr) desc = client.get(rpath+'.description') as_units = client.get(rpath+'.units') if as_units: om_units = get_translation(as_units) else: om_units = None if client.get(rpath+'.hasUpperBound') == 'true': high = float(client.get(rpath+'.upperBound')) else: high = None if client.get(rpath+'.hasLowerBound') == 'true': low = float(client.get(rpath+'.lowerBound')) else: low = None Float.__init__(self, default_value=default, iotype=iotype, desc=desc, low=low, high=high, units=om_units)
def __init__(self, iotype, client, rpath, typ, valstrs): ProxyMixin.__init__(self, client, rpath) om_units = None if typ == 'PHXDouble': self._from_string = float self._to_string = _float2str as_units = client.get(rpath+'.units') if as_units: om_units = get_translation(as_units) elif typ == 'PHXLong': self._from_string = int self._to_string = str elif typ == 'PHXString': self._from_string = self._null self._to_string = self._null else: raise NotImplementedError('EnumProxy for %r' % typ) default = self._value = self._from_string(self._valstr) desc = client.get(rpath+'.description') enum_values = [] for valstr in valstrs.split(','): enum_values.append(self._from_string(valstr.strip(' "'))) enum_aliases = [] aliases = self._client.get(rpath+'.enumAliases') if aliases: for alias in aliases.split(','): enum_aliases.append(alias.strip(' "')) if enum_aliases: if len(enum_aliases) != len(enum_values): raise ValueError("Aliases %r don't match values %r" % (enum_aliases, enum_values)) Enum.__init__(self, default_value=default, iotype=iotype, desc=desc, values=enum_values, aliases=enum_aliases, units=om_units)
def __init__(self, iotype, client, rpath, typ): ProxyMixin.__init__(self, client, rpath) self._type = typ default = self._value = self._parse(self._valstr) desc = client.get(rpath+'.description') if typ == float: as_units = client.get(rpath+'.units') if as_units: om_units = get_translation(as_units) else: om_units = None if typ != str: if client.get(rpath+'.hasUpperBound') == 'true': high = typ(client.get(rpath+'.upperBound')) else: high = None if client.get(rpath+'.hasLowerBound') == 'true': low = typ(client.get(rpath+'.lowerBound')) else: low = None if typ == float: Array.__init__(self, dtype=typ, iotype=iotype, desc=desc, default_value=default, low=low, high=high, units=om_units) elif typ == int: Array.__init__(self, dtype=typ, iotype=iotype, desc=desc, default_value=default, low=low, high=high) else: # FIXME: This will pickle, but not unpickle. # Probabably don't want fixed max-length string storage anyway. Array.__init__(self, dtype=typ, iotype=iotype, desc=desc, default_value=default)