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


Python namespace_manager.set_namespace方法代码示例

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


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

示例1: run_taskqueue_tasks

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def run_taskqueue_tasks(testbed, app):
    """Runs tasks that are queued in the GAE taskqueue."""
    from google.appengine.api import namespace_manager

    tasks = testbed.taskqueue_stub.get_filtered_tasks()
    for task in tasks:
        namespace = task.headers.get('X-AppEngine-Current-Namespace', '')
        previous_namespace = namespace_manager.get_namespace()
        try:
            namespace_manager.set_namespace(namespace)
            app.post(
                task.url,
                task.extract_params(),
                headers=dict([
                    (k, v) for k, v in task.headers.iteritems()
                    if k.startswith('X-AppEngine')]))
        finally:
            namespace_manager.set_namespace(previous_namespace)


# py.test helpers 
开发者ID:GoogleCloudPlatform,项目名称:python-repo-tools,代码行数:23,代码来源:appengine.py

示例2: get

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def get(self, namespace='default'):
        # Queue task to update global counter.
        current_global_count = get_count('counter')
        taskqueue.add(
            url='/tasks/counter',
            params={'counter_name': 'counter'})

        # Queue task to update counter in specified namespace.
        previous_namespace = namespace_manager.get_namespace()
        try:
            namespace_manager.set_namespace(namespace)
            current_namespace_count = get_count('counter')
            taskqueue.add(
                url='/tasks/counter',
                params={'counter_name': 'counter'})
        finally:
            namespace_manager.set_namespace(previous_namespace)

        self.response.write(
            'Counters will be updated asyncronously.'
            'Current values: Global: {}, Namespace {}: {}'.format(
                current_global_count, namespace, current_namespace_count)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:24,代码来源:taskqueue.py

示例3: put_empty

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def put_empty(self, token):
    """Empty put is used to query upload progress.

    The file must has not finished upload.

    Args:
      token: upload token returned by post_start_creation.

    Returns:
      last offset uploaded. -1 if none has been uploaded.

    Raises:
      ValueError: if token matches no in progress uploads.
    """
    ns = namespace_manager.get_namespace()
    try:
      namespace_manager.set_namespace('')
      gcs_file = _AE_GCSFileInfo_.get_by_key_name(token)
      if not gcs_file:
        raise ValueError('Invalid token', httplib.BAD_REQUEST)
      return gcs_file.next_offset - 1
    finally:
      namespace_manager.set_namespace(ns) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:25,代码来源:cloudstorage_stub.py

示例4: _create_entities

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def _create_entities(keys_itr,
                     key_to_scatter_val,
                     ns=None,
                     entity_model_cls=TestEntity):
  """Create entities for tests.

  Args:
    keys_itr: an iterator that contains all the key names.
    key_to_scatter_val: a dict that maps key names to its scatter values.
    ns: the namespace to create the entity at.
    entity_model_cls: entity model class.

  Returns:
    A list of entities created.
  """
  namespace_manager.set_namespace(ns)
  set_scatter_setter(key_to_scatter_val)
  entities = []
  for k in keys_itr:
    entity = entity_model_cls(key_name=str(k))
    entities.append(entity)
    entity.put()
  namespace_manager.set_namespace(None)
  return entities 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:26,代码来源:testutil.py

示例5: testMakeQuery

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def testMakeQuery(self):
    keys = [str(i) for i in range(30)]
    a_vals = list(range(10))
    b_vals = list(range(3))
    ns = "foo"
    namespace_manager.set_namespace(ns)
    for k in keys:
      for a in a_vals:
        for b in b_vals:
          TestEntity(key_name=k, a=a, b=b).put()
    namespace_manager.set_namespace(None)

    r = property_range.PropertyRange(
        [("a", ">", 2), ("a", "<", 4), ("b", "=", 1)], "__main__.TestEntity")
    query = r.make_query(ns)
    results = set()
    for i in query.run():
      self.assertEquals(3, i.a)
      self.assertEquals(1, i.b)
      self.assertFalse(i.key().name() in results)
      results.add(i.key().name()) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:23,代码来源:property_range_test.py

示例6: testSplitNamespacesPresent

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def testSplitNamespacesPresent(self):
    """Test reader with multiple namespaces present."""
    testutil.TestEntity().put()
    for i in string.letters + string.digits:
      namespace_manager.set_namespace(i)
      testutil.TestEntity().put()
    namespace_manager.set_namespace(None)

    readers = input_readers.NamespaceInputReader.split_input(self.mapper_spec)
    self.assertEquals(10, len(readers))

    namespaces = set()
    for r in readers:
      namespaces.update(list(r))

    # test read
    self.assertEquals(set(list(string.letters + string.digits) + [""]),
                      namespaces) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:20,代码来源:input_readers_test.py

示例7: setUp

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def setUp(self):
    """Setup for namespaces test."""
    super(GenerateBlobKeyTestNamespace, self).setUp()
    # Set the namespace. Blobstore should ignore this.
    namespace_manager.set_namespace('abc') 
开发者ID:elsigh,项目名称:browserscope,代码行数:7,代码来源:blob_upload_test.py

示例8: setUp

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def setUp(self):
    """Setup for namespaces test."""
    super(BlobDownloadTestNamespace, self).setUp()
    # Set the namespace. Blobstore should ignore this.
    namespace_manager.set_namespace('abc') 
开发者ID:elsigh,项目名称:browserscope,代码行数:7,代码来源:blob_download_test.py

示例9: FetchAllEntitites

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def FetchAllEntitites():
  """Returns all datastore entities from all namespaces as a list."""
  ns = list(datastore.Query('__namespace__').Run())
  original_ns = namespace_manager.get_namespace()
  entities_set = []
  for namespace in ns:
    namespace_manager.set_namespace(namespace.key().name())
    kinds_list = list(datastore.Query('__kind__').Run())
    for kind_entity in kinds_list:
      ents = list(datastore.Query(kind_entity.key().name()).Run())
      for ent in ents:
        entities_set.append(ent)
  namespace_manager.set_namespace(original_ns)
  return entities_set 
开发者ID:elsigh,项目名称:browserscope,代码行数:16,代码来源:dev_appserver.py

示例10: get

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def get(self, namespace='default'):
        global_count = update_counter('counter')

        # Save the current namespace.
        previous_namespace = namespace_manager.get_namespace()
        try:
            namespace_manager.set_namespace(namespace)
            namespace_count = update_counter('counter')
        finally:
            # Restore the saved namespace.
            namespace_manager.set_namespace(previous_namespace)

        self.response.write('Global: {}, Namespace {}: {}'.format(
            global_count, namespace, namespace_count)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:16,代码来源:datastore.py

示例11: get

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def get(self, namespace='default'):
        global_count = memcache.incr('counter', initial_value=0)

        # Save the current namespace.
        previous_namespace = namespace_manager.get_namespace()
        try:
            namespace_manager.set_namespace(namespace)
            namespace_count = memcache.incr('counter', initial_value=0)
        finally:
            # Restore the saved namespace.
            namespace_manager.set_namespace(previous_namespace)

        self.response.write('Global: {}, Namespace {}: {}'.format(
            global_count, namespace, namespace_count)) 
开发者ID:GoogleCloudPlatform,项目名称:python-docs-samples,代码行数:16,代码来源:memcache.py

示例12: instance_namespace_context

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def instance_namespace_context():
  previous_namespace = namespace_manager.get_namespace()
  try:
    namespace_manager.set_namespace(INSTANCE_NAMESPACE)
    yield
  finally:
    namespace_manager.set_namespace(previous_namespace) 
开发者ID:luci,项目名称:luci-py,代码行数:9,代码来源:shared.py

示例13: get

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def get(self):
    self.version_filter = self.request.GET.get('versions', 'all')
    self.sender = self.request.GET['sender']
    self.to = self.request.GET.get('to', None)
    report_date = self.request.GET.get('date', None)
    if report_date:
      self.yesterday = datetime.date(*[int(x) for x in report_date.split('-')])
    else:
      self.yesterday = datetime.date.today() - datetime.timedelta(days=1)
    self.app_id = os.environ['APPLICATION_ID']
    version = os.environ['CURRENT_VERSION_ID']
    self.major_version, self.minor_version = version.rsplit('.', 1)
    self.minor_version = int(self.minor_version)
    self.max_results = int(self.request.GET.get('max_results',
                                                self.DEFAULT_MAX_RESULTS))
    self.debug = isTrue(self.request.GET.get('debug', 'false'))
    self.delete = isTrue(self.request.GET.get('delete', 'true'))

    namespace_manager.set_namespace('')
    try:
      exceptions = self.GetQuery(order='-minor_version').fetch(self.max_results)
    except db.NeedIndexError:

      exceptions = self.GetQuery().fetch(self.max_results)

    if exceptions:
      report = self.GenerateReport(exceptions)
      if self.debug:
        self.response.out.write(report)
      else:
        self.SendReport(report)


      if self.delete:
        db.delete(exceptions) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:37,代码来源:report_generator.py

示例14: emit

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def emit(self, record):
    """Log an error to the datastore, if applicable.

    Args:
      The logging.LogRecord object.
        See http://docs.python.org/library/logging.html#logging.LogRecord
    """
    try:
      if not record.exc_info:

        return

      signature = self.__GetSignature(record.exc_info)

      old_namespace = namespace_manager.get_namespace()
      try:
        namespace_manager.set_namespace('')


        if not memcache.add(signature, None, self.log_interval):
          return


        db.run_in_transaction_custom_retries(1, self.__EmitTx, signature,
                                             record.exc_info)
      finally:
        namespace_manager.set_namespace(old_namespace)
    except Exception:
      self.handleError(record) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:31,代码来源:ereporter.py

示例15: put_copy

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import set_namespace [as 别名]
def put_copy(self, src, dst, options):
    """Copy file from src to dst.

    Metadata is copied.

    Args:
      src: /bucket/filename. This file must exist.
      dst: /bucket/filename.
      options: a dict containing all user specified request headers.
        e.g. {'content-type': 'foo', 'x-goog-meta-bar': 'bar'}. If None,
        old metadata is copied.
    """
    common.validate_file_path(src)
    common.validate_file_path(dst)


    ns = namespace_manager.get_namespace()
    try:
      namespace_manager.set_namespace('')
      src_blobkey = self._filename_to_blobkey(src)
      source = _AE_GCSFileInfo_.get_by_key_name(src_blobkey)
      token = self._filename_to_blobkey(dst)
      new_file = _AE_GCSFileInfo_(key_name=token,
                                  filename=dst,
                                  finalized=True)
      if options:
        new_file.options = options
      else:
        new_file.options = source.options
      new_file.etag = source.etag
      new_file.size = source.size
      new_file.creation = source.creation
      new_file.put()
    finally:
      namespace_manager.set_namespace(ns)


    if src_blobkey != token:

      local_file = self.blob_storage.OpenBlob(src_blobkey)
      self.blob_storage.StoreBlob(token, local_file) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:43,代码来源:cloudstorage_stub.py


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