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


Python ndb.get_context方法代码示例

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


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

示例1: setUp

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def setUp(self):
        super(BaseTest, self).setUp()

        root_path = '.'
        application_id = 'graphene-gae-test'

        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.setup_env(app_id=application_id, overwrite=True)
        policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=self.datastore_probability)
        self.testbed.init_datastore_v3_stub(root_path=root_path, consistency_policy=policy, require_indexes=True)
        self.testbed.init_app_identity_stub()
        self.testbed.init_blobstore_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub(root_path=root_path)
        self.testbed.init_urlfetch_stub()
        self.storage = cloudstorage_stub.CloudStorageStub(self.testbed.get_stub('blobstore').storage)
        self.testbed.init_mail_stub()
        self.testbed.init_user_stub()
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)

        ndb.get_context().clear_cache()
        ndb.get_context().set_cache_policy(lambda x: True) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:26,代码来源:base_test.py

示例2: setUp

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        # Clear ndb's in-context cache between tests.
        # This prevents data from leaking between tests.
        # Alternatively, you could disable caching by
        # using ndb.get_context().set_cache_policy(False)
        ndb.get_context().clear_cache()

# [END datastore_example_test]

    # [START datastore_example_teardown] 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:19,代码来源:datastore_test.py

示例3: _tidy_stale_BotTaskDimensions

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def _tidy_stale_BotTaskDimensions(now):
  """Removes all stale BotTaskDimensions entities.

  This also cleans up entities for bots that were deleted or that died, as the
  corresponding will become stale after _EXTEND_VALIDITY.
  """
  qit = BotTaskDimensions.query(BotTaskDimensions.valid_until_ts < now).iter(
      batch_size=64, keys_only=True)
  btd = []
  while (yield qit.has_next_async()):
    key = qit.next()
    # This function takes care of confirming that the entity is indeed
    # expired.
    res = yield _remove_old_entity_async(key, now)
    btd.append(res)
    if res:
      bot_id = res.parent().string_id()
      yield ndb.get_context().memcache_delete(bot_id, namespace='task_queues')
      logging.debug('- BTD: %d for bot %s', res.integer_id(), bot_id)
  raise ndb.Return(btd) 
开发者ID:luci,项目名称:luci-py,代码行数:22,代码来源:task_queues.py

示例4: process_export

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def process_export():
    bucket = int(flask.request.values['bucket'])
    filename = '/ilps-search-log.appspot.com/search_log.%d.gz' % bucket
    with gcs.open(filename, 'w' , 'text/plain', {'content-encoding': 'gzip'}) as f:
        bucket_size = int(flask.request.values['bucket_size'])
        offset = bucket * bucket_size
        with gzip.GzipFile('', fileobj=f, mode='wb') as gz:
            ndb.get_context().clear_cache()
            for s in Session.query(Session.shared == True).iter(batch_size=10,
                    offset=offset, limit=bucket_size):
                ndb.get_context().clear_cache()
                gc.collect()
                s.user_id = ''
                print >>gz, json.dumps(s.to_dict(), default=util.default,
                        ensure_ascii=False).encode('utf-8')
    response = 'Written: %s' % str(blobstore.create_gs_key('/gs' + filename))
    app.logger.info(response)
    return response, 200 
开发者ID:varepsilon,项目名称:cas-eval,代码行数:20,代码来源:main.py

示例5: _CreateRuleChangeSet

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def _CreateRuleChangeSet(self, rules_future, new_policy):
    """Creates a RuleChangeSet and trigger an attempted commit."""
    rules = rules_future.get_result()
    # If there are no rules to be created (rare but possible), we can just drop
    # the change set entirely.
    if not rules:
      return

    keys = [rule.key for rule in rules]
    change = rule_models.RuleChangeSet(
        rule_keys=keys, change_type=new_policy, parent=self.blockable.key)
    change.put()

    # Attempt to commit the change set in a deferred task.
    # NOTE: If we're in a transaction, we should only send out the
    # request to Bit9 once the RuleChangeSet has been successfully created.
    # If we're not in a transaction, this executes immediately.
    ndb.get_context().call_on_commit(self._TriggerCommit) 
开发者ID:google,项目名称:upvote,代码行数:20,代码来源:api.py

示例6: _set_ndb_cache_policy

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def _set_ndb_cache_policy():
  """Tell NDB to never cache anything in memcache or in-process.

  This ensures that entities fetched from Datastore input_readers via NDB
  will not bloat up the request memory size and Datastore Puts will avoid
  doing calls to memcache. Without this you get soft memory limit exits,
  which hurts overall throughput.
  """
  ndb_ctx = ndb.get_context()
  ndb_ctx.set_cache_policy(lambda key: False)
  ndb_ctx.set_memcache_policy(lambda key: False) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:13,代码来源:util.py

示例7: urlfetch_async

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def urlfetch_async(self, url, **kwds):
    """Make an async urlfetch() call.

    This just passes the url and keyword arguments to NDB's async
    urlfetch() wrapper in the current context.

    This returns a Future despite not being decorated with @ndb.tasklet!
    """
    ctx = ndb.get_context()
    return ctx.urlfetch(url, **kwds) 
开发者ID:googlearchive,项目名称:billing-export-python,代码行数:12,代码来源:rest_api.py

示例8: set_in_process_cache_policy

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def set_in_process_cache_policy(func):
    context = ndb.get_context()
    context.set_cache_policy(func) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets.py

示例9: set_memcache_policy

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def set_memcache_policy(func):
    context = ndb.get_context()
    context.set_memcache_policy(func) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets.py

示例10: bypass_in_process_cache_for_account_entities

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def bypass_in_process_cache_for_account_entities():
    context = ndb.get_context()
    context.set_cache_policy(lambda key: key.kind() != 'Account') 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets.py

示例11: set_memcache_timeout_policy

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def set_memcache_timeout_policy(func):
    context = ndb.get_context()
    context.set_memcache_timeout_policy(func) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets.py

示例12: clear_cache

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def clear_cache():
    context = ndb.get_context()
    context.clear_cache() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:5,代码来源:snippets.py

示例13: test_set_in_process_cache_policy

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def test_set_in_process_cache_policy(testbed):
    def policy(key):
        return 1 == 1

    snippets.set_in_process_cache_policy(policy)
    assert policy == ndb.get_context().get_cache_policy() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:8,代码来源:snippets_test.py

示例14: test_set_memcache_policy

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def test_set_memcache_policy(testbed):
    def policy(key):
        return 1 == 2

    snippets.set_memcache_policy(policy)
    assert policy == ndb.get_context().get_memcache_policy() 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:8,代码来源:snippets_test.py

示例15: test_bypass_in_process_cache_for_account_entities

# 需要导入模块: from google.appengine.ext import ndb [as 别名]
# 或者: from google.appengine.ext.ndb import get_context [as 别名]
def test_bypass_in_process_cache_for_account_entities(testbed):
    context = ndb.get_context()
    assert context.get_cache_policy() == context.default_cache_policy
    snippets.bypass_in_process_cache_for_account_entities()
    assert context.get_cache_policy() != context.default_cache_policy 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:7,代码来源:snippets_test.py


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