def __getattribute__(self, name): """ Return the requested attribute unless it is a non-read-only method. The purpose of this overwrite is to disable access to the following non-read-only dict methods: `clear`, `pop`, `popitem`, `setdefault`, and `update`. The first two methods are disabled otherwise. Parameters ---------- name : str The name of the requested attribute. Returns ------- attribute : None The requested attribute. Notes ----- `__getattribute__` is implicitly called, when the attribute of an object is accessed as `object.attribute`. """ if name in ('clear', 'pop', 'popitem', 'setdefault', 'update'): if self._disabled: value = _OrderedDict.__getattribute__(self, name) else: raise TypeError('{!r} objects are read-only.' .format(self.__class__)) else: value = _OrderedDict.__getattribute__(self, name) return value
def __getattribute__(self, name): if name not in OrderedDict.__getattribute__(self, '_overridden_names'): return OrderedDict.__getattribute__(self, name) def _missing(*args, **kwargs): if not self._unshielded: self._unshield() return OrderedDict.__getattribute__(self, name)() return _missing
def __getattr__(self, name): # print ("***", name) if name in ["_OrderedDict__root", "_OrderedDict__map"]: return OrderedDict.__getattribute__(self, name) if name in self: return self[name] else: raise KeyError("The state object does not have an entry for the key '%s'." % (name,))
def __getattr__(self, item): try: return OrderedDict.__getattribute__(self, item) except AttributeError: try: return self.__getitem__(item) except KeyError: try: return self.__getitem__(item.replace('-', '_')) except KeyError: raise AttributeError("'%s' object has no attribute '%s'", (self.__class__.__name__, item))
class AutoIncDict: def __init__(self): self.__d = OrderedDict() def __getitem__(self, key): if key not in self.__d: self.__d[key] = len(self.__d) return self.__d[key] def __getattr__(self, attr): try: return self.__d.__getattribute__(attr) except AttributeError: raise AttributeError("'AutoIncDict' object has no attribute '%s'" % attr)
def __getattr__(self, name): try: return self[name] except: pass return OrderedDict.__getattribute__(self, name)
def _missing(*args, **kwargs): if not self._unshielded: self._unshield() return OrderedDict.__getattribute__(self, name)()
def __getattribute__(self, name): """Allow direct access to elements in uppercase.""" if name.isupper(): return self[name] else: return OrderedDict.__getattribute__(self, name)
class Dictionary(): def __init__(self): self.__dictionary = OrderedDict() def clear(self): self.__dictionary.clear() def get_json(self): return json.dumps(self.__dictionary) def set_item(self, key, value): self.__dictionary.__setitem__(key, value) return self def values(self): return [value for value in self.__dictionary.values().__iter__()] def items(self): return self.__dictionary.items() def copy(self): self.__dictionary def constain(self, key): return key in self.get_list_of_key() def get(self, key): return self.__dictionary.get(key) def clear(self, key, default): self.__dictionary.pop(key, default) def format(self, *args, **kwargs): return self.__dictionary.__format__(*args, **kwargs) def ne(self, *args, **kwargs): return self.__dictionary.__ne__(*args, **kwargs) def repr(self, *args, **kwargs): return self.__dictionary.__repr__(*args, **kwargs) def ge(self, *args, **kwargs): return self.dictionary__ge__(*args, **kwargs) def __sizeof__(self): return self.__dictionary.__sizeof__() def setattr(self, *args, **kwargs): return self.__dictionary.__setattr__(*args, **kwargs) def dir(self): return self.__dictionary.__dir__() def le(self, *args, **kwargs): return self.__dictionary.__le__(*args, **kwargs) def delattr(self, *args, **kwargs): return self.__dictionary.__delattr__(*args, **kwargs) def hash(self, *args, **kwargs): return self.__dictionary.__hash__(*args, **kwargs) def gt(self, *args, **kwargs): return self.__dictionary.__gt__(*args, **kwargs) def eq(self, *args, **kwargs): return self.__dictionary.__eq__(*args, **kwargs) def getattribute(self, *args, **kwargs): return self.__dictionary.__getattribute__(*args, **kwargs) def str(self, *args, **kwargs): return self.__dictionary.__str__(*args, **kwargs) def reduce(self, *args, **kwargs): return self.__dictionary.__reduce__(*args, **kwargs) def reduce_ex(self, *args, **kwargs): return self.__dictionary.__reduce_ex__(*args, **kwargs) def lt(self, *args, **kwargs): return self.__dictionary.__lt__(*args, **kwargs) def keys(self): return self.get_list_of_key() def get_list_of_key(self): return [key for key in self.__dictionary.keys().__iter__()]
def __getattr__(self,key): if key.startswith('_'): return OrderedDict.__getattribute__(self,key) return self.__getitem__(key)