示例#1
0
    def get_many(self, keys):
        keys = list(keys)
        if not len(keys):
            raise StopIteration

        for key, value in izip(keys, self.conn.mget(keys)):
            yield (key, Serializer.loads(self.format, value))
示例#2
0
    def load_plugin_config(self, cls):
        name = cls.__name__.lower()
        if name.endswith('plugin'):
            name = name[:-6]

        path = os.path.join(self.config.plugin_config_dir,
                            name) + '.' + self.config.plugin_config_format

        data = {}
        if self.config.shared_config:
            data.update(self.config.shared_config)

        if name in self.config.plugin_config:
            data.update(self.config.plugin_config[name])

        if os.path.exists(path):
            with open(path, 'r') as f:
                data.update(
                    Serializer.loads(self.config.plugin_config_format,
                                     f.read()))

        if hasattr(cls, 'config_cls'):
            inst = cls.config_cls()
            if data:
                inst.update(data)
            return inst

        return data
示例#3
0
文件: disk.py 项目: jhgg/disco
    def load(self):
        if not os.path.exists(self.path):
            return

        if self.config.get('autosave', True):
            self.autosave_task = gevent.spawn(
                self.autosave_loop, self.config.get('autosave_interval', 120))

        with open(self.path, 'r') as f:
            self.data = Serializer.loads(self.format, f.read())
示例#4
0
文件: storage.py 项目: Lymia/rowboat
    def __init__(self, ctx, config):
        self._ctx = ctx
        self._path = config.path
        self._serializer = config.serializer
        self._fsync = config.fsync
        self._data = {}

        if os.path.exists(self._path):
            with open(self._path, 'r') as f:
                self._data = Serializer.loads(self._serializer, f.read())
                if not self._data:
                    self._data = {}
示例#5
0
    def load_plugin_config(self, cls):
        name = cls.__name__.lower()
        if name.endswith('plugin'):
            name = name[:-6]

        path = os.path.join(self.config.plugin_config_dir,
                            name) + '.' + self.config.plugin_config_format

        if not os.path.exists(path):
            if hasattr(cls, 'config_cls'):
                return cls.config_cls()
            return

        with open(path, 'r') as f:
            data = Serializer.loads(self.config.plugin_config_format, f.read())

        if hasattr(cls, 'config_cls'):
            inst = cls.config_cls()
            inst.update(data)
            return inst

        return data
示例#6
0
 def set(self, key, value):
     self.db.put(self.k(key), Serializer.dumps(self.format, value))
示例#7
0
 def get(self, key):
     return Serializer.loads(self.format,
                             self.db.get(self.k(key)).decode('utf-8'))
示例#8
0
 def get_many(self, keys):
     for key, value in izip(keys, self.db.multi_get(list(map(self.k,
                                                             keys)))):
         yield (key, Serializer.loads(self.format, value.decode('utf-8')))
示例#9
0
 def set(self, key, value):
     self.conn.set(key, Serializer.dumps(self.format, value))
示例#10
0
 def get(self, key):
     return Serializer.loads(self.format, self.conn.get(key))
示例#11
0
文件: storage.py 项目: Lymia/rowboat
    def save(self):
        if not self._path:
            return

        with open(self._path, 'w') as f:
            f.write(Serializer.dumps(self._serializer, self._data))
示例#12
0
文件: redis.py 项目: sgtlaggy/disco
 def get_many(self, keys):
     for key, value in izip(keys, self.conn.mget(keys)):
         yield (key, Serializer.loads(self.format, value))
示例#13
0
文件: disk.py 项目: jhgg/disco
 def save(self):
     with open(self.path, 'w') as f:
         f.write(Serializer.dumps(self.format, self.data))