Example #1
0
File: ar.py Project: oldchuo1/pysar
 def get_container_value(self, attr):
     feature = MMHelper.WRAP_SUB_CONTAINERS
     if is_type(self, 'MODULE_CONFIGURATION'):
         feature = MMHelper.WRAP_CONTAINERS
     if self.children.has_key(feature):
         cont_vals = self.children[feature]
         vals = filter(lambda e: MMHelper.has_definition(e, attr),
                       cont_vals)
         if [] == vals:
             return None
         val = vals[0]
         def_uri = MMHelper.get_definition_uri(val)
         definition = self.get_identifiable(def_uri)
         wrap_upper_multi_inf = MMHelper.WRAP_UPPER_MULTIPLICITY_INFINITE
         if hasattr(definition, wrap_upper_multi_inf):
             if getattr(definition, wrap_upper_multi_inf):
                 return vals
         wrap_upper_multi = MMHelper.WRAP_UPPER_MULTIPLICITY
         if 1 == getattr(definition, wrap_upper_multi):
             if len(vals) > 1:
                 raise AttributeError(
                     self.msg.format('container', def_uri, self))
             else:
                 return val
         else:
             return vals
Example #2
0
File: ar.py Project: oldchuo1/pysar
 def find_aux(obj, ar_type, result):
     if isinstance(obj, AR):
         for child in obj.all_children():
             if isinstance(child, AR) and is_type(child, ar_type):
                 if MMHelper.attrib_match(child, kwargs):
                     result.append(child)
             find_aux(child, ar_type, result)
     return result
Example #3
0
File: ar.py Project: oldchuo1/pysar
 def wrap_self(self, parent=None):
     for feature in self.obj.getchildren():
         grand_children = feature.getchildren()
         attr = feature.tag[AR_NS_LEN:]
         lower_attr = MMHelper.wrap_name(attr)
         if grand_children:
             filtered = filter(lambda e: e.tag != 'comment', grand_children)
             grand_children_wrappers = [
                 AR(grand_child, self) for grand_child in filtered
             ]
             self.children[lower_attr] = grand_children_wrappers
         else:
             if lower_attr == MMHelper.WRAP_DEFINITION_REF:
                 self.children[MMHelper.wrap_name(
                     'DEFINITION')] = types.MethodType(
                         MMHelper.get_definition(), self, type(self))
             self.children[lower_attr] = types.MethodType(
                 MMHelper.single_attr(attr), self, type(self))
Example #4
0
File: ar.py Project: oldchuo1/pysar
 def get_parameter_value(self, attr):
     wrap_parameter_values = MMHelper.WRAP_PARAMETER_VALUES
     if self.children.has_key(wrap_parameter_values):
         par_vals = self.children[wrap_parameter_values]
         vals = filter(lambda e: MMHelper.has_definition(e, attr), par_vals)
         if [] == vals:
             return None
         val = vals[0]
         def_uri = MMHelper.get_definition_uri(val)
         definition = self.get_identifiable(def_uri)
         wrap_upper_multi_inf = MMHelper.WRAP_UPPER_MULTIPLICITY_INFINITE
         if hasattr(definition, wrap_upper_multi_inf):
             if getattr(definition, wrap_upper_multi_inf):
                 return vals
         wrap_upper_multi = MMHelper.WRAP_UPPER_MULTIPLICITY
         wrap_value = MMHelper.WRAP_VALUE
         if 1 == getattr(definition, wrap_upper_multi):
             if len(vals) > 1:
                 raise AttributeError(
                     self.msg.format('parameter', def_uri, self))
             else:
                 return getattr(val, wrap_value)
         else:
             return [getattr(v, wrap_value) for v in vals]
Example #5
0
File: ar.py Project: oldchuo1/pysar
 def __getattr__(self, attr):
     attr = MMHelper.maps(attr)
     if self.children.has_key(attr):
         child = self.children[attr]
         if isinstance(child, list):
             return child
         else:
             result = child()
             if isinstance(result, objectify.StringElement):
                 return str(result)
             return result
     if self.ar_type.startswith('MACC_'):
         g = self.get_parameter_value(attr)
         if g is not None:
             return g
         g = self.get_container_value(attr)
         if g is not None:
             return g
     raise AttributeError(attr)
Example #6
0
File: ar.py Project: oldchuo1/pysar
def is_type(ar_obj, ar_type):
    ar_type = MMHelper.maps(ar_type)
    return ar_obj.obj.tag == AR_NAMESPACE + ar_type