Skip to content

Commit

Permalink
Removing _PropertyMixin.properties public property.
Browse files Browse the repository at this point in the history
The blob/bucket metadata was never actually accessed via
the public properties `properties`.
  • Loading branch information
dhermes committed Mar 28, 2015
1 parent 027bfdf commit 87b9bf3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 54 deletions.
11 changes: 1 addition & 10 deletions gcloud/storage/_helpers.py
Original file line number Diff line number Diff line change
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 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
28 changes: 14 additions & 14 deletions gcloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,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 @@ -492,7 +492,7 @@ def component_count(self):
:rtype: integer
"""
return self.properties['componentCount']
return self._properties['componentCount']

@property
def etag(self):
Expand All @@ -503,7 +503,7 @@ def etag(self):
:rtype: string
"""
return self.properties['etag']
return self._properties['etag']

@property
def generation(self):
Expand All @@ -513,7 +513,7 @@ def generation(self):
:rtype: integer
"""
return self.properties['generation']
return self._properties['generation']

@property
def id(self):
Expand All @@ -523,7 +523,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 @@ -542,7 +542,7 @@ def media_link(self):
:rtype: string
"""
return self.properties['mediaLink']
return self._properties['mediaLink']

@property
def metadata(self):
Expand All @@ -552,7 +552,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 @@ -572,7 +572,7 @@ def metageneration(self):
:rtype: integer
"""
return self.properties['metageneration']
return self._properties['metageneration']

@property
def owner(self):
Expand All @@ -583,7 +583,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 @@ -593,7 +593,7 @@ def self_link(self):
:rtype: string
"""
return self.properties['selfLink']
return self._properties['selfLink']

@property
def size(self):
Expand All @@ -603,7 +603,7 @@ def size(self):
:rtype: integer
"""
return self.properties['size']
return self._properties['size']

@property
def storage_class(self):
Expand All @@ -615,7 +615,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 @@ -627,7 +627,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 @@ -638,7 +638,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
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def get_cors(self):
:rtype: list(dict)
:returns: A sequence of mappings describing each CORS policy.
"""
return [policy.copy() for policy in self.properties.get('cors', ())]
return [policy.copy() for policy in self._properties.get('cors', ())]

def update_cors(self, entries):
"""Update CORS policies configured for this bucket.
Expand Down Expand Up @@ -501,7 +501,7 @@ def etag(self):
:rtype: string
"""
return self.properties['etag']
return self._properties['etag']

@property
def id(self):
Expand All @@ -511,7 +511,7 @@ def id(self):
:rtype: string
"""
return self.properties['id']
return self._properties['id']

def get_lifecycle(self):
"""Retrieve lifecycle rules configured for this bucket.
Expand All @@ -522,7 +522,7 @@ def get_lifecycle(self):
:rtype: list(dict)
:returns: A sequence of mappings describing each lifecycle rule.
"""
info = self.properties.get('lifecycle', {})
info = self._properties.get('lifecycle', {})
return [rule.copy() for rule in info.get('rule', ())]

def update_lifecycle(self, rules):
Expand Down Expand Up @@ -556,7 +556,7 @@ def get_logging(self):
(if logging is enabled), or None (if not).
"""
self.reload()
info = self.properties.get('logging')
info = self._properties.get('logging')
if info is not None:
return info.copy()

Expand Down Expand Up @@ -591,7 +591,7 @@ def metageneration(self):
:rtype: integer
"""
return self.properties['metageneration']
return self._properties['metageneration']

@property
def owner(self):
Expand All @@ -602,7 +602,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 @@ -612,7 +612,7 @@ def project_number(self):
:rtype: integer
"""
return self.properties['projectNumber']
return self._properties['projectNumber']

@property
def self_link(self):
Expand All @@ -622,7 +622,7 @@ def self_link(self):
:rtype: string
"""
return self.properties['selfLink']
return self._properties['selfLink']

@property
def storage_class(self):
Expand All @@ -634,7 +634,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 @@ -645,7 +645,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 @@ -657,7 +657,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
14 changes: 1 addition & 13 deletions gcloud/storage/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ 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):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
self.assertEqual(derived.properties, {})
derived.reload()
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(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,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.assertTrue(blob._acl is None)

def test_acl_property(self):
Expand Down Expand Up @@ -291,7 +291,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
6 changes: 3 additions & 3 deletions gcloud/storage/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def test_configure_website_defaults(self):
connection = _Connection(patched)
bucket = self._makeOne(NAME, connection)
self.assertTrue(bucket.configure_website() is bucket)
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 @@ -948,7 +948,7 @@ def test_configure_website_explicit(self):
connection = _Connection(patched)
bucket = self._makeOne(NAME, connection)
self.assertTrue(bucket.configure_website('html', '404.html') is bucket)
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 @@ -963,7 +963,7 @@ def test_disable_website(self):
connection = _Connection(patched)
bucket = self._makeOne(NAME, connection)
self.assertTrue(bucket.disable_website() is bucket)
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

0 comments on commit 87b9bf3

Please sign in to comment.