def __getitem__(self, item): if item in self._extra: return self._extra[item] if item in self._header.dtype.names: return self._header[item] elif hasattr(self, item): attr = getattr(self, item) if isinstance(attr, basestring): return self._header[attr] elif isinstance(attr, tuple) or isinstance(attr, list): dtype, get, set = attr return virtarray(None, dtype, MethodType(get, self, None), MethodType(set, self, None)) else: return attr
def __setitem__(self, item, value): if item is Ellipsis: assert isinstance(value, ConstBase) self._header[...] = value._header self._extra = value._extra.copy() elif item in self._header.dtype.names: self._header[item] = value elif hasattr(self, item): attr = getattr(self, item) if isinstance(attr, basestring): self._header[attr] = value elif isinstance(attr, tuple) or isinstance(attr, list): dtype, get, set = attr virtarray(None, dtype, MethodType(get, self, None), MethodType(set, self, None))[...] = value else: raise IndexError("can't set %s" % item) else: self._extra[item] = value