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

Ditching lazy loading for ACLs attached to Blob/Bucket. #771

Merged
merged 1 commit into from
Mar 30, 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: 1 addition & 4 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class Blob(_PropertyMixin):

This must be a multiple of 256 KB per the API specification.
"""
# ACL rules are lazily retrieved.
_acl = None

def __init__(self, name, bucket=None):
if bucket is None:
Expand All @@ -72,6 +70,7 @@ def __init__(self, name, bucket=None):
super(Blob, self).__init__(name=name)

self.bucket = bucket
self._acl = ObjectACL(self)

@staticmethod
def path_helper(bucket_path, blob_name):
Expand All @@ -91,8 +90,6 @@ def path_helper(bucket_path, blob_name):
@property
def acl(self):
"""Create our ACL on demand."""
if self._acl is None:
self._acl = ObjectACL(self)
return self._acl

def __repr__(self):

This comment was marked as spam.

This comment was marked as spam.

Expand Down
9 changes: 2 additions & 7 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ class Bucket(_PropertyMixin):
_MAX_OBJECTS_FOR_BUCKET_DELETE = 256
"""Maximum number of existing objects allowed in Bucket.delete()."""

# ACL rules are lazily retrieved.
_acl = _default_object_acl = None

def __init__(self, name=None, connection=None):
super(Bucket, self).__init__(name=name)
self._connection = connection
self._acl = BucketACL(self)
self._default_object_acl = DefaultObjectACL(self)

def __repr__(self):
return '<Bucket: %s>' % self.name
Expand Down Expand Up @@ -128,15 +127,11 @@ def exists(self):
@property
def acl(self):
"""Create our ACL on demand."""
if self._acl is None:
self._acl = BucketACL(self)
return self._acl

@property
def default_object_acl(self):
"""Create our defaultObjectACL on demand."""
if self._default_object_acl is None:
self._default_object_acl = DefaultObjectACL(self)
return self._default_object_acl

@property
Expand Down
9 changes: 6 additions & 3 deletions gcloud/storage/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def mock_get_bucket():
self.assertEqual(blob.connection, None)
self.assertEqual(blob.name, None)
self.assertEqual(blob._properties, {})
self.assertTrue(blob._acl is None)
self.assertFalse(blob._acl.loaded)
self.assertTrue(blob._acl.blob is blob)

def test_ctor_defaults(self):
FAKE_BUCKET = _Bucket(None)
Expand All @@ -52,7 +53,8 @@ def test_ctor_defaults(self):
self.assertEqual(blob.connection, None)
self.assertEqual(blob.name, None)
self.assertEqual(blob._properties, {})
self.assertTrue(blob._acl is None)
self.assertFalse(blob._acl.loaded)
self.assertTrue(blob._acl.blob is blob)

def test_ctor_explicit(self):
BLOB_NAME = 'blob-name'
Expand All @@ -64,7 +66,8 @@ def test_ctor_explicit(self):
self.assertTrue(blob.connection is connection)
self.assertEqual(blob.name, BLOB_NAME)
self.assertEqual(blob.properties, properties)
self.assertTrue(blob._acl is None)
self.assertFalse(blob._acl.loaded)
self.assertTrue(blob._acl.blob is blob)

def test_acl_property(self):
from gcloud.storage.acl import ObjectACL
Expand Down
12 changes: 8 additions & 4 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def test_ctor_defaults(self):
self.assertEqual(bucket.connection, None)
self.assertEqual(bucket.name, None)
self.assertEqual(bucket._properties, {})
self.assertTrue(bucket._acl is None)
self.assertTrue(bucket._default_object_acl is None)
self.assertFalse(bucket._acl.loaded)
self.assertTrue(bucket._acl.bucket is bucket)
self.assertFalse(bucket._default_object_acl.loaded)
self.assertTrue(bucket._default_object_acl.bucket is bucket)

def test_ctor_explicit(self):
NAME = 'name'
Expand All @@ -85,8 +87,10 @@ def test_ctor_explicit(self):
self.assertTrue(bucket.connection is connection)
self.assertEqual(bucket.name, NAME)
self.assertEqual(bucket._properties, properties)
self.assertTrue(bucket._acl is None)
self.assertTrue(bucket._default_object_acl is None)
self.assertFalse(bucket._acl.loaded)
self.assertTrue(bucket._acl.bucket is bucket)
self.assertFalse(bucket._default_object_acl.loaded)
self.assertTrue(bucket._default_object_acl.bucket is bucket)

def test___iter___empty(self):
NAME = 'name'
Expand Down