本文整理汇总了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)
示例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]
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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')
示例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)
示例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()
示例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()
示例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()
示例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