当前位置: 首页>>代码示例>>Python>>正文


Python leveldb.WriteBatch方法代码示例

本文整理汇总了Python中leveldb.WriteBatch方法的典型用法代码示例。如果您正苦于以下问题:Python leveldb.WriteBatch方法的具体用法?Python leveldb.WriteBatch怎么用?Python leveldb.WriteBatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在leveldb的用法示例。


在下文中一共展示了leveldb.WriteBatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_prefix

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def test_prefix(self):
        """
        Test iterator prefixes
        """
        batch = leveldb.WriteBatch()
        batch.put('a', 'b')
        batch.put('b', 'b')
        batch.put('cd', 'a')
        batch.put('ce', 'a')
        batch.put('c', 'a')
        batch.put('f', 'b')
        db = self.db_class(self.db_path, create_if_missing=True)
        db.write(batch)
        iterator = db.iterator(prefix="c")
        iterator.seekFirst()
        self.assertEqual(iterator.next(), ('', 'a'))
        self.assertEqual(iterator.next(), ('d', 'a'))
        self.assertEqual(iterator.next(), ('e', 'a'))
        self.assertRaises(StopIteration, iterator.next)
        db.close() 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:22,代码来源:test_leveldb.py

示例2: testApproximateSizes

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def testApproximateSizes(self):
        db = self.db_class(self.db_path, create_if_missing=True)
        self.assertEqual([0, 0, 0],
            db.approximateDiskSizes(("a", "z"), ("0", "9"), ("A", "Z")))
        batch = leveldb.WriteBatch()
        for i in xrange(100):
            batch.put("c%d" % i, os.urandom(4096))
        db.write(batch, sync=True)
        db.close()
        db = self.db_class(self.db_path)
        sizes = db.approximateDiskSizes(("0", "9"), ("A", "Z"), ("a", "z"))
        self.assertEqual(sizes[0], 0)
        self.assertEqual(sizes[1], 0)
        self.assertTrue(sizes[2] >= 4096 * 100)
        for i in xrange(10):
            db.put("3%d" % i, os.urandom(10))
        db.close()
        db = self.db_class(self.db_path)
        sizes = db.approximateDiskSizes(("A", "Z"), ("a", "z"), ("0", "9"))
        self.assertEqual(sizes[0], 0)
        self.assertTrue(sizes[1] >= 4096 * 100)
        self.assertTrue(sizes[2] < 4096 * 100)
        self.assertTrue(sizes[2] >= 10 * 10)
        db.close() 
开发者ID:jtolio,项目名称:leveldb-py,代码行数:26,代码来源:test_leveldb.py

示例3: testApproximateSizes

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def testApproximateSizes(self):
        db = self.db_class(self.db_path, create_if_missing=True)
        self.assertEqual([0, 0, 0],
                         db.approximateDiskSizes(("a", "z"), ("0", "9"), ("A", "Z")))
        batch = leveldb.WriteBatch()
        for i in xrange(100):
            batch.put("c%d" % i, os.urandom(4096))
        db.write(batch, sync=True)
        db.close()
        db = self.db_class(self.db_path)
        sizes = db.approximateDiskSizes(("0", "9"), ("A", "Z"), ("a", "z"))
        self.assertEqual(sizes[0], 0)
        self.assertEqual(sizes[1], 0)
        self.assertTrue(sizes[2] >= 4096 * 100)
        for i in xrange(10):
            db.put("3%d" % i, os.urandom(10))
        db.close()
        db = self.db_class(self.db_path)
        sizes = db.approximateDiskSizes(("A", "Z"), ("a", "z"), ("0", "9"))
        self.assertEqual(sizes[0], 0)
        self.assertTrue(sizes[1] >= 4096 * 100)
        self.assertTrue(sizes[2] < 4096 * 100)
        self.assertTrue(sizes[2] >= 10 * 10)
        db.close() 
开发者ID:mcgreentn,项目名称:GDMC,代码行数:26,代码来源:test_leveldb.py

示例4: _saveChunk_pre1_0

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def _saveChunk_pre1_0(self, chunk, batch=None, writeOptions=None):
        """
        :param chunk: PocketLeveldbChunk
        :param batch: WriteBatch
        :param writeOptions: WriteOptions
        :return: None
        """
        cx, cz = chunk.chunkPosition
        data = chunk.savedData()
        key = struct.pack('<i', cx) + struct.pack('<i', cz)+dimension

        if batch is None:
            with self.world_db() as db:
                wop = self.writeOptions if writeOptions is None else writeOptions
                db.Put(wop, key + "0", data[0])
                if data[1] is not None:
                    db.Put(wop, key + "1", data[1])
                if data[2] is not None:
                    db.Put(wop, key + "2", data[2])
        else:
            batch.Put(key + "0", data[0])
            if data[1] is not None:
                batch.Put(key + "1", data[1])
            if data[2] is not None:
                batch.Put(key + "2", data[2]) 
开发者ID:Podshot,项目名称:MCEdit-Unified,代码行数:27,代码来源:leveldbpocket.py

示例5: saveChunk

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def saveChunk(self, chunk, batch=None, writeOptions=None):
        """
        Wrapper for the methods corresponding to the world version.
        :param chunk: PocketLeveldbChunk
        :param batch: WriteBatch
        :param writeOptions: WriteOptions
        :return: None
        """
        # Check the chunk version, since PE 1.0+ can contain pre 1.0+ chunks
        ver = chunk.chunk_version
        if ver == "\x02":
            self._saveChunk_pre1_0(chunk, batch, writeOptions)
        elif ord(ver) >= 3:
            self._saveChunk_1plus(chunk, batch, writeOptions)
        else:
            raise AttributeError("Unknown version %s for chunk %s"%(ver, chunk.chunkPosition())) 
开发者ID:Podshot,项目名称:MCEdit-Unified,代码行数:18,代码来源:leveldbpocket.py

示例6: deleteChunk

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def deleteChunk(self, cx, cz, batch=None):
        """
        Deletes a chunk at given cx, cz. Deletes using the batch if batch is given, uses world_db() otherwise.
        :param cx, cz Coordinates of the chunk
        :param batch WriteBatch
        :return: None
        """
        self.worldFile.deleteChunk(cx, cz, batch=batch)
        try:
            del self._loadedChunks[(cx, cz)]
        except:
            pass
        try:
            self.allChunks.remove((cx, cz))
        except:
            pass 
开发者ID:Podshot,项目名称:MCEdit-Unified,代码行数:18,代码来源:leveldbpocket.py

示例7: test_prefix

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def test_prefix(self):
        """
        Test iterator prefixes
        """
        batch = leveldb.WriteBatch()
        batch.Put('a', 'b')
        batch.Put('b', 'b')
        batch.Put('cd', 'a')
        batch.Put('ce', 'a')
        batch.Put('c', 'a')
        batch.Put('f', 'b')
        db = self.db_class(leveldb.Options(), self.db_path, create_if_missing=True)
        db.write(leveldb.WriteOptions(), batch)
        iterator = db.NewIterator(prefix="c")
        iterator.SeekToFirst()
        self.assertEqual(iterator.next(), ('', 'a'))
        self.assertEqual(iterator.next(), ('d', 'a'))
        self.assertEqual(iterator.next(), ('e', 'a'))
        self.assertRaises(StopIteration, iterator.next)
        db.close() 
开发者ID:Podshot,项目名称:MCEdit-Unified,代码行数:22,代码来源:test_leveldb.py

示例8: testApproximateSizes

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def testApproximateSizes(self):
        db = self.db_class(leveldb.Options(), self.db_path, create_if_missing=True)
        self.assertEqual([0, 0, 0],
                         db.approximateDiskSizes(("a", "z"), ("0", "9"), ("A", "Z")))
        batch = leveldb.WriteBatch()
        for i in xrange(100):
            batch.Put("c%d" % i, os.urandom(4096))
        db.write(leveldb.WriteOptions(), batch, sync=True)
        db.close()
        db = self.db_class(leveldb.Options(), self.db_path)
        sizes = db.approximateDiskSizes(("0", "9"), ("A", "Z"), ("a", "z"))
        self.assertEqual(sizes[0], 0)
        self.assertEqual(sizes[1], 0)
        self.assertTrue(sizes[2] >= 4096 * 100)
        for i in xrange(10):
            db.Put(leveldb.WriteOptions(), "3%d" % i, os.urandom(10))
        db.close()
        db = self.db_class(leveldb.Options(), self.db_path)
        sizes = db.approximateDiskSizes(("A", "Z"), ("a", "z"), ("0", "9"))
        self.assertEqual(sizes[0], 0)
        self.assertTrue(sizes[1] >= 4096 * 100)
        self.assertTrue(sizes[2] < 4096 * 100)
        self.assertTrue(sizes[2] >= 10 * 10)
        db.close() 
开发者ID:Podshot,项目名称:MCEdit-Unified,代码行数:26,代码来源:test_leveldb.py

示例9: setBatch

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def setBatch(self, batch: Iterable[Tuple]):
        b = leveldb.WriteBatch()
        for key, value in batch:
            key = self.to_byte_repr(key)
            value = self.to_byte_repr(value)
            b.Put(key, value)
        self._db.Write(b, sync=False) 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:9,代码来源:kv_store_leveldb.py

示例10: do_ops_in_batch

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def do_ops_in_batch(self, batch: Iterable[Tuple]):
        b = leveldb.WriteBatch()
        for op, key, value in batch:
            key = self.to_byte_repr(key)
            value = self.to_byte_repr(value)
            if op == self.WRITE_OP:
                b.Put(key, value)
            elif op == self.REMOVE_OP:
                b.Delete(key)
            else:
                raise ValueError('Unknown operation')
        self._db.Write(b, sync=False) 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:14,代码来源:kv_store_leveldb.py

示例11: commit

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def commit(self):
        log.debug('committing', db=self)
        batch = leveldb.WriteBatch()
        for k, v in self.uncommitted.items():
            if v is None:
                batch.Delete(k)
            else:
                batch.Put(k, compress(v))
        self.db.Write(batch, sync=False)
        self.uncommitted.clear() 
开发者ID:heikoheiko,项目名称:pyethapp,代码行数:12,代码来源:leveldb_service.py

示例12: _new_batch

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def _new_batch(self):
        return leveldb.WriteBatch() 
开发者ID:icon-project,项目名称:loopchain,代码行数:4,代码来源:key_value_store_leveldb.py

示例13: WriteBatch

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def WriteBatch(self, sync=False) -> KeyValueStoreWriteBatch:
        return _KeyValueStoreWriteBatchLevelDb(self._db, sync) 
开发者ID:icon-project,项目名称:loopchain,代码行数:4,代码来源:key_value_store_leveldb.py

示例14: __init__

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def __init__(self, path):
        self._path = path
        self._db = leveldb.LevelDB(path)
        self._batch = leveldb.WriteBatch()
        self._init_db()
        self.x = 0
        self.lflush = clock() 
开发者ID:InMobi,项目名称:level-tsd,代码行数:9,代码来源:base.py

示例15: flush

# 需要导入模块: import leveldb [as 别名]
# 或者: from leveldb import WriteBatch [as 别名]
def flush(self, sync_mode=False):
        self._db.Write(self._batch, sync=sync_mode)
        self.x = 0
        self._batch = leveldb.WriteBatch()
        self.lflush = clock() 
开发者ID:InMobi,项目名称:level-tsd,代码行数:7,代码来源:base.py


注:本文中的leveldb.WriteBatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。