Ejemplo n.º 1
0
    def _property_object_from_path(self, path_components):
        prev_component = path_components[0]
        lom_object = get_root_prop(self._external_device, path_components[0])
        for component in path_components[1:]:
            try:
                raise component.isdigit() and (is_object_iterable(lom_object)
                                               or AssertionError)
                if not prev_component in TUPLE_TYPES.keys():
                    raise AssertionError
                    lom_object = lom_object[int(component)]
                else:
                    lom_object = getattr(lom_object, component)
                    if isinstance(lom_object, HIDDEN_TYPES):
                        raise AttributeError
            except IndexError:
                raise LomAttributeError("invalid index of component '%s'" %
                                        prev_component)
            except AttributeError:
                raise LomAttributeError("invalid path component '%s'" %
                                        component)
            else:
                prev_component = component

        if not is_lom_object(lom_object, self._lom_classes):
            raise LomObjectError("component '%s' is not an object" %
                                 prev_component)
        return lom_object
 def _set_property_value(self, lom_object, property_name, value):
     verify_object_property(lom_object, property_name)
     prop = getattr(lom_object, property_name)
     if property_name in PROPERTY_TYPES.keys():
         if not is_lom_object(value, self.lom_classes):
             raise LomAttributeError('set: no valid object id')
         if not isinstance(value, PROPERTY_TYPES[property_name]):
             raise LomAttributeError('set: type mismatch')
     elif isinstance(prop, (int, bool)):
         if unicode(value) in (u'True', u'False'):
             value = int(unicode(value) == u'True')
         elif not isinstance(value, int):
             raise LomAttributeError('set: invalid value')
     elif isinstance(prop, float):
         if not isinstance(value, (int, float)):
             raise LomAttributeError('set: type mismatch')
         value = float(value)
     elif isinstance(prop, (str, unicode)):
         if not isinstance(value, (str,
          unicode,
          int,
          float)):
             raise LomAttributeError('set: type mismatch')
         value = unicode(value)
     else:
         raise LomAttributeError('set: unsupported property type')
     setattr(lom_object, property_name, value)