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

Make Blob/Bucket reload() public and remove the public interface to _properties #770

Merged
merged 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions gcloud/storage/_helpers.py
Expand Up @@ -49,15 +49,6 @@ def __init__(self, name=None):
self._properties = {}
self._changes = set()

@property
def properties(self):
"""Return a copy of properties.

:rtype: dict
:returns: Copy of properties.
"""
return self._properties.copy()

@property
def batch(self):
"""Return a context manager which defers/batches updates.
Expand All @@ -82,7 +73,7 @@ def batch(self):
"""
return _PropertyBatch(self)

def _reload_properties(self):
def reload(self):

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

"""Reload properties from Cloud Storage.

:rtype: :class:`_PropertyMixin`
Expand Down Expand Up @@ -155,7 +146,7 @@ def _scalar_property(fieldname):
"""
def _getter(self):
"""Scalar property getter."""
return self.properties[fieldname]
return self._properties[fieldname]

def _setter(self, value):
"""Scalar property setter."""
Expand Down
2 changes: 1 addition & 1 deletion gcloud/storage/api.py
Expand Up @@ -126,7 +126,7 @@ def get_bucket(bucket_name, connection=None):
connection = get_default_connection()

bucket = Bucket(bucket_name, connection=connection)
bucket._reload_properties()
bucket.reload()
return bucket


Expand Down
28 changes: 14 additions & 14 deletions gcloud/storage/blob.py
Expand Up @@ -250,7 +250,7 @@ def download_to_filename(self, filename):

mtime = time.mktime(
datetime.datetime.strptime(
self.properties['updated'],
self._properties['updated'],
'%Y-%m-%dT%H:%M:%S.%fz').timetuple()
)
os.utime(file_obj.name, (mtime, mtime))
Expand Down Expand Up @@ -489,7 +489,7 @@ def component_count(self):

:rtype: integer
"""
return self.properties['componentCount']
return self._properties['componentCount']

@property
def etag(self):
Expand All @@ -500,7 +500,7 @@ def etag(self):

:rtype: string
"""
return self.properties['etag']
return self._properties['etag']

@property
def generation(self):
Expand All @@ -510,7 +510,7 @@ def generation(self):

:rtype: integer
"""
return self.properties['generation']
return self._properties['generation']

@property
def id(self):
Expand All @@ -520,7 +520,7 @@ def id(self):

:rtype: string
"""
return self.properties['id']
return self._properties['id']

md5_hash = _scalar_property('md5Hash')
"""MD5 hash for this object.
Expand All @@ -539,7 +539,7 @@ def media_link(self):

:rtype: string
"""
return self.properties['mediaLink']
return self._properties['mediaLink']

@property
def metadata(self):
Expand All @@ -549,7 +549,7 @@ def metadata(self):

:rtype: dict
"""
return copy.deepcopy(self.properties['metadata'])
return copy.deepcopy(self._properties['metadata'])

@metadata.setter
def metadata(self, value):
Expand All @@ -569,7 +569,7 @@ def metageneration(self):

:rtype: integer
"""
return self.properties['metageneration']
return self._properties['metageneration']

@property
def owner(self):
Expand All @@ -580,7 +580,7 @@ def owner(self):
:rtype: dict
:returns: mapping of owner's role/ID.
"""
return self.properties['owner'].copy()
return self._properties['owner'].copy()

@property
def self_link(self):
Expand All @@ -590,7 +590,7 @@ def self_link(self):

:rtype: string
"""
return self.properties['selfLink']
return self._properties['selfLink']

@property
def size(self):
Expand All @@ -600,7 +600,7 @@ def size(self):

:rtype: integer
"""
return self.properties['size']
return self._properties['size']

@property
def storage_class(self):
Expand All @@ -612,7 +612,7 @@ def storage_class(self):
:rtype: string
:returns: Currently one of "STANDARD", "DURABLE_REDUCED_AVAILABILITY"
"""
return self.properties['storageClass']
return self._properties['storageClass']

@property
def time_deleted(self):
Expand All @@ -624,7 +624,7 @@ def time_deleted(self):
:returns: timestamp in RFC 3339 format, or None if the object
has a "live" version.
"""
return self.properties.get('timeDeleted')
return self._properties.get('timeDeleted')

@property
def updated(self):
Expand All @@ -635,7 +635,7 @@ def updated(self):
:rtype: string
:returns: timestamp in RFC 3339 format.
"""
return self.properties['updated']
return self._properties['updated']


class _UploadConfig(object):
Expand Down
24 changes: 12 additions & 12 deletions gcloud/storage/bucket.py
Expand Up @@ -463,7 +463,7 @@ def cors(self):
:returns: A sequence of mappings describing each CORS policy.
"""
return [copy.deepcopy(policy)
for policy in self.properties.get('cors', ())]
for policy in self._properties.get('cors', ())]

@cors.setter
def cors(self, entries):
Expand Down Expand Up @@ -499,7 +499,7 @@ def etag(self):

:rtype: string
"""
return self.properties['etag']
return self._properties['etag']

@property
def id(self):
Expand All @@ -509,7 +509,7 @@ def id(self):

:rtype: string
"""
return self.properties['id']
return self._properties['id']

@property
def lifecycle_rules(self):
Expand Down Expand Up @@ -554,8 +554,8 @@ def get_logging(self):
:returns: a dict w/ keys, ``logBucket`` and ``logObjectPrefix``
(if logging is enabled), or None (if not).
"""
self._reload_properties()
info = self.properties.get('logging')
self.reload()
info = self._properties.get('logging')
if info is not None:
return info.copy()

Expand Down Expand Up @@ -590,7 +590,7 @@ def metageneration(self):

:rtype: integer
"""
return self.properties['metageneration']
return self._properties['metageneration']

@property
def owner(self):
Expand All @@ -601,7 +601,7 @@ def owner(self):
:rtype: dict
:returns: mapping of owner's role/ID.
"""
return self.properties['owner'].copy()
return self._properties['owner'].copy()

@property
def project_number(self):
Expand All @@ -611,7 +611,7 @@ def project_number(self):

:rtype: integer
"""
return self.properties['projectNumber']
return self._properties['projectNumber']

@property
def self_link(self):
Expand All @@ -621,7 +621,7 @@ def self_link(self):

:rtype: string
"""
return self.properties['selfLink']
return self._properties['selfLink']

@property
def storage_class(self):
Expand All @@ -633,7 +633,7 @@ def storage_class(self):
:rtype: string
:returns: Currently one of "STANDARD", "DURABLE_REDUCED_AVAILABILITY"
"""
return self.properties['storageClass']
return self._properties['storageClass']

@property
def time_created(self):
Expand All @@ -644,7 +644,7 @@ def time_created(self):
:rtype: string
:returns: timestamp in RFC 3339 format.
"""
return self.properties['timeCreated']
return self._properties['timeCreated']

@property
def versioning_enabled(self):
Expand All @@ -656,7 +656,7 @@ def versioning_enabled(self):
:rtype: boolean
:returns: True if enabled, else False.
"""
versioning = self.properties.get('versioning', {})
versioning = self._properties.get('versioning', {})
return versioning.get('enabled', False)

@versioning_enabled.setter
Expand Down
18 changes: 3 additions & 15 deletions gcloud/storage/test__helpers.py
Expand Up @@ -60,22 +60,10 @@ def test_batch(self):
self.assertEqual(kw[0]['data'], {'foo': 'Qux', 'bar': 'Baz'})
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})

def test_properties_no_fetch(self):
def test_reload(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
self.assertEqual(derived.properties, {})
derived._reload_properties()
self.assertEqual(derived.properties, {'foo': 'Foo'})
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})

def test__reload_properties(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
derived._reload_properties()
derived.reload()
self.assertEqual(derived._properties, {'foo': 'Foo'})
kw = connection._requested
self.assertEqual(len(kw), 1)
Expand Down Expand Up @@ -175,7 +163,7 @@ def test_getter(self):

class Test(object):
def __init__(self, **kw):
self.properties = kw.copy()
self._properties = kw.copy()
do_re_mi = self._callFUT('solfege')

test = Test(solfege='Latido')
Expand Down
4 changes: 2 additions & 2 deletions gcloud/storage/test_blob.py
Expand Up @@ -65,7 +65,7 @@ def test_ctor_explicit(self):
self.assertTrue(blob.bucket is bucket)
self.assertTrue(blob.connection is connection)
self.assertEqual(blob.name, BLOB_NAME)
self.assertEqual(blob.properties, properties)
self.assertEqual(blob._properties, properties)
self.assertFalse(blob._acl.loaded)
self.assertTrue(blob._acl.blob is blob)

Expand Down Expand Up @@ -294,7 +294,7 @@ def test_download_to_filename(self):
mtime = os.path.getmtime(f.name)
updatedTime = time.mktime(
datetime.datetime.strptime(
blob.properties['updated'],
blob._properties['updated'],
'%Y-%m-%dT%H:%M:%S.%fz').timetuple()
)
self.assertEqual(wrote, b'abcdef')
Expand Down
8 changes: 4 additions & 4 deletions gcloud/storage/test_bucket.py
Expand Up @@ -846,7 +846,7 @@ def test_versioning_enabled_getter_missing(self):
NAME = 'name'
connection = _Connection({})
bucket = self._makeOne(NAME, connection)
bucket._reload_properties()
bucket.reload()
self.assertEqual(bucket.versioning_enabled, False)
kw = connection._requested
self.assertEqual(len(kw), 1)
Expand Down Expand Up @@ -887,7 +887,7 @@ def test_configure_website_defaults(self):
bucket = self._makeOne(NAME, connection)
bucket.configure_website()
bucket.patch()
self.assertEqual(bucket.properties, patched)
self.assertEqual(bucket._properties, patched)
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
Expand All @@ -903,7 +903,7 @@ def test_configure_website_explicit(self):
bucket = self._makeOne(NAME, connection)
bucket.configure_website('html', '404.html')
bucket.patch()
self.assertEqual(bucket.properties, patched)
self.assertEqual(bucket._properties, patched)
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
Expand All @@ -919,7 +919,7 @@ def test_disable_website(self):
bucket = self._makeOne(NAME, connection)
bucket.disable_website()
bucket.patch()
self.assertEqual(bucket.properties, patched)
self.assertEqual(bucket._properties, patched)
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
Expand Down
2 changes: 1 addition & 1 deletion regression/storage.py
Expand Up @@ -157,7 +157,7 @@ def test_direct_write_and_read_into_file(self):
self.case_blobs_to_delete.append(blob)

same_blob = storage.Blob(bucket=self.bucket, name='MyBuffer')
same_blob._reload_properties() # Initialize properties.
same_blob.reload() # Initialize properties.
temp_filename = tempfile.mktemp()
with open(temp_filename, 'wb') as file_obj:
same_blob.download_to_file(file_obj)
Expand Down