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


Python Store.remove方法代码示例

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


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

示例1: go_store

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import remove [as 别名]
def go_store():
    store = Store()

    store.remove(None)
    store.add(323, 2, 10, 88, 78, 415, 89, 189)
    store.remove(78)

    store.save()
    store.load()

    print store.grep('\d*[02468]$')
    print store.find(89, -1, 415)

    for item in store.items():
        print item
开发者ID:dmitryfisko,项目名称:University,代码行数:17,代码来源:main.py

示例2: TestStore

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import remove [as 别名]
class TestStore(unittest2.TestCase):
    
    def setUp(self):
        self.store = Store(name="scratch")
        self.ns = Namespace('http://example.com/#')
        
    def tearDown(self):
        self.store.close()
        
    def testSize(self):
        """ Tests the size of the repository """
        self.assertEqual(len(self.store),0)
        
    def testAdd(self):
        bob = self.ns['bob']
        name = self.ns['name']
        value = Literal('Bob Bilbins')
        self.store.add((bob, name, value))
        self.assertEqual(len(self.store),1)
        
        
    def testRemove(self):
        triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
        self.store.add(triple)
        self.assertEqual(len(self.store),1)
        self.store.remove(triple)
        self.assertEqual(len(self.store),0)
        
    def testTriples(self):
        """ Tests the search by triple. """
        triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
        self.store.add(triple)
        for tri in self.store.triples((self.ns['alice'],None, None)):
            for i in range(3):
                self.assertEqual(tri[i], triple[i])
                
    def testSimpleSparql(self):
        triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
        self.store.add(triple)
        for tri in self.store.query("SELECT ?s ?p ?o  WHERE {?s ?p ?o .}"):
            for i in range(3):
                self.assertEqual(tri[i], triple[i])
        
    def testNamespacedSparql(self):
        triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
        self.store.add(triple)
        self.store.add((self.ns['bob'],self.ns['name'],Literal('Bob')))
        for tri in self.store.query("SELECT ?p ?o  WHERE { ex:alice ?p ?o .}", initNs={'ex':self.ns}):
            for i in range(1,3):
                self.assertEqual(tri[i-1], triple[i])
        
    def testBindedSparql(self):
        triple = (self.ns['alice'],self.ns['name'],Literal('Alice'))
        self.store.add(triple)
        self.store.add((self.ns['bob'],self.ns['name'],Literal('Bob')))
        for tri in self.store.query("SELECT ?p ?o  WHERE { ?s ?p ?o .}", initBindings={'s':self.ns['alice']}):
            for i in range(1,3):
                self.assertEqual(tri[i-1], triple[i])
    
    def testDataTypes(self):
        birth = Literal('2006-01-03', datatype=_XSD_NS.date)
        comp = Literal('2006-01-01', datatype=_XSD_NS.date)
        triple = (self.ns['alice'],self.ns['birthdate'],birth)
        self.store.add(triple)
        for s, p, o in self.store.query("SELECT ?s ?p ?o  WHERE {?s ?p ?o .}"):
            self.assertLess(comp,birth)
开发者ID:mpetyx,项目名称:pychatbot,代码行数:68,代码来源:test.py

示例3: NodeServer

# 需要导入模块: from store import Store [as 别名]
# 或者: from store.Store import remove [as 别名]

#.........这里部分代码省略.........

    def __internal_get(self, key):
        if __debug__: logging.debug('key: %s', key)
        timestamp, value = self.__store.get(key)
        return timestamp or 0, value

    def __internal_set(self, key, timestamp, value):
        if __debug__: logging.debug('key: %s', key)
        self.__store.set(key, timestamp, value)
        return timestamp

    def __internal_stat(self, key):
        if __debug__: logging.debug('key: %s', key)
        timestamp, value = self.__store.get(key)
        if __debug__: logging.debug('timestamp: %s', timestamp)
        return timestamp or 0

    def __public_get(self, key):
        if __debug__: logging.debug("key: %s", key)
        timestamp, value = None, None
        node_ids = self.__configuration.find_nodes_for_key(key)
        if self.node.id in node_ids:
            timestamp, value = self.__store.get(key)
        if self.__read_repair_enabled:
            new_timestamp, new_value = self.__read_repair(key, timestamp, value, node_ids)
            if new_timestamp > timestamp and self.node.id in node_ids:
                timestamp, value = new_timestamp, new_value
                self.__store.set(key, timestamp, value)
        return timestamp or 0, value


    def __public_set(self, key, timestamp, value):
        if __debug__: logging.debug("key: %s", key)
        node_ids = self.__configuration.find_nodes_for_key(key)
        if self.__read_repair_enabled:
            timestamp, value = self.__read_repair(key, timestamp, value, node_ids)
        if self.node.id in node_ids:
            self.__store.set(key, timestamp, value)
        return timestamp

    def __public_stat(self, key):
        return self.__public_get(key)

    def __repair_key(self, key):
        node_ids = self.__configuration.find_nodes_for_key(key)
        if self.node.id not in node_ids:
            self.__store.remove(key)
        else:
            timestamp, value = self.__store.get(key)
            if timestamp:
                new_timestamp, new_value = self.__read_repair(key, timestamp, value, node_ids)
                if new_timestamp > timestamp:
                    self.__store.set(key, new_timestamp, new_value)

    def __repair_store(self):
        if not self.node:
            return
        if not self.__background_repair_enabled:
            return

        total_count = self.__store.count()
        scan_count = 0
        start_time = time.time()
        last_time = start_time
        elapsed_time = 0

        logging.info('Starting store repair. Total %d keys.', total_count)

        # TODO: Refactor away this cursor muck
        cursor = self.__store.cursor()
        while True:
            key = None
            try:
                cursor.next()
                key = cursor.key()
            except StopIteration:
                break
            except KeyError, e:
                logging.warning('KeyError: %s', e)
            except Exception, e:
                logging.warning('TC Exception: %s', e)
                # Not supposed to get this... pytc is broken.
                pass
            if not key:
                continue
            self.__repair_key(key)
            scan_count += 1
            now = time.time()
            if now - last_time > 5.0:
                last_time = now
                elapsed_time = now - start_time
                if __debug__: logging.debug('Store repair in progress. Scanned %d keys. Elapsed time: %s', scan_count, timedelta(seconds=elapsed_time))
            total_count = self.__store.count()
            if total_count == 0:
                break
            if not self.node:
                break
            if not self.__background_repair_enabled:
                break
            coio.sleep(self.__background_repair_interval_seconds / total_count)
开发者ID:danielnorberg,项目名称:tako,代码行数:104,代码来源:nodeserver.py


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