當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。