Пример #1
0
 def __get__(self, instance, owner=None):
     if instance is None:
         return self
     else:
         try:
             exp = self._instance_expressions[id(instance)]
         except KeyError:
             exp = coerce(self._factory(instance), size=self._size)
         return _PropertyValue(self, instance, exp)
Пример #2
0
    def __init__(self, size=1, make_default=None, *, name=None, doc=None):
        self._instance_expressions = {}
        if make_default:
            self._size = size
            self._factory = make_default
        else:
            self._size = size
            default = coerce(0, size=size)
            self._factory = lambda instance: default

        self.name, component_names = _get_names(name, size)

        self._component_names = {(i, i + 1): n
                                 for i, n in enumerate(component_names)}
        self.__doc__ = doc
Пример #3
0
 def __set__(self, instance, value):
     exp = self._vector_property.__get__(instance)
     new = exp.replace(slice(self._start, self._end),
                       coerce(value, size=len(self)))
     self._vector_property.__set__(instance, new)
Пример #4
0
 def __set__(self, instance, value):
     exp = coerce(value, size=self._size)
     if id(instance) not in self._instance_expressions:
         finalize(instance, self._instance_expressions.pop,
                  id(instance), None)
     self._instance_expressions[id(instance)] = simplify(exp)