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


Python namespace_manager.get_namespace方法代码示例

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


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

示例1: run_taskqueue_tasks

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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 get_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: ResolveNamespace

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_namespace [as 别名]
def ResolveNamespace(namespace):
  """Validate app namespace, providing a default.

  If the argument is None, namespace_manager.get_namespace() is substituted.

  Args:
    namespace: The namespace argument value to be validated.

  Returns:
    The value of namespace, or the substituted default. The empty string is used
    to denote the empty namespace.

  Raises:
    BadArgumentError if the value is not a string.
  """
  if namespace is None:
    namespace = namespace_manager.get_namespace()
  else:
    namespace_manager.validate_namespace(
        namespace, datastore_errors.BadArgumentError)
  return namespace 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:23,代码来源:datastore_types.py

示例4: put_empty

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例5: GetCurrentUsername

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_namespace [as 别名]
def GetCurrentUsername():
  """Returns the username of the signed in user, if any.

  If the email address of the signed in user belongs to a domain other than the
  current request's namespace, returns the entire email address instead to avoid
  confusion.  (We don't want to raise an exception since those get swallowed
  when rendering templates, which is where this function is most likely to be
  used.)

  Returns:
    The username or email address of the currently signed in user, or an empty
    string if no one is signed in.
  """
  user = users.get_current_user()
  if not user: return ''
  username, domain = user.email().split('@', 1)
  if domain == namespace_manager.get_namespace():
    return username
  return user.email() 
开发者ID:google,项目名称:upvote,代码行数:21,代码来源:context.py

示例6: FetchAllEntitites

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例7: get

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例8: get

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例9: instance_namespace_context

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例10: render_by_namespace

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_namespace [as 别名]
def render_by_namespace(template_path, context={}):
    ns = get_namespace()
    if not ns:
        return template.render(template_path, context)

    try:
        return template.render('/'.join([ns, template_path]), context)
    except TemplateNotFound:
        return template.render(template_path, context) 
开发者ID:renzon,项目名称:tekton,代码行数:11,代码来源:template_middleware.py

示例11: __init__

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_namespace [as 别名]
def __init__(self, name, namespace=None, source=SEARCH):
    """Initializer.

    Args:
      name: The name of the index. An index name must be a visible printable
        ASCII string not starting with '!'. Whitespace characters are excluded.
      namespace: The namespace of the index name. If not set, then the current
        namespace is used.
      source: Deprecated as of 1.7.6. The source of
        the index:
          SEARCH - The Index was created by adding documents throught this
            search API.
          DATASTORE - The Index was created as a side-effect of putting entities
            into Datastore.
          CLOUD_STORAGE - The Index was created as a side-effect of adding
            objects into a Cloud Storage bucket.
    Raises:
      TypeError: If an unknown attribute is passed.
      ValueError: If invalid namespace is given.
    """
    if source not in self._SOURCES:
      raise ValueError('source must be one of %s' % self._SOURCES)
    if source is not self.SEARCH:
      warnings.warn('source is deprecated.', DeprecationWarning, stacklevel=2)
    self._source = source
    self._name = _CheckIndexName(_ConvertToUnicode(name))
    self._namespace = _ConvertToUnicode(namespace)
    if self._namespace is None:
      self._namespace = _ConvertToUnicode(namespace_manager.get_namespace())
    if self._namespace is None:
      self._namespace = u''
    namespace_manager.validate_namespace(self._namespace, exception=ValueError)
    self._schema = None
    self._storage_usage = None
    self._storage_limit = None 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:37,代码来源:search.py

示例12: _add_name_space

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_namespace [as 别名]
def _add_name_space(message, namespace=None):
  """Populate the name_space field in a messagecol buffer.

  Args:
    message: A messagecol buffer supporting the set_name_space() operation.
    namespace: The name of the namespace part. If None, use the
      default namespace. The empty namespace (i.e. '') will clear
      the name_space field.
  """
  if namespace is None:
    namespace = namespace_manager.get_namespace()
  if not namespace:
    message.clear_name_space()
  else:
    message.set_name_space(namespace) 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:17,代码来源:__init__.py

示例13: emit

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例14: put_copy

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_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

示例15: create_entities_in_multiple_ns

# 需要导入模块: from google.appengine.api import namespace_manager [as 别名]
# 或者: from google.appengine.api.namespace_manager import get_namespace [as 别名]
def create_entities_in_multiple_ns(self, names):
    ns = namespace_manager.get_namespace()
    for name in names:
      namespace_manager.set_namespace(name)
      TestEntity().put()
    namespace_manager.set_namespace(ns) 
开发者ID:GoogleCloudPlatform,项目名称:appengine-mapreduce,代码行数:8,代码来源:key_ranges_test.py


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