Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Removing properties= from Blob() constructor.
  • Loading branch information
dhermes committed Mar 28, 2015
commit 44e5b74022c9735cc890164d1d0afd63dfacd8b7
7 changes: 1 addition & 6 deletions gcloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,15 @@ def path(self):
"""Abstract getter for the object path."""
raise NotImplementedError

def __init__(self, name=None, properties=None):
def __init__(self, name=None):
"""_PropertyMixin constructor.

:type name: string
:param name: The name of the object.

:type properties: dict
:param properties: All the other data provided by Cloud Storage.
"""
self.name = name
self._properties = {}
self._changes = set()
if properties is not None:
self._properties.update(properties)

@property
def properties(self):
Expand Down
7 changes: 2 additions & 5 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,14 @@ class Blob(_PropertyMixin):
# ACL rules are lazily retrieved.
_acl = None

def __init__(self, name, bucket=None, properties=None):
if name is None and properties is not None:
name = properties.get('name')

def __init__(self, name, bucket=None):
if bucket is None:
bucket = _implicit_environ.get_default_bucket()

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

super(Blob, self).__init__(name=name, properties=properties)
super(Blob, self).__init__(name=name)

self.bucket = bucket

Expand Down
10 changes: 8 additions & 2 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def get_items_from_response(self, response):
"""
self.prefixes = tuple(response.get('prefixes', ()))
for item in response.get('items', []):
yield Blob(None, properties=item, bucket=self.bucket)
name = item.get('name')
blob = Blob(name, bucket=self.bucket)
blob._properties = item
yield blob


class Bucket(_PropertyMixin):
Expand Down Expand Up @@ -188,7 +191,10 @@ def get_blob(self, blob_name):
try:
response = self.connection.api_request(method='GET',
path=blob.path)
return Blob(None, bucket=self, properties=response)
name = response.get('name') # Expect this to be blob_name
blob = Blob(name, bucket=self)
blob._properties = response
return blob
except NotFound:
return None

Expand Down
4 changes: 3 additions & 1 deletion gcloud/storage/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class MyIterator(Iterator):
def get_items_from_response(self, response):
items = response.get('items', [])
for item in items:
yield MyItemClass(properties=item, other_arg=True)
my_item = MyItemClass(other_arg=True)
my_item._properties = item
yield my_item

You then can use this to get **all** the results from a resource::

Expand Down
31 changes: 5 additions & 26 deletions gcloud/storage/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Test_Blob(unittest2.TestCase):

def _makeOne(self, *args, **kw):
from gcloud.storage.blob import Blob
return Blob(*args, **kw)
properties = kw.pop('properties', None)
blob = Blob(*args, **kw)
blob._properties = properties or {}
return blob

def test_ctor_no_bucket(self):
self.assertRaises(ValueError, self._makeOne, None)
Expand Down Expand Up @@ -63,29 +66,6 @@ def test_ctor_explicit(self):
self.assertEqual(blob.properties, properties)
self.assertTrue(blob._acl is None)

def test_ctor_no_name_defaults(self):
BLOB_NAME = 'blob-name'
properties = {'key': 'value', 'name': BLOB_NAME}
FAKE_BUCKET = _Bucket(None)
blob = self._makeOne(None, bucket=FAKE_BUCKET, properties=properties)
self.assertEqual(blob.bucket, FAKE_BUCKET)
self.assertEqual(blob.connection, None)
self.assertEqual(blob.name, BLOB_NAME)
self.assertEqual(blob.properties, properties)
self.assertTrue(blob._acl is None)

def test_ctor_no_name_explicit(self):
BLOB_NAME = 'blob-name'
connection = _Connection()
bucket = _Bucket(connection)
properties = {'key': 'value', 'name': BLOB_NAME}
blob = self._makeOne(None, properties=properties, bucket=bucket)
self.assertTrue(blob.bucket is bucket)
self.assertTrue(blob.connection is connection)
self.assertEqual(blob.name, BLOB_NAME)
self.assertEqual(blob.properties, properties)
self.assertTrue(blob._acl is None)

def test_acl_property(self):
from gcloud.storage.acl import ObjectACL
FAKE_BUCKET = _Bucket(None)
Expand Down Expand Up @@ -1043,8 +1023,7 @@ def __init__(self, connection):

def copy_blob(self, blob, destination_bucket, new_name):
destination_bucket._blobs[new_name] = self._blobs[blob.name]
return blob.__class__(None, bucket=destination_bucket,
properties={'name': new_name})
return blob.__class__(new_name, bucket=destination_bucket)

def delete_blob(self, blob_name):
del self._blobs[blob_name]
Expand Down
4 changes: 2 additions & 2 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class Test_Bucket(unittest2.TestCase):

def _makeOne(self, *args, **kw):
from gcloud.storage.bucket import Bucket
properties = kw.pop('properties', {})
properties = kw.pop('properties', None)
bucket = Bucket(*args, **kw)
bucket._properties = properties
bucket._properties = properties or {}
return bucket

def test_ctor_defaults(self):
Expand Down