From a59fa43d3760afd113ea48983d9f2b3eab156474 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 3 Feb 2015 10:42:53 -0800 Subject: [PATCH] Adding Bucket.path_helper static method for external use. This covers callers which want a bucket path but don't want to create a full-flegded Bucket object. See #586 for context. --- gcloud/storage/bucket.py | 14 +++++++++++++- gcloud/storage/connection.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index edb0e7e4b577b..f2def041e549b 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -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. diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index 46eb40564e970..54e83d532261c 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -462,7 +462,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) def generate_signed_url(self, resource, expiration,