本文整理汇总了Python中gcloud.storage.bucket.Bucket类的典型用法代码示例。如果您正苦于以下问题:Python Bucket类的具体用法?Python Bucket怎么用?Python Bucket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bucket类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_bucket
def get_bucket(bucket_name, connection=None):
"""Get a bucket by name.
If the bucket isn't found, this will raise a
:class:`gcloud.storage.exceptions.NotFound`.
For example::
>>> from gcloud import storage
>>> from gcloud.exceptions import NotFound
>>> try:
>>> bucket = storage.get_bucket('my-bucket')
>>> except NotFound:
>>> print 'Sorry, that bucket does not exist!'
This implements "storage.buckets.get".
:type bucket_name: string
:param bucket_name: The name of the bucket to get.
:type connection: :class:`gcloud.storage.connection.Connection` or
``NoneType``
:param connection: Optional. The connection to use when sending requests.
If not provided, falls back to default.
:rtype: :class:`gcloud.storage.bucket.Bucket`
:returns: The bucket matching the name provided.
:raises: :class:`gcloud.exceptions.NotFound`
"""
connection = _require_connection(connection)
bucket = Bucket(bucket_name, connection=connection)
bucket.reload()
return bucket
示例2: create_bucket
def create_bucket(bucket_name, project=None, connection=None):
"""Create a new bucket.
For example::
>>> from gcloud import storage
>>> storage.set_defaults()
>>> bucket = storage.create_bucket('my-bucket')
>>> print bucket
<Bucket: my-bucket>
This implements "storage.buckets.insert".
If the bucket already exists, will raise
:class:`gcloud.exceptions.Conflict`.
:type project: string
:param project: Optional. The project to use when creating bucket.
If not provided, falls back to default.
:type bucket_name: string
:param bucket_name: The bucket name to create.
:type connection: :class:`gcloud.storage.connection.Connection` or
``NoneType``
:param connection: Optional. The connection to use when sending requests.
If not provided, falls back to default.
:rtype: :class:`gcloud.storage.bucket.Bucket`
:returns: The newly created bucket.
"""
connection = _require_connection(connection)
bucket = Bucket(bucket_name, connection=connection)
bucket.create(project)
return bucket
示例3: get_bucket
def get_bucket(self, bucket_name):
"""Get a bucket by name.
If the bucket isn't found, this will raise a
:class:`gcloud.storage.exceptions.NotFound`.
For example::
>>> try:
>>> bucket = client.get_bucket('my-bucket')
>>> except gcloud.exceptions.NotFound:
>>> print 'Sorry, that bucket does not exist!'
This implements "storage.buckets.get".
: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.exceptions.NotFound`
"""
bucket = Bucket(self, name=bucket_name)
bucket.reload(client=self)
return bucket
示例4: _makeOne
def _makeOne(self, client=None, name=None, properties=None):
from gcloud.storage.bucket import Bucket
if client is None:
connection = _Connection()
client = _Client(connection)
bucket = Bucket(client, name=name)
bucket._properties = properties or {}
return bucket
示例5: get_items_from_response
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', []):
name = item.get('name')
bucket = Bucket(name, connection=self.connection)
bucket._properties = item
yield bucket
示例6: get_bucket
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)
示例7: delete_bucket
def delete_bucket(self, bucket_name):
"""Delete a bucket.
You can use this method to delete a bucket by name.
>>> from gcloud import storage
>>> connection = storage.get_connection(project)
>>> connection.delete_bucket('my-bucket')
If the bucket doesn't exist, this will raise a
:class:`gcloud.exceptions.NotFound`::
>>> from gcloud.exceptions import NotFound
>>> try:
>>> connection.delete_bucket('my-bucket')
>>> except NotFound:
>>> print 'That bucket does not exist!'
If the bucket still has objects in it, this will raise a
:class:`gcloud.exceptions.Conflict`::
>>> from gcloud.exceptions import Conflict
>>> try:
>>> connection.delete_bucket('my-bucket')
>>> except Conflict:
>>> print 'That bucket is not empty!'
This implements "storage.buckets.delete".
:type bucket_name: string
:param bucket_name: The bucket name to delete.
"""
bucket_path = Bucket.path_helper(bucket_name)
self.api_request(method='DELETE', path=bucket_path)
示例8: get_items_from_response
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)
示例9: create_bucket
def create_bucket(self, bucket_name):
"""Create a new bucket.
For example::
>>> bucket = client.create_bucket('my-bucket')
>>> print bucket
<Bucket: my-bucket>
This implements "storage.buckets.insert".
If the bucket already exists, will raise
:class:`gcloud.exceptions.Conflict`.
:type bucket_name: string
:param bucket_name: The bucket name to create.
:rtype: :class:`gcloud.storage.bucket.Bucket`
:returns: The newly created bucket.
"""
bucket = Bucket(self, name=bucket_name)
bucket.create(client=self)
return bucket
示例10: create_bucket
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)
示例11: create_bucket
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)
示例12: _makeOne
def _makeOne(self, *args, **kw):
from gcloud.storage.bucket import Bucket
properties = kw.pop('properties', None)
bucket = Bucket(*args, **kw)
bucket._properties = properties or {}
return bucket