Skip to content

Commit

Permalink
Adding Bucket.path_helper static method for external use.
Browse files Browse the repository at this point in the history
This covers callers which want a bucket path but don't want
to create a full-flegded Bucket object.

See #586 for context.
  • Loading branch information
dhermes committed Feb 3, 2015
1 parent 41223d0 commit 4fec0fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 13 additions & 1 deletion gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,25 @@ def connection(self):
"""
return self._connection

@staticmethod
def path_helper(bucket_name):
"""Relative URL path for a bucket.
:type bucket_name: string
:param bucket_name: The bucket name in the path.
:rtype: string
:returns: The relative URL path for ``bucket_name``.
"""
return '/b/' + bucket_name

@property
def path(self):
"""The URL path to this bucket."""
if not self.name:
raise ValueError('Cannot determine path without bucket name.')

return '/b/' + self.name
return self.path_helper(self.name)

def get_blob(self, blob):
"""Get a blob object by name.
Expand Down
3 changes: 1 addition & 2 deletions gcloud/storage/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from gcloud.exceptions import NotFound
from gcloud.storage.bucket import Bucket
from gcloud.storage.iterator import Iterator
import six


class Connection(_Base):
Expand Down Expand Up @@ -379,7 +378,7 @@ def delete_bucket(self, bucket_name):
:type bucket_name: string
:param bucket_name: The bucket name to delete.
"""
bucket_path = '/b/' + bucket_name
bucket_path = Bucket.path_helper(bucket_name)
self.api_request(method='DELETE', path=bucket_path)


Expand Down

0 comments on commit 4fec0fb

Please sign in to comment.