Skip to content

Commit

Permalink
Merge pull request #771 from dhermes/fix-752
Browse files Browse the repository at this point in the history
Ditching lazy loading for ACLs attached to Blob/Bucket.
  • Loading branch information
dhermes committed Mar 30, 2015
2 parents f65f7c7 + 935c612 commit 4e64267
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
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):
Expand Down
9 changes: 2 additions & 7 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,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 @@ -129,15 +128,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

0 comments on commit 4e64267

Please sign in to comment.