From 88c7a3dcab5685701f3aefa01d9884cac54e5852 Mon Sep 17 00:00:00 2001 From: olivier <> Date: Fri, 3 Apr 2009 14:55:16 +0000 Subject: [PATCH] #67: let the OAI-PMH and Dublin Core identifiers be one and the same --- telemeta/interop/oai.py | 32 ++++++++++++++++++++++---------- telemeta/interop/oaitest.py | 8 ++++++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/telemeta/interop/oai.py b/telemeta/interop/oai.py index 2c77a0d6..bea62f97 100644 --- a/telemeta/interop/oai.py +++ b/telemeta/interop/oai.py @@ -46,23 +46,25 @@ class IDataSource(object): 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): @@ -338,6 +340,12 @@ class Response(object): 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)) @@ -367,7 +375,11 @@ class Response(object): 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: diff --git a/telemeta/interop/oaitest.py b/telemeta/interop/oaitest.py index a830baa5..fcd75239 100644 --- a/telemeta/interop/oaitest.py +++ b/telemeta/interop/oaitest.py @@ -19,7 +19,10 @@ class DataSource(object): 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 @@ -36,9 +39,10 @@ class DataSource(object): 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 -- 2.39.5