From 935c6128cca3e3a3dcfc311440d54693cd5fbec0 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Sat, 28 Mar 2015 14:14:38 -0700 Subject: [PATCH] Ditching lazy loading for ACLs attached to Blob/Bucket. Fixes #752. --- gcloud/storage/blob.py | 5 +---- gcloud/storage/bucket.py | 9 ++------- gcloud/storage/test_blob.py | 9 ++++++--- gcloud/storage/test_bucket.py | 12 ++++++++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/gcloud/storage/blob.py b/gcloud/storage/blob.py index e1ae7a41d5a2..ed8491474a5f 100644 --- a/gcloud/storage/blob.py +++ b/gcloud/storage/blob.py @@ -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: @@ -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): @@ -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): diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index 0200d766d126..fe12cd8c3dfd 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -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 '' % self.name @@ -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 diff --git a/gcloud/storage/test_blob.py b/gcloud/storage/test_blob.py index 3fafb8cd790c..a9f05119c06e 100644 --- a/gcloud/storage/test_blob.py +++ b/gcloud/storage/test_blob.py @@ -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) @@ -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' @@ -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 diff --git a/gcloud/storage/test_bucket.py b/gcloud/storage/test_bucket.py index 081344598825..a8a76e3d043e 100644 --- a/gcloud/storage/test_bucket.py +++ b/gcloud/storage/test_bucket.py @@ -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' @@ -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'