瀏覽代碼

Be slightly less stupid about ConfigNodes

tags/v0.1^2
Ben Kurtovic 12 年之前
父節點
當前提交
3cb89711f8
共有 1 個檔案被更改,包括 24 行新增12 行删除
  1. +24
    -12
      earwigbot/config/node.py

+ 24
- 12
earwigbot/config/node.py 查看文件

@@ -23,25 +23,37 @@
__all__ = ["ConfigNode"]

class ConfigNode(object):
def __init__(self):
self._data = {}

def __iter__(self):
for key in self.__dict__:
for key in self._data:
yield key

def __getitem__(self, item):
return self.__dict__.__getitem__(item)
def __getitem__(self, key):
return self._data[key]

def __setitem__(self, key, item):
self._data[key] = item

def __getattr__(self, key):
return self._data[key]

def __setattr__(self, key, item):
self._data[key] = item

def _dump(self):
data = self.__dict__.copy()
data = self._data.copy()
for key, val in data.iteritems():
if isinstance(val, ConfigNode):
data[key] = val._dump()
return data

def _load(self, data):
self.__dict__ = data.copy()
self._data = data.copy()

def _decrypt(self, cipher, intermediates, item):
base = self.__dict__
base = self._data
for inter in intermediates:
try:
base = base[inter]
@@ -52,22 +64,22 @@ class ConfigNode(object):
base[item] = cipher.decrypt(ciphertext).rstrip("\x00")

def get(self, *args, **kwargs):
return self.__dict__.get(*args, **kwargs)
return self._data.get(*args, **kwargs)

def keys(self):
return self.__dict__.keys()
return self._data.keys()

def values(self):
return self.__dict__.values()
return self._data.values()

def items(self):
return self.__dict__.items()
return self._data.items()

def iterkeys(self):
return self.__dict__.iterkeys()
return self._data.iterkeys()

def itervalues(self):
return self.__dict__.itervalues()
return self._data.itervalues()

def iteritems(self):
return self.__dict__.iteritems()

Loading…
取消
儲存