本文整理汇总了Python中google.appengine.ext.db.get方法的典型用法代码示例。如果您正苦于以下问题:Python db.get方法的具体用法?Python db.get怎么用?Python db.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.ext.db
的用法示例。
在下文中一共展示了db.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UploadCategoryBrowsers
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def UploadCategoryBrowsers(request):
"""Upload browser lists for each category and version level."""
category = request.REQUEST.get('category')
version_level = request.REQUEST.get('version_level')
browsers_str = request.REQUEST.get('browsers')
if not category:
return http.HttpResponseServerError(
'Must set "category".')
if not version_level.isdigit() or int(version_level) not in range(4):
return http.HttpResponseServerError(
'Version level must be an integer 0..3.')
if not browsers_str:
return http.HttpResponseServerError(
'Must set "browsers" (comma-separated list).')
version_level = int(version_level)
browsers = browsers_str.split(',')
result_stats.CategoryBrowserManager.SetBrowsers(
category, version_level, browsers)
UpdateSummaryBrowsers(request)
return http.HttpResponse('Success.')
示例2: _get_descending_key
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def _get_descending_key(gettime=time.time):
"""Returns a key name lexically ordered by time descending.
This lets us have a key name for use with Datastore entities which returns
rows in time descending order when it is scanned in lexically ascending order,
allowing us to bypass index building for descending indexes.
Args:
gettime: Used for testing.
Returns:
A string with a time descending key.
"""
now_descending = int((_FUTURE_TIME - gettime()) * 100)
request_id_hash = os.environ.get("REQUEST_ID_HASH")
if not request_id_hash:
request_id_hash = str(random.getrandbits(32))
return "%d%s" % (now_descending, request_id_hash)
示例3: _processing_limit
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def _processing_limit(self, spec):
"""Get the limit on the number of map calls allowed by this slice.
Args:
spec: a Mapreduce spec.
Returns:
The limit as a positive int if specified by user. -1 otherwise.
"""
processing_rate = float(spec.mapper.params.get("processing_rate", 0))
slice_processing_limit = -1
if processing_rate > 0:
slice_processing_limit = int(math.ceil(
_SLICE_DURATION_SEC*processing_rate/int(spec.mapper.shard_count)))
return slice_processing_limit
# Deprecated. Only used by old test cases.
# TODO(user): clean up tests.
示例4: _schedule_slice
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def _schedule_slice(cls,
shard_state,
tstate,
queue_name=None,
eta=None,
countdown=None):
"""Schedule slice scanning by adding it to the task queue.
Args:
shard_state: An instance of ShardState.
tstate: An instance of TransientShardState.
queue_name: Optional queue to run on; uses the current queue of
execution or the default queue if unspecified.
eta: Absolute time when the MR should execute. May not be specified
if 'countdown' is also supplied. This may be timezone-aware or
timezone-naive.
countdown: Time in seconds into the future that this MR should execute.
Defaults to zero.
"""
queue_name = queue_name or os.environ.get("HTTP_X_APPENGINE_QUEUENAME",
"default")
task = cls._state_to_task(tstate, shard_state, eta, countdown)
cls._add_task(task, tstate.mapreduce_spec, queue_name)
示例5: _get_required_param
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def _get_required_param(self, param_name):
"""Get a required request parameter.
Args:
param_name: name of request parameter to fetch.
Returns:
parameter value
Raises:
errors.NotEnoughArgumentsError: if parameter is not specified.
"""
value = self.request.get(param_name)
if not value:
raise errors.NotEnoughArgumentsError(param_name + " not specified")
return value
示例6: _get_query_spec
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def _get_query_spec(cls, mapper_spec):
"""Construct a model.QuerySpec from model.MapperSpec."""
params = _get_params(mapper_spec)
entity_kind = params[cls.ENTITY_KIND_PARAM]
filters = params.get(cls.FILTERS_PARAM)
app = params.get(cls._APP_PARAM)
ns = params.get(cls.NAMESPACE_PARAM)
return model.QuerySpec(
entity_kind=cls._get_raw_entity_kind(entity_kind),
keys_only=bool(params.get(cls.KEY_RANGE_PARAM, False)),
filters=filters,
batch_size=int(params.get(cls.BATCH_SIZE_PARAM, cls._BATCH_SIZE)),
model_class_path=entity_kind,
app=app,
ns=ns)
示例7: _read
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def _read(self, entry):
"""Read entry content.
Args:
entry: zip file entry as zipfile.ZipInfo.
Returns:
Entry content as string.
"""
start_time = time.time()
content = self._zip.read(entry.filename)
ctx = context.get()
if ctx:
operation.counters.Increment(COUNTER_IO_READ_BYTES, len(content))(ctx)
operation.counters.Increment(
COUNTER_IO_READ_MSEC, int((time.time() - start_time) * 1000))(ctx)
return content
示例8: validate
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def validate(cls, mapper_spec):
"""Validates mapper spec and all mapper parameters.
Args:
mapper_spec: The MapperSpec for this InputReader.
Raises:
BadReaderParamsError: required parameters are missing or invalid.
"""
if mapper_spec.input_reader_class() != cls:
raise BadReaderParamsError("Mapper input reader class mismatch")
params = _get_params(mapper_spec)
if cls.BLOB_KEY_PARAM not in params:
raise BadReaderParamsError("Must specify 'blob_key' for mapper input")
blob_key = params[cls.BLOB_KEY_PARAM]
blob_info = blobstore.BlobInfo.get(blobstore.BlobKey(blob_key))
if not blob_info:
raise BadReaderParamsError("Could not find blobinfo for key %s" %
blob_key)
示例9: split_input
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def split_input(cls, mapper_spec):
"""Returns a list of input readers for the input spec.
Args:
mapper_spec: The MapperSpec for this InputReader.
Returns:
A list of InputReaders.
"""
batch_size = int(_get_params(mapper_spec).get(
cls.BATCH_SIZE_PARAM, cls._BATCH_SIZE))
shard_count = mapper_spec.shard_count
namespace_ranges = namespace_range.NamespaceRange.split(shard_count,
contiguous=True)
return [NamespaceInputReader(ns_range, batch_size)
for ns_range in namespace_ranges]
示例10: __iter__
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def __iter__(self):
"""Iterate over records in file.
Yields records as strings.
"""
ctx = context.get()
while self._reader:
try:
start_time = time.time()
record = self._reader.read()
if ctx:
operation.counters.Increment(
COUNTER_IO_READ_MSEC, int((time.time() - start_time) * 1000))(ctx)
operation.counters.Increment(COUNTER_IO_READ_BYTES, len(record))(ctx)
yield record
except (files.ExistenceError), e:
raise errors.FailJobError("ExistenceError: %s" % e)
except (files.UnknownError), e:
raise errors.RetrySliceError("UnknownError: %s" % e)
示例11: get_callback_task
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def get_callback_task(self, *args, **kwargs):
"""Returns a task for calling back this Pipeline.
Args:
params: Keyword argument containing a dictionary of key/value pairs
that will be passed to the callback when it is executed.
args, kwargs: Passed to the taskqueue.Task constructor. Use these
arguments to set the task name (for idempotence), etc.
Returns:
A taskqueue.Task instance that must be enqueued by the caller.
"""
if not self.async:
raise UnexpectedPipelineError(
'May only call get_callback_task() method for asynchronous pipelines.')
params = kwargs.get('params', {})
kwargs['params'] = params
params['pipeline_id'] = self._pipeline_key.name()
kwargs['url'] = self.base_path + '/callback'
kwargs['method'] = 'POST'
return taskqueue.Task(*args, **kwargs)
示例12: testCreateAddsPledge
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def testCreateAddsPledge(self):
resp = self.makeDefaultRequest()
pledge = db.get(resp.json['id'])
self.assertEquals(4200, pledge.amountCents)
self.assertEquals(resp.json['auth_token'], pledge.url_nonce)
self.assertEquals('fake_1234', pledge.stripeCustomer)
self.assertEquals('charge_2468', pledge.stripe_charge_id)
self.assertEquals('rocket', pledge.team)
user = model.User.get_by_key_name('pika@pokedex.biz')
def assertEqualsSampleProperty(prop_name, actual):
self.assertEquals(self.pledge[prop_name], actual)
assertEqualsSampleProperty('email', user.email)
self.assertEquals(u'Pik\u00E1', user.first_name)
self.assertEquals('Chu', user.last_name)
assertEqualsSampleProperty('occupation', user.occupation)
assertEqualsSampleProperty('employer', user.employer)
assertEqualsSampleProperty('phone', user.phone)
assertEqualsSampleProperty('target', user.target)
assertEqualsSampleProperty('subscribe', user.mail_list_optin)
assert user.url_nonce
assert not user.from_import
示例13: request
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def request(pledge_key):
"""Indicates that we are allowed to execute the charge at our leisure."""
charge_key = ChargeStatus._get_charge_key(pledge_key)
pledge = db.get(pledge_key)
charge_status = db.get(charge_key)
if not pledge:
raise Error('No pledge found with key: %s' % pledge_key)
if charge_status:
logging.warning('Requesting already requested charge for pledge: %s',
pledge_key)
return
charge_status = ChargeStatus(key=charge_key,
request_time=datetime.datetime.now())
charge_status.put()
示例14: get_count
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def get_count(name):
total = cache.GetShardedCounterTotal(name)
if total is None:
total = 0
all_keys = ShardedCounter._get_keys_for(name)
for counter in db.get(all_keys):
if counter is not None:
total += counter.count
logging.info("recalculated counter %s to %s", name, total)
# Add the stretch check total which is not reflected elsewhere in the counter
# And is set manually
# This is here so that is only read out on a cache miss
stretchCheckTotal = StretchCheckTotal.get()
if stretchCheckTotal < STRETCH_CACHE_MISS_TOTAL:
stretchCheckTotal = STRETCH_CACHE_MISS_TOTAL
total += stretchCheckTotal
cache.SetShardedCounterTotal(name, total)
return total
示例15: get
# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import get [as 别名]
def get(self):
util.EnableCors(self)
WP_PLEDGES = 4099
VERSION_12_AND_UNDER = 59009
count = memcache.get('TOTAL-PLEDGES')
if not count:
query = model.Pledge.all(keys_only=True).filter('model_version >', 12)
i = 0
while True:
result = query.fetch(1000)
i = i + len(result)
if len(result) < 1000:
break
cursor = query.cursor()
query.with_cursor(cursor)
count = i + WP_PLEDGES + VERSION_12_AND_UNDER
memcache.set('TOTAL-PLEDGES', count, 120)
self.response.headers['Content-Type'] = 'application/json'
json.dump({'count':count}, self.response)