Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'Bucket.connection' property #876

Merged
merged 3 commits into from
May 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions gcloud/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ def set_default_bucket(bucket=None):
"""
if bucket is None:
bucket_name = os.getenv(_BUCKET_ENV_VAR_NAME)
connection = get_default_connection()

if bucket_name is not None and connection is not None:
bucket = Bucket(bucket_name, connection=connection)
if bucket_name is not None:
bucket = Bucket(bucket_name)

if bucket is not None:
_implicit_environ._DEFAULTS.bucket = bucket
Expand Down
9 changes: 4 additions & 5 deletions gcloud/storage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def lookup_bucket(bucket_name, connection=None):
:rtype: :class:`gcloud.storage.bucket.Bucket`
:returns: The bucket matching the name provided or None if not found.
"""
connection = _require_connection(connection)
try:
return get_bucket(bucket_name, connection=connection)
except NotFound:
Expand Down Expand Up @@ -104,7 +103,6 @@ def list_buckets(project=None, max_results=None, page_token=None, prefix=None,
:rtype: iterable of :class:`gcloud.storage.bucket.Bucket` objects.
:returns: All buckets belonging to this project.
"""
connection = _require_connection(connection)
if project is None:
project = get_default_project()

This comment was marked as spam.

extra_params = {'project': project}
Expand Down Expand Up @@ -159,7 +157,7 @@ def get_bucket(bucket_name, connection=None):
:raises: :class:`gcloud.exceptions.NotFound`
"""
connection = _require_connection(connection)
bucket = Bucket(bucket_name, connection=connection)
bucket = Bucket(bucket_name)
bucket.reload(connection=connection)
return bucket

Expand Down Expand Up @@ -195,7 +193,7 @@ def create_bucket(bucket_name, project=None, connection=None):
:returns: The newly created bucket.
"""
connection = _require_connection(connection)
bucket = Bucket(bucket_name, connection=connection)
bucket = Bucket(bucket_name)
bucket.create(project, connection=connection)
return bucket

Expand All @@ -212,6 +210,7 @@ class _BucketIterator(Iterator):
"""

def __init__(self, connection, extra_params=None):
connection = _require_connection(connection)
super(_BucketIterator, self).__init__(connection=connection, path='/b',
extra_params=extra_params)

Expand All @@ -223,6 +222,6 @@ def get_items_from_response(self, response):
"""
for item in response.get('items', []):
name = item.get('name')
bucket = Bucket(name, connection=self.connection)
bucket = Bucket(name)
bucket._set_properties(item)
yield bucket
2 changes: 2 additions & 0 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def rename(self, new_name, connection=None):
:rtype: :class:`Blob`
:returns: The newly-copied blob.
"""
connection = _require_connection(connection)
new_blob = self.bucket.copy_blob(self, self.bucket, new_name,
connection=connection)
self.delete(connection=connection)
Expand All @@ -269,6 +270,7 @@ def delete(self, connection=None):
(propagated from
:meth:`gcloud.storage.bucket.Bucket.delete_blob`).
"""
connection = _require_connection(connection)
return self.bucket.delete_blob(self.name, connection=connection)

def download_to_file(self, file_obj, connection=None):
Expand Down
12 changes: 0 additions & 12 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ class Bucket(_PropertyMixin):
:type name: string
:param name: The name of the bucket.

:type connection: :class:`gcloud.storage.connection.Connection`
:param connection: The connection to use when sending requests.

:type properties: dictionary or ``NoneType``
:param properties: The properties associated with the bucket.
"""
Expand Down Expand Up @@ -196,15 +193,6 @@ def default_object_acl(self):
"""Create our defaultObjectACL on demand."""
return self._default_object_acl

@property
def connection(self):
"""Getter property for the connection to use with this Bucket.

:rtype: :class:`gcloud.storage.connection.Connection`
:returns: The connection to use.
"""
return self._connection

@staticmethod
def path_helper(bucket_name):
"""Relative URL path for a bucket.
Expand Down
2 changes: 0 additions & 2 deletions gcloud/storage/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def test_set_from_env_var(self):

default_bucket = _implicit_environ.get_default_bucket()
self.assertEqual(default_bucket.name, IMPLICIT_BUCKET_NAME)
self.assertEqual(default_bucket.connection, CONNECTION)

def test_set_explicit_w_env_var_set(self):
from gcloud.storage._testing import _monkey_defaults
Expand Down Expand Up @@ -113,7 +112,6 @@ def test_set_explicit_None_w_env_var_set(self):

default_bucket = _implicit_environ.get_default_bucket()
self.assertEqual(default_bucket.name, IMPLICIT_BUCKET_NAME)
self.assertEqual(default_bucket.connection, CONNECTION)


class Test_set_defaults(unittest2.TestCase):
Expand Down
5 changes: 0 additions & 5 deletions gcloud/storage/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def _lookup_bucket_hit_helper(self, use_default=False):
bucket = self._callFUT(BLOB_NAME, connection=conn)

self.assertTrue(isinstance(bucket, Bucket))
self.assertTrue(bucket.connection is conn)
self.assertEqual(bucket.name, BLOB_NAME)
self.assertEqual(http._called_with['method'], 'GET')
self.assertEqual(http._called_with['uri'], URI)
Expand Down Expand Up @@ -256,7 +255,6 @@ def _get_bucket_hit_helper(self, use_default=False):
bucket = self._callFUT(BLOB_NAME, connection=conn)

self.assertTrue(isinstance(bucket, Bucket))
self.assertTrue(bucket.connection is conn)
self.assertEqual(bucket.name, BLOB_NAME)
self.assertEqual(http._called_with['method'], 'GET')
self.assertEqual(http._called_with['uri'], URI)
Expand Down Expand Up @@ -301,7 +299,6 @@ def _create_bucket_success_helper(self, project, use_default=False):
bucket = self._callFUT(BLOB_NAME, project=project, connection=conn)

self.assertTrue(isinstance(bucket, Bucket))
self.assertTrue(bucket.connection is conn)
self.assertEqual(bucket.name, BLOB_NAME)
self.assertEqual(http._called_with['method'], 'POST')
self.assertEqual(http._called_with['uri'], URI)
Expand All @@ -325,7 +322,6 @@ def _makeOne(self, *args, **kw):
def test_ctor(self):
connection = object()
iterator = self._makeOne(connection)
self.assertTrue(iterator.connection is connection)
self.assertEqual(iterator.path, '/b')
self.assertEqual(iterator.page_number, 0)
self.assertEqual(iterator.next_page_token, None)
Expand All @@ -345,7 +341,6 @@ def test_get_items_from_response_non_empty(self):
self.assertEqual(len(buckets), 1)
bucket = buckets[0]
self.assertTrue(isinstance(bucket, Bucket))
self.assertTrue(bucket.connection is connection)
self.assertEqual(bucket.name, BLOB_NAME)


Expand Down
Loading