Ejemplo n.º 1
0
  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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
  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)
Ejemplo n.º 5
0
  def create_bucket(self, bucket, *args, **kwargs):
    # TODO: Which exceptions will this raise?
    """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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
    def create_bucket(self, bucket):
        """Create a new bucket.

        For example::

          >>> from gcloud import storage
          >>> connection = storage.get_connection(project)
          >>> 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)