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


Python db.Key方法代码示例

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


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

示例1: ancestor

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def ancestor(self, ancestor):
        """Sets an ancestor for this query.

        This restricts the query to only return results that descend from
        a given model instance. In other words, all of the results will
        have the ancestor as their parent, or parent's parent, etc.  The
        ancestor itself is also a possible result!

        Args:
          ancestor: Model or Key (that has already been saved)

        Returns:
          Self to support method chaining.
        """
        self._ancestor = ancestor
        return self 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:pager.py

示例2: FixFirefoxBeta

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def FixFirefoxBeta(request):
  query = db.Query(models.user_agent.UserAgent)
  query.filter('family =', 'Firefox')
  query.filter('v3 =', 'b5')
  key = request.GET.get('key')
  if key:
    query.filter('__key__ >', db.Key(key))
  query.order('__key__')
  user_agent = query.get()
  if not user_agent:
    return http.HttpResponse('All Done!')

  # Do something with user_agent here.
  user_agent.family = 'Firefox Beta'
  user_agent.save()

  params = {
    'next_url': '/admin/ua/ffbeta?key=%s' % user_agent.key(),
    'current_name': user_agent.get_string_list(),
    'next_name': 'nextosity'
  }
  return util.Render(request, 'update_datastore.html', params) 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:admin_rankers.py

示例3: _get_unapplied_jobs_accross_namespaces

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def _get_unapplied_jobs_accross_namespaces(self,
                                             namespace_start,
                                             namespace_end,
                                             app):
    filters = {"__key__ >=": db.Key.from_path("__namespace__",
                                              namespace_start or 1,
                                              _app=app),
               "__key__ <=": db.Key.from_path("__namespace__",
                                              namespace_end or 1,
                                              _app=app),
               self.UNAPPLIED_LOG_FILTER: self.start_time_us}
    unapplied_query = datastore.Query(filters=filters, keys_only=True, _app=app)
    return unapplied_query.Get(
        limit=self._batch_size,
        config=datastore_rpc.Configuration(
            deadline=self.UNAPPLIED_QUERY_DEADLINE)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:18,代码来源:input_readers.py

示例4: start_test

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def start_test(self, idempotence_key=None, base_path='', **kwargs):
    """Starts this pipeline in test fashion.

    Args:
      idempotence_key: Dummy idempotence_key to use for this root pipeline.
      base_path: Dummy base URL path to use for this root pipeline.
      kwargs: Ignored keyword arguments usually passed to start().
    """
    if not idempotence_key:
      idempotence_key = uuid.uuid1().hex
    pipeline_key = db.Key.from_path(_PipelineRecord.kind(), idempotence_key)
    context = _PipelineContext('', 'default', base_path)
    future = PipelineFuture(self.output_names, force_strict=True)
    self._set_values_internal(
        context, pipeline_key, pipeline_key, future, _PipelineRecord.WAITING)
    context.start_test(self)

  # Pipeline control methods. 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:pipeline.py

示例5: cleanup

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def cleanup(self):
    """Clean up this Pipeline and all Datastore records used for coordination.

    Only works when called on a root pipeline. Child pipelines will ignore
    calls to this method.

    After this method is called, Pipeline.from_id() and related status
    methods will return inconsistent or missing results. This method is
    fire-and-forget and asynchronous.
    """
    if self._root_pipeline_key is None:
      raise UnexpectedPipelineError(
          'Could not cleanup Pipeline with unknown root pipeline ID.')
    if not self.is_root:
      return
    task = taskqueue.Task(
        params=dict(root_pipeline_key=self._root_pipeline_key),
        url=self.base_path + '/cleanup',
        headers={'X-Ae-Pipeline-Key': self._root_pipeline_key})
    taskqueue.Queue(self.queue_name).add(task) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:pipeline.py

示例6: _set_values_internal

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def _set_values_internal(self,
                           context,
                           pipeline_key,
                           root_pipeline_key,
                           outputs,
                           result_status):
    """Sets the user-visible values provided as an API by this class.

    Args:
      context: The _PipelineContext used for this Pipeline.
      pipeline_key: The db.Key of this pipeline.
      root_pipeline_key: The db.Key of the root pipeline.
      outputs: The PipelineFuture for this pipeline.
      result_status: The result status of this pipeline.
    """
    self._context = context
    self._pipeline_key = pipeline_key
    self._root_pipeline_key = root_pipeline_key
    self._result_status = result_status
    self.outputs = outputs 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:pipeline.py

示例7: _key_for_namespace

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def _key_for_namespace(namespace, app):
  """Return the __namespace__ key for a namespace.

  Args:
    namespace: The namespace whose key is requested.
    app: The id of the application that the key belongs to.

  Returns:
    A db.Key representing the namespace.
  """
  if namespace:
    return db.Key.from_path(metadata.Namespace.KIND_NAME,
                            namespace,
                            _app=app)
  else:
    return db.Key.from_path(metadata.Namespace.KIND_NAME,
                            metadata.Namespace.EMPTY_NAMESPACE_ID,
                            _app=app) 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:namespace_range.py

示例8: to_barrier_key

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def to_barrier_key(cls, barrier_index_key):
    """Converts a _BarrierIndex key to a _BarrierRecord key.

    Args:
      barrier_index_key: db.Key for a _BarrierIndex entity.

    Returns:
      db.Key for the corresponding _BarrierRecord entity.
    """
    barrier_index_path = barrier_index_key.to_path()

    # Pick out the items from the _BarrierIndex key path that we need to
    # construct the _BarrierRecord key path.
    (pipeline_kind, dependent_pipeline_id,
     unused_kind, purpose) = barrier_index_path[-4:]

    barrier_record_path = (
        pipeline_kind, dependent_pipeline_id,
        _BarrierRecord.kind(), purpose)

    return db.Key.from_path(*barrier_record_path) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:23,代码来源:models.py

示例9: start_test

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def start_test(self, idempotence_key=None, base_path='', **kwargs):
    """Starts this pipeline in test fashion.

    Args:
      idempotence_key: Dummy idempotence_key to use for this root pipeline.
      base_path: Dummy base URL path to use for this root pipeline.
      kwargs: Ignored keyword arguments usually passed to start().
    """
    if not idempotence_key:
      idempotence_key = uuid.uuid4().hex
    pipeline_key = db.Key.from_path(_PipelineRecord.kind(), idempotence_key)
    context = _PipelineContext('', 'default', base_path)
    future = PipelineFuture(self.output_names, force_strict=True)
    self._set_values_internal(
        context, pipeline_key, pipeline_key, future, _PipelineRecord.WAITING)
    context.start_test(self)

  # Pipeline control methods. 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:20,代码来源:pipeline.py

示例10: __get_value

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def __get_value(self, name):
    """Gets a `BlobInfo` value, loading an entity if necessary.

    This method allows lazy loading of the underlying datastore entity.  It
    should never be invoked directly.

    Args:
      name: The name of property for which you want to retrieve the value.

    Returns:
      The value of the `BlobInfo` property from the entity.
    """
    if self.__entity is None:
      self.__entity = datastore.Get(
          datastore_types.Key.from_path(
              self.kind(), str(self.__key), namespace=''))
    return self.__entity.get(name, None) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:19,代码来源:blobstore.py

示例11: run

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def run(self, mr_type, encoded_key, output):
    logging.debug("output is %s" % str(output))
    key = db.Key(encoded=encoded_key)
    m = FileMetadata.get(key)

    blobstore_filename = "/gs" + output[0]
    blobstore_gs_key = blobstore.create_gs_key(blobstore_filename)
    url_path = "/blobstore/" + blobstore_gs_key

    if mr_type == "WordCount":
      m.wordcount_link = url_path
    elif mr_type == "Index":
      m.index_link = url_path
    elif mr_type == "Phrases":
      m.phrases_link = url_path

    m.put() 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:19,代码来源:main.py

示例12: run_count

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def run_count(make_query, update_counter, counter):
    """Scans the entities matching a query up to FETCH_LIMIT.
    
    Returns False if we finished counting all entries."""
    # Get the next batch of entities.
    query = make_query()
    if counter.last_key:
        query = query.filter('__key__ >', db.Key(counter.last_key))
    entities = query.order('__key__').fetch(FETCH_LIMIT)
    if not entities:
        counter.last_key = ''
        return False

    # Pass the entities to the counting function.
    for entity in entities:
        update_counter(counter, entity)

    # Remember where we left off.
    counter.last_key = str(entities[-1].key())
    return True 
开发者ID:google,项目名称:personfinder,代码行数:22,代码来源:tasks.py

示例13: _decode_bookmark

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def _decode_bookmark(self, bookmark):
        """Decodes a bookmark and prepares the values to be used on queries.
        Currently supported properties are DateTimeProperty, FloatProperty,
        IntegerProperty, StringProperty and ReferenceProperty.

        Returns:
          A dictionary of property names/values to be used in queries.
        """
        required = list(self._bookmark_properties)
        required.append('_')
        try:
            bookmark = decode_bookmark(bookmark)
            # Ensure that all required values are available.
            for key in required:
                if key not in bookmark:
                    return None
        except:
            return None

        for key in required:
            value = bookmark[key]
            if key == '_':
                self._first_result = bookmark[key]
            elif key == '__key__':
                bookmark[key] = db.Key(value)
            else:
                prop = getattr(self._model_class, key)
                if isinstance(prop, db.ReferenceProperty):
                    bookmark[key] = db.Key(value)
                elif isinstance(prop, db.DateTimeProperty):
                    bookmark[key] = parseDateTime(value)
                else:
                    bookmark[key] = prop.data_type(value)

        return bookmark

# from http://kbyanc.blogspot.com/2007/09/python-reconstructing-datetimes-from.html 
开发者ID:elsigh,项目名称:browserscope,代码行数:39,代码来源:pager.py

示例14: FixFirefoxBetaCategories

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def FixFirefoxBetaCategories(request):
  query = db.Query(result_stats.CategoryBrowserManager)
  key = request.GET.get('key')
  if key:
    query.filter('__key__ >', db.Key(key))
  query.order('__key__')
  bm = query.get()
  if not bm:
    return http.HttpResponse('All Done!')

  dirty = False
  newbrowsers = []
  for browser in bm.browsers:
    if browser.find('Firefox 4') != -1:
      dirty = True
      browser = browser.replace('Firefox 4', 'Firefox Beta 4')
    newbrowsers.append(browser)

  if dirty:
    bm.browsers = newbrowsers
    bm.save()

  params = {
    'next_url': '/admin/ua/ffbeta?key=%s' % bm.key(),
    'current_name': 'Dirty? %s - %s' % (dirty, newbrowsers)
  }
  return util.Render(request, 'update_datastore.html', params) 
开发者ID:elsigh,项目名称:browserscope,代码行数:29,代码来源:admin_rankers.py

示例15: SubmitChanges

# 需要导入模块: from google.appengine.ext import db [as 别名]
# 或者: from google.appengine.ext.db import Key [as 别名]
def SubmitChanges(request):
  logging.info('^^^^^^^^^^^^^^^^^^^^ SubmitChanges')
  encoded_ua_keys = [key[3:] for key in request.GET if key.startswith('ac_')]
  logging.info('Encoded ua keys: %s' % ', '.join(encoded_ua_keys))
  update_user_agents = []
  for encoded_key in encoded_ua_keys:
    action = request.REQUEST['ac_%s' % encoded_key]
    ua = db.get(db.Key(encoded=encoded_key))
    if action == 'confirm' and not ua.confirmed:
      ua.confirmed = True
      update_user_agents.append(ua)
    if action == 'unconfirm' and ua.confirmed:
      ua.confirmed = False
      update_user_agents.append(ua)
    if action == 'change' and not ua.changed:
      change_to = request.REQUEST['cht_%s' % key]
      if change_to != ua.pretty():
        #UserAgent.parse_to_string_list(change_to)
        #ua.family =
        pass
  logging.info('Update user agents: %s' % ', '.join([ua.string for ua in update_user_agents]))
  db.put(update_user_agents)
  return http.HttpResponseRedirect(
      '/admin/confirm-ua?browser=%s&confirmed=%s&cursor=%s' %
      (request.REQUEST.get('browser', ''),
       request.REQUEST.get('confirmed', ''),
       request.REQUEST.get('cursor', ''))) 
开发者ID:elsigh,项目名称:browserscope,代码行数:29,代码来源:admin.py


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