pass
def get_record(self, id):
- """Must return a tuple with :
- - record as (dict,timestamp) of Dublin Core elements
- - last changetime as a datetime object
- or None if the record doesn't exist"""
+ """Must return a tuple of the form (dublin core dict, change time)
+ or None if the record doesn't exist.
+
+ The dublin core data must contain an 'identifier' element, which is the same
+ as the id parameter."""
pass
def count_records(self, from_time = None, until_time = None):
- """Must return the number of record identifiers between (optional) from and
- until change time."""
+ """Must return the number of records between (optional) from and until change time."""
pass
def list_records(self, offset, limit, from_time = None, until_time = None):
"""Must return the list of records between (optional) from and
until change time, starting from record at offset, with a maximum of limit
- entries. Each entry of the list must be a tuple containing the identifier, a dict
- containing dublin core data, and the change time. If no record matches, should return
- an empty list."""
+ entries. Each entry of the list must be a tuple of the form:
+ (dublin core dict, change time)
+
+ If no record matches, should return an empty list. The dublin core data must
+ contain an 'identifier' element, which can be used as a parameter to get_record()."""
pass
def iso_time(date_time = None):
self.error('idDoesNotExist')
else:
dc, ctime = record
+ if not dc.get('identifier'):
+ raise Exception("DataSource.get_record() didn't provide an 'identifier' dublin core element")
+ elif dc["identifier"] != id:
+ raise Exception("DataSource.get_record() returned an 'identifier' dublin core element "
+ "which is different from the requested identifier")
+
self.set_attributes(self.request, {'identifier': id, 'metadataPrefix': 'oai_dc'})
container = self.root.appendChild(self.doc.createElement(self.verb))
container.appendChild(self.make_record(id, dc, ctime))
if len(data):
container = self.root.appendChild(self.doc.createElement(self.verb))
for item in data:
- id, dc, ctime = item
+ dc, ctime = item
+ if not dc.get('identifier'):
+ raise Exception("DataSource.list_records() didn't provide an 'identifier' dublin core element")
+
+ id = dc['identifier']
if ids_only:
container.appendChild(self.make_record_header(id, ctime))
else:
return self.oldest
def get_record(self, id):
- return self.data.get(id)
+ record = self.data.get(id)
+ if record:
+ record['identifier'] = id
+ return record
def count_records(self, from_time = None, until_time = None):
result = 0
n = 0
for k in self.data:
dc, ctime = self.data[k]
+ dc['identifier'] = k
if ((not from_time) or ctime >= from_time) and ((not until_time) or ctime <= until_time):
if (i >= offset) and (n < limit):
- result.append((k, dc, ctime))
+ result.append((dc, ctime))
n += 1
i += 1
return result