Change so that Resource.datetime is implemented over ts_datetime timestamp like other timestamps

This commit is contained in:
Simeon Warner 2020-12-13 16:52:43 -05:00
parent 9a789d1b75
commit 1685107039

View File

@ -34,6 +34,7 @@ class Resource(object):
mime_type - MIME type
md5, sha1, sha256 - digests, have hash accessor
change - change type
ts_datetime - time of the change, has datetime accessor
path - path in dump
If non-core attributes are needed then the '_extra' attribute
@ -56,15 +57,15 @@ class Resource(object):
"""
__slots__ = ('uri', 'timestamp', 'length', 'mime_type',
'md5', 'sha1', 'sha256', 'change', 'datetime',
'md5', 'sha1', 'sha256', 'change', 'ts_datetime',
'path', '_extra', 'ln')
CHANGE_TYPES = ['created', 'updated', 'deleted']
def __init__(self, uri=None, timestamp=None, length=None,
md5=None, sha1=None, sha256=None, mime_type=None,
change=None, datetime=None, path=None, lastmod=None,
capability=None,
change=None, ts_datetime=None, datetime=None, path=None,
lastmod=None, capability=None,
ts_at=None, md_at=None,
ts_completed=None, md_completed=None,
ts_from=None, md_from=None,
@ -85,14 +86,14 @@ class Resource(object):
self.sha1 = None
self.sha256 = None
self.change = None
self.datetime = None # Added in ResourceSync v1.1
self.ts_datetime = None # Added in ResourceSync v1.1
self.path = None
self._extra = None
self.ln = None
# Create from a Resource-like object? Copy any relevant attributes
if (resource is not None):
for att in ['uri', 'timestamp', 'length', 'md5', 'sha1', 'sha256',
'change', 'datetime', 'path', 'capability',
'change', 'ts_datetime', 'path', 'capability',
'ts_at', 'md_at', 'ts_completed', 'md_completed',
'ts_from', 'md_from', 'ts_until', 'md_until', 'ln']:
if hasattr(resource, att):
@ -114,8 +115,8 @@ class Resource(object):
self.mime_type = mime_type
if (change is not None):
self.change = change
if (datetime is not None):
self.datetime = datetime
if (ts_datetime is not None):
self.ts_datetime = ts_datetime
if (path is not None):
self.path = path
if (ts_at is not None):
@ -133,6 +134,8 @@ class Resource(object):
# Timestamp setters
if (lastmod is not None):
self.lastmod = lastmod
if (datetime is not None):
self.datetime = datetime
if (md_at is not None):
self.md_at = md_at
if (md_completed is not None):
@ -178,14 +181,24 @@ class Resource(object):
@property
def lastmod(self):
"""The Last-Modified data in W3C Datetime syntax, Z notation."""
"""The Last-Modified date for the resource in W3C Datetime syntax, Z notation."""
return datetime_to_str(self.timestamp)
@lastmod.setter
def lastmod(self, lastmod):
"""Set timestamp from a W3C Datetime Last-Modified value."""
"""Set last modified timestamp from a W3C Datetime Last-Modified value."""
self.timestamp = str_to_datetime(lastmod, context='lastmod')
@property
def datetime(self):
"""The datetime of the resource change in W3C Datetime syntax, Z notation."""
return datetime_to_str(self.ts_datetime)
@datetime.setter
def datetime(self, datetime):
"""Set timestamp from a W3C Datetime Last-Modified value."""
self.ts_datetime = str_to_datetime(datetime, context='ts_datetime')
@property
def md_at(self):
"""md_at values in W3C Datetime syntax, Z notation."""