class ProtoObject(object): def __init__(self, name_or_dict, bases=None, dict=None): if bases is not None and dict is not None: if '__metaclass__' in dict: del dict['__metaclass__'] else: dict = name_or_dict self.__dict__['_dict'] = dict if 'parent' not in self._dict: self._dict['parent'] = default_parent def __getattr__(self, name): current = self while name not in current._dict: current = current._dict['parent'] if current is None: break else: val = current._dict[name] if hasattr(val, "__get__"): val = val.__get__(self) return val raise AttributeError, name def __setattr__(self, name, value): current = self while name not in current._dict: current = current._dict['parent'] if current is None: break else: current._dict[name] = value return self._dict[name] = value ProtoMeta = ProtoObject class default_parent: __metaclass__ = ProtoMeta parent = None def clone(self): return ProtoObject(self._dict.copy())