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


Python Bucket.from_dict方法代码示例

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


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

示例1: get_bucket

# 需要导入模块: from gcloud.storage.bucket import Bucket [as 别名]
# 或者: from gcloud.storage.bucket.Bucket import from_dict [as 别名]
  def get_bucket(self, bucket_name, *args, **kwargs):
    """Get a bucket by name.

    If the bucket isn't found,
    this will raise a :class:`gcloud.storage.exceptions.NotFoundError`.
    If you would rather get a bucket by name,
    and return ``None`` if the bucket isn't found
    (like ``{}.get('...')``)
    then use :func:`Connection.lookup`.

    For example::

      >>> from gcloud import storage
      >>> from gcloud.storage import exceptions
      >>> connection = storage.get_connection(project, email, key_path)
      >>> try:
      >>>   bucket = connection.get_bucket('my-bucket')
      >>> except exceptions.NotFoundError:
      >>>   print 'Sorry, that bucket does not exist!'

    :type bucket_name: string
    :param bucket_name: The name of the bucket to get.

    :rtype: :class:`gcloud.storage.bucket.Bucket`
    :returns: The bucket matching the name provided.
    :raises: :class:`gcloud.storage.exceptions.NotFoundError`
    """

    # TODO: URL-encode the bucket name to be safe?
    bucket = self.new_bucket(bucket_name)
    response = self.api_request(method='GET', path=bucket.path)
    return Bucket.from_dict(response, connection=self)
开发者ID:Zoramite,项目名称:gcloud-python,代码行数:34,代码来源:connection.py

示例2: get_items_from_response

# 需要导入模块: from gcloud.storage.bucket import Bucket [as 别名]
# 或者: from gcloud.storage.bucket.Bucket import from_dict [as 别名]
    def get_items_from_response(self, response):
        """Factory method which yields :class:`.Bucket` items from a response.

        :type response: dict
        :param response: The JSON API response for a page of buckets.
        """
        for item in response.get('items', []):
            yield Bucket.from_dict(item, connection=self.connection)
开发者ID:pohsiang,项目名称:gcloud-python,代码行数:10,代码来源:connection.py

示例3: create_bucket

# 需要导入模块: from gcloud.storage.bucket import Bucket [as 别名]
# 或者: from gcloud.storage.bucket.Bucket import from_dict [as 别名]
  def create_bucket(self, bucket, *args, **kwargs):
    """Create a new bucket.

    For example::

      >>> from gcloud import storage
      >>> connection = storage.get_connection(project, client, key_path)
      >>> bucket = connection.create_bucket('my-bucket')
      >>> print bucket
      <Bucket: my-bucket>

    :type bucket: string or :class:`gcloud.storage.bucket.Bucket`
    :param bucket: The bucket name (or bucket object) to create.

    :rtype: :class:`gcloud.storage.bucket.Bucket`
    :returns: The newly created bucket.
    """

    bucket = self.new_bucket(bucket)
    response = self.api_request(method='POST', path='/b',
                                data={'name': bucket.name})
    return Bucket.from_dict(response, connection=self)
开发者ID:kleyow,项目名称:gcloud-python,代码行数:24,代码来源:connection.py

示例4: create_bucket

# 需要导入模块: from gcloud.storage.bucket import Bucket [as 别名]
# 或者: from gcloud.storage.bucket.Bucket import from_dict [as 别名]
    def create_bucket(self, bucket):
        """Create a new bucket.

        For example::

          >>> from gcloud import storage
          >>> connection = storage.get_connection(project, client, key_path)
          >>> bucket = connection.create_bucket('my-bucket')
          >>> print bucket
          <Bucket: my-bucket>

        :type bucket: string or :class:`gcloud.storage.bucket.Bucket`
        :param bucket: The bucket name (or bucket object) to create.

        :rtype: :class:`gcloud.storage.bucket.Bucket`
        :returns: The newly created bucket.
        :raises: :class:`gcloud.storage.exceptions.Conflict` if
                 there is a confict (bucket already exists, invalid name, etc.)
        """
        bucket = self.new_bucket(bucket)
        response = self.api_request(method='POST', path='/b',
                                    data={'name': bucket.name})
        return Bucket.from_dict(response, connection=self)
开发者ID:gitter-badger,项目名称:gcloud-python,代码行数:25,代码来源:connection.py


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