Skip to content

Commit 44e5b74

Browse files
committed
Removing properties= from Blob() constructor.
1 parent beb14fe commit 44e5b74

File tree

6 files changed

+21
-42
lines changed

6 files changed

+21
-42
lines changed

gcloud/storage/_helpers.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,15 @@ def path(self):
3939
"""Abstract getter for the object path."""
4040
raise NotImplementedError
4141

42-
def __init__(self, name=None, properties=None):
42+
def __init__(self, name=None):
4343
"""_PropertyMixin constructor.
4444
4545
:type name: string
4646
:param name: The name of the object.
47-
48-
:type properties: dict
49-
:param properties: All the other data provided by Cloud Storage.
5047
"""
5148
self.name = name
5249
self._properties = {}
5350
self._changes = set()
54-
if properties is not None:
55-
self._properties.update(properties)
5651

5752
@property
5853
def properties(self):

gcloud/storage/blob.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,14 @@ class Blob(_PropertyMixin):
6262
# ACL rules are lazily retrieved.
6363
_acl = None
6464

65-
def __init__(self, name, bucket=None, properties=None):
66-
if name is None and properties is not None:
67-
name = properties.get('name')
68-
65+
def __init__(self, name, bucket=None):
6966
if bucket is None:
7067
bucket = _implicit_environ.get_default_bucket()
7168

7269
if bucket is None:
7370
raise ValueError('A Blob must have a bucket set.')
7471

75-
super(Blob, self).__init__(name=name, properties=properties)
72+
super(Blob, self).__init__(name=name)
7673

7774
self.bucket = bucket
7875

gcloud/storage/bucket.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def get_items_from_response(self, response):
6969
"""
7070
self.prefixes = tuple(response.get('prefixes', ()))
7171
for item in response.get('items', []):
72-
yield Blob(None, properties=item, bucket=self.bucket)
72+
name = item.get('name')
73+
blob = Blob(name, bucket=self.bucket)
74+
blob._properties = item
75+
yield blob
7376

7477

7578
class Bucket(_PropertyMixin):
@@ -188,7 +191,10 @@ def get_blob(self, blob_name):
188191
try:
189192
response = self.connection.api_request(method='GET',
190193
path=blob.path)
191-
return Blob(None, bucket=self, properties=response)
194+
name = response.get('name') # Expect this to be blob_name
195+
blob = Blob(name, bucket=self)
196+
blob._properties = response
197+
return blob
192198
except NotFound:
193199
return None
194200

gcloud/storage/iterator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class MyIterator(Iterator):
2525
def get_items_from_response(self, response):
2626
items = response.get('items', [])
2727
for item in items:
28-
yield MyItemClass(properties=item, other_arg=True)
28+
my_item = MyItemClass(other_arg=True)
29+
my_item._properties = item
30+
yield my_item
2931
3032
You then can use this to get **all** the results from a resource::
3133

gcloud/storage/test_blob.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class Test_Blob(unittest2.TestCase):
1919

2020
def _makeOne(self, *args, **kw):
2121
from gcloud.storage.blob import Blob
22-
return Blob(*args, **kw)
22+
properties = kw.pop('properties', None)
23+
blob = Blob(*args, **kw)
24+
blob._properties = properties or {}
25+
return blob
2326

2427
def test_ctor_no_bucket(self):
2528
self.assertRaises(ValueError, self._makeOne, None)
@@ -63,29 +66,6 @@ def test_ctor_explicit(self):
6366
self.assertEqual(blob.properties, properties)
6467
self.assertTrue(blob._acl is None)
6568

66-
def test_ctor_no_name_defaults(self):
67-
BLOB_NAME = 'blob-name'
68-
properties = {'key': 'value', 'name': BLOB_NAME}
69-
FAKE_BUCKET = _Bucket(None)
70-
blob = self._makeOne(None, bucket=FAKE_BUCKET, properties=properties)
71-
self.assertEqual(blob.bucket, FAKE_BUCKET)
72-
self.assertEqual(blob.connection, None)
73-
self.assertEqual(blob.name, BLOB_NAME)
74-
self.assertEqual(blob.properties, properties)
75-
self.assertTrue(blob._acl is None)
76-
77-
def test_ctor_no_name_explicit(self):
78-
BLOB_NAME = 'blob-name'
79-
connection = _Connection()
80-
bucket = _Bucket(connection)
81-
properties = {'key': 'value', 'name': BLOB_NAME}
82-
blob = self._makeOne(None, properties=properties, bucket=bucket)
83-
self.assertTrue(blob.bucket is bucket)
84-
self.assertTrue(blob.connection is connection)
85-
self.assertEqual(blob.name, BLOB_NAME)
86-
self.assertEqual(blob.properties, properties)
87-
self.assertTrue(blob._acl is None)
88-
8969
def test_acl_property(self):
9070
from gcloud.storage.acl import ObjectACL
9171
FAKE_BUCKET = _Bucket(None)
@@ -1043,8 +1023,7 @@ def __init__(self, connection):
10431023

10441024
def copy_blob(self, blob, destination_bucket, new_name):
10451025
destination_bucket._blobs[new_name] = self._blobs[blob.name]
1046-
return blob.__class__(None, bucket=destination_bucket,
1047-
properties={'name': new_name})
1026+
return blob.__class__(new_name, bucket=destination_bucket)
10481027

10491028
def delete_blob(self, blob_name):
10501029
del self._blobs[blob_name]

gcloud/storage/test_bucket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ class Test_Bucket(unittest2.TestCase):
6464

6565
def _makeOne(self, *args, **kw):
6666
from gcloud.storage.bucket import Bucket
67-
properties = kw.pop('properties', {})
67+
properties = kw.pop('properties', None)
6868
bucket = Bucket(*args, **kw)
69-
bucket._properties = properties
69+
bucket._properties = properties or {}
7070
return bucket
7171

7272
def test_ctor_defaults(self):

0 commit comments

Comments
 (0)