當前位置: 首頁>>代碼示例>>Python>>正文


Python IMasterStore.get方法代碼示例

本文整理匯總了Python中lp.services.database.interfaces.IMasterStore.get方法的典型用法代碼示例。如果您正苦於以下問題:Python IMasterStore.get方法的具體用法?Python IMasterStore.get怎麽用?Python IMasterStore.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lp.services.database.interfaces.IMasterStore的用法示例。


在下文中一共展示了IMasterStore.get方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_can_shutdown_slave_only

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
    def test_can_shutdown_slave_only(self):
        """Confirm that this TestCase's test infrastructure works as needed.
        """
        master_store = IMasterStore(Person)
        slave_store = ISlaveStore(Person)

        # Both Stores work when pgbouncer is up.
        master_store.get(Person, 1)
        slave_store.get(Person, 1)

        # Slave Store breaks when pgbouncer is torn down. Master Store
        # is fine.
        self.pgbouncer_fixture.stop()
        master_store.get(Person, 2)
        self.assertRaises(DisconnectionError, slave_store.get, Person, 2)
開發者ID:vitaminmoo,項目名稱:unnaturalcode,代碼行數:17,代碼來源:test_dbpolicy.py

示例2: removeAssociation

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
 def removeAssociation(self, server_url, handle):
     """See `OpenIDStore`."""
     store = IMasterStore(self.Association)
     assoc = store.get(self.Association, (
             server_url.decode('UTF-8'), handle.decode('ASCII')))
     if assoc is None:
         return False
     store.remove(assoc)
     return True
開發者ID:pombreda,項目名稱:UnnaturalCodeFork,代碼行數:11,代碼來源:baseopenidstore.py

示例3: test_useNonce

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
    def test_useNonce(self):
        timestamp = time.time()
        # The nonce can only be used once.
        self.assertEqual(self.store.useNonce("server-url", timestamp, "salt"), True)
        storm_store = IMasterStore(self.store.Nonce)
        new_nonce = storm_store.get(self.store.Nonce, (u"server-url", timestamp, u"salt"))
        self.assertIsNot(None, new_nonce)

        self.assertEqual(self.store.useNonce("server-url", timestamp, "salt"), False)
        self.assertEqual(self.store.useNonce("server-url", timestamp, "salt"), False)
開發者ID:vitaminmoo,項目名稱:unnaturalcode,代碼行數:12,代碼來源:test_baseopenidstore.py

示例4: storeAssociation

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
 def storeAssociation(self, server_url, association):
     """See `OpenIDStore`."""
     store = IMasterStore(self.Association)
     db_assoc = store.get(
         self.Association, (server_url.decode('UTF-8'),
                            association.handle.decode('ASCII')))
     if db_assoc is None:
         db_assoc = self.Association(server_url, association)
         store.add(db_assoc)
     else:
         db_assoc.update(association)
開發者ID:pombreda,項目名稱:UnnaturalCodeFork,代碼行數:13,代碼來源:baseopenidstore.py

示例5: test_getAssociation_expired

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
    def test_getAssociation_expired(self):
        lifetime = 600
        timestamp = int(time.time()) - 2 * lifetime
        self.store.storeAssociation("server-url", Association("handle", "secret", timestamp, lifetime, "HMAC-SHA1"))
        # The association is not returned because it is out of date.
        # Further more, it is removed from the database.
        assoc = self.store.getAssociation("server-url", "handle")
        self.assertEquals(assoc, None)

        store = IMasterStore(self.store.Association)
        db_assoc = store.get(self.store.Association, (u"server-url", u"handle"))
        self.assertEqual(db_assoc, None)
開發者ID:vitaminmoo,項目名稱:unnaturalcode,代碼行數:14,代碼來源:test_baseopenidstore.py

示例6: get_object_from_master_store

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
def get_object_from_master_store(obj):
    """Return a copy of the given object retrieved from its master Store.

    Returns the object if it already comes from the relevant master Store.

    Registered as a trusted adapter, so if the input is security wrapped,
    so is the result. Otherwise an unwrapped object is returned.
    """
    master_store = IMasterStore(obj)
    if master_store is not Store.of(obj):
        obj = master_store.get(obj.__class__, obj.id)
        if obj is None:
            return None
    alsoProvides(obj, IMasterObject)
    return obj
開發者ID:pombreda,項目名稱:UnnaturalCodeFork,代碼行數:17,代碼來源:adapter.py

示例7: __call__

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
    def __call__(self, chunk_size):
        """Take a batch of targets and update their BugTasks' name caches.

        See `ITunableLoop`.
        """
        # XXX 2008-03-05 gmb:
        #     We cast chunk_size to an integer to ensure that we're not
        #     trying to slice using floats or anything similarly
        #     foolish. We shouldn't have to do this, but bug #198767
        #     means that we do.
        chunk_size = int(chunk_size)

        start = self.offset
        end = self.offset + chunk_size

        chunk = self.candidates[start:end]

        self.transaction.begin()
        store = IMasterStore(BugTask)

        # Transpose the target rows into lists of object IDs to retrieve.
        ids_to_cache = zip(*(target for (target, names) in chunk))
        for index, cls in enumerate(target_classes):
            # Get all of the objects that we will need into the cache.
            list(store.find(cls, cls.id.is_in(set(ids_to_cache[index]))))

        for target_bits, cached_names in chunk:
            self.offset += 1
            # Resolve the IDs to objects, and get the actual IBugTarget.
            # If the ID is None, don't even try to get an object.
            target_objects = (
                (store.get(cls, id) if id is not None else None) for cls, id in zip(target_classes, target_bits)
            )
            target = bug_target_from_key(*target_objects)
            new_name = target.bugtargetdisplayname
            cached_names.discard(new_name)
            # If there are any outdated names cached, update them all in
            # a single query.
            if len(cached_names) > 0:
                self.logger.info("Updating %r to '%s'." % (tuple(cached_names), new_name))
                self.total_updated += len(cached_names)
                conditions = (col == id for col, id in zip(target_columns, target_bits))
                to_update = store.find(BugTask, BugTask.targetnamecache.is_in(cached_names), *conditions)
                to_update.set(targetnamecache=new_name)

        self.logger.info("Checked %i targets." % len(chunk))

        self.transaction.commit()
開發者ID:vitaminmoo,項目名稱:unnaturalcode,代碼行數:50,代碼來源:bugtasktargetnamecaches.py

示例8: useNonce

# 需要導入模塊: from lp.services.database.interfaces import IMasterStore [as 別名]
# 或者: from lp.services.database.interfaces.IMasterStore import get [as 別名]
    def useNonce(self, server_url, timestamp, salt):
        """See `OpenIDStore`."""
        # If the nonce is too far from the present time, it is not valid.
        if abs(timestamp - time.time()) > nonce.SKEW:
            return False

        server_url = server_url.decode('UTF-8')
        salt = salt.decode('ASCII')

        store = IMasterStore(self.Nonce)
        old_nonce = store.get(self.Nonce, (server_url, timestamp, salt))
        if old_nonce is not None:
            # The nonce has already been seen, so reject it.
            return False
        # Record the nonce so it can't be used again.
        store.add(self.Nonce(server_url, timestamp, salt))
        return True
開發者ID:pombreda,項目名稱:UnnaturalCodeFork,代碼行數:19,代碼來源:baseopenidstore.py


注:本文中的lp.services.database.interfaces.IMasterStore.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。