當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。