Example #1
0
    def set_property(self, name, value, context=None):
        start_type, derived = self.__type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        declared_properties = start_type.find_property(name)
        if context is None:
            context = self.object_store.executor.create_object_context(self)
        if len(declared_properties) > 0:
            declared_properties = self.type.find_property(name)
            values_to_assign = []
            for mc in declared_properties:
                spec = mc.get_property(name)
                if (caller_class is not None and
                        not helpers.are_property_modifications_allowed(context)
                        and (spec.usage not in typespec.PropertyUsages.Writable
                             or not derived)):
                    raise exceptions.NoWriteAccessError(name)

                default = self.__config.get(name, spec.default)
                default = self.__defaults.get(name, default)
                default = helpers.evaluate(default, context)

                obj = self.cast(mc)
                values_to_assign.append((obj, spec.validate(
                    value, self.real_this,
                    self.real_this, default=default)))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
    def set_property(self, name, value, context=None, dry_run=False):
        start_type, derived = self.real_this.type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        if context is None:
            context = self.executor.create_object_context(self)
        declared_properties = start_type.find_properties(
            lambda p: p.name == name)
        if len(declared_properties) > 0:
            ultimate_spec = self.real_this.type.find_single_property(name)
            property_list = list(self._list_properties(name))
            for spec in property_list:
                if (caller_class is not None and
                        not helpers.are_property_modifications_allowed(context)
                        and
                    (spec.usage not in dsl_types.PropertyUsages.Writable
                     or not derived)):
                    raise exceptions.NoWriteAccessError(name)

                if spec.usage == dsl_types.PropertyUsages.Static:
                    default = None
                else:
                    default = self._config.get(name, spec.default)

                if spec is ultimate_spec:
                    value = spec.transform(value,
                                           self.real_this,
                                           self.real_this,
                                           context,
                                           default=default,
                                           finalize=len(property_list) == 1)
                else:
                    spec.validate(value, self.real_this, context, default)
            if len(property_list) > 1:
                value = ultimate_spec.finalize(value, self.real_this, context)
            if ultimate_spec.usage == dsl_types.PropertyUsages.Static:
                self.executor.set_static_property(ultimate_spec.declaring_type,
                                                  name,
                                                  value,
                                                  context,
                                                  dry_run=dry_run)
            elif not dry_run:
                self.real_this._properties[name] = value
        elif derived:
            if not dry_run:
                obj = self.cast(caller_class)
                obj._properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
Example #3
0
    def set_property(self, name, value, context=None):
        if self is not self.real_this:
            return self.real_this.set_property(name, value, context)
        start_type, derived = self.__type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        declared_properties = start_type.find_properties(
            lambda p: p.name == name)
        if context is None:
            context = helpers.get_executor().create_object_context(self)
        if len(declared_properties) > 0:
            values_to_assign = []
            classes_for_static_properties = []
            first = True
            for spec in self._list_properties(name):
                if (caller_class is not None and
                        not helpers.are_property_modifications_allowed(context)
                        and
                    (spec.usage not in dsl_types.PropertyUsages.Writable
                     or not derived)):
                    raise exceptions.NoWriteAccessError(name)

                if spec.usage == dsl_types.PropertyUsages.Static:
                    classes_for_static_properties.append(spec.declaring_type)
                else:
                    default = self.__config.get(name, spec.default)

                    obj = self.cast(spec.declaring_type)
                    res = spec.transform(value,
                                         self.real_this,
                                         self.real_this,
                                         context,
                                         default=default)
                    if first:
                        value = res
                        first = False
                    values_to_assign.append((obj, res))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
            for cls in classes_for_static_properties:
                cls.set_property(name, value, context)
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
Example #4
0
    def set_property(self, name, value, context=None):
        start_type, derived = self.__type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        declared_properties = start_type.find_properties(
            lambda p: p.name == name)
        if context is None:
            context = self.executor.create_object_context(self)
        if len(declared_properties) > 0:
            declared_properties = self.type.find_properties(
                lambda p: p.name == name)
            values_to_assign = []
            classes_for_static_properties = []
            for spec in declared_properties:
                if (caller_class is not None and not
                        helpers.are_property_modifications_allowed(context) and
                        (spec.usage not in dsl_types.PropertyUsages.Writable or
                            not derived)):
                    raise exceptions.NoWriteAccessError(name)

                if spec.usage == dsl_types.PropertyUsages.Static:
                    classes_for_static_properties.append(spec.declaring_type)
                else:
                    default = self.__config.get(name, spec.default)
                    # default = helpers.evaluate(default, context)

                    obj = self.cast(spec.declaring_type)
                    values_to_assign.append((obj, spec.transform(
                        value, self.real_this,
                        self.real_this, context, default=default)))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
            for cls in classes_for_static_properties:
                cls.set_property(name, value, context)
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)
Example #5
0
    def set_property(self, name, value, context=None):
        start_type, derived = self.__type, False
        caller_class = None if not context else helpers.get_type(context)
        if caller_class is not None and caller_class.is_compatible(self):
            start_type, derived = caller_class, True
        declared_properties = start_type.find_property(name)
        if context is None:
            context = self.object_store.executor.create_object_context(self)
        if len(declared_properties) > 0:
            declared_properties = self.type.find_property(name)
            values_to_assign = []
            for mc in declared_properties:
                spec = mc.get_property(name)
                if (caller_class is not None and
                        not helpers.are_property_modifications_allowed(context)
                        and (spec.usage not in typespec.PropertyUsages.Writable
                             or not derived)):
                    raise exceptions.NoWriteAccessError(name)

                default = self.__config.get(name, spec.default)
                default = self.__defaults.get(name, default)
                default = helpers.evaluate(default, context)

                obj = self.cast(mc)
                values_to_assign.append((obj,
                                         spec.validate(value,
                                                       self.real_this,
                                                       self.real_this,
                                                       default=default)))
            for obj, value in values_to_assign:
                obj.__properties[name] = value
        elif derived:
            obj = self.cast(caller_class)
            obj.__properties[name] = value
        else:
            raise exceptions.PropertyWriteError(name, start_type)