本文整理汇总了Python中oaipmh.metadata.MetadataRegistry.hasWriter方法的典型用法代码示例。如果您正苦于以下问题:Python MetadataRegistry.hasWriter方法的具体用法?Python MetadataRegistry.hasWriter怎么用?Python MetadataRegistry.hasWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oaipmh.metadata.MetadataRegistry
的用法示例。
在下文中一共展示了MetadataRegistry.hasWriter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cheshire3OaiServer
# 需要导入模块: from oaipmh.metadata import MetadataRegistry [as 别名]
# 或者: from oaipmh.metadata.MetadataRegistry import hasWriter [as 别名]
class Cheshire3OaiServer(object):
"""A server object complying with the oaipmh module's API."""
protocolMap = None
db = None
def __init__(self, session, configs, dbs, dbName):
self.session = session
self.protocolMap = configs[dbName]
self.db = dbs[dbName]
session.database = self.db.id
# Get some generally useful stuff now
self.baseURL = self.protocolMap.baseURL
# Get earliest datestamp in database - UTC of the epoch as query term
q = cqlparse('rec.lastModificationDate > "%s"'
'' % (str(datetime.datetime.utcfromtimestamp(0))))
try:
tl = self.db.scan(session, q, 1)
except SRWDiagnostics.Diagnostic16:
raise ConfigFileException('Index map for '
'rec.lastModificationDate required '
'in protocolMap: %s'
'' % self.db.get_path(session,
'protocolMap').id
)
else:
try:
datestamp = tl[0][0]
except IndexError:
# Something went wrong :( - use the epoch
self.earliestDatestamp = datetime.datetime.utcfromtimestamp(0)
else:
try:
self.earliestDatestamp = datetime.datetime.strptime(
datestamp,
'%Y-%m-%dT%H:%M:%S'
)
except ValueError:
self.earliestDatestamp = datetime.datetime.strptime(
datestamp,
'%Y-%m-%d %H:%M:%S'
)
self.repositoryName = self.protocolMap.title
self.protocolVersion = self.protocolMap.version
self.adminEmails = self.protocolMap.contacts
# Check for deletion support
recordStore = self.db.get_path(session, 'recordStore')
deletions = recordStore.get_setting(session, 'storeDeletions')
# Cheshire3 cannot guarantee that deletions will persist
self.deletedRecord = "transient" if deletions else "no"
# Finest level of granularity
self.granularity = "YYYY-MM-DDThh:mm:ssZ"
# Cheshire3 does not support compressions at this time
self.compression = []
self.metadataRegistry = OaiMetadataRegistry()
def getRecord(self, metadataPrefix, identifier):
"""Return a (header, metadata, about) tuple for the the record.
metadataPrefix - identifies metadata set to retrieve the record in
identifier - repository-unique identifier of record
Should raise error.CannotDisseminateFormatError if metadataPrefix
is unknown or not supported by identifier.
Should raise error.IdDoesNotExistError if identifier is unknown or
illegal.
"""
session = self.session
if (
metadataPrefix and not
(metadataPrefix in self.protocolMap.recordNamespaces)
):
raise CannotDisseminateFormatError()
if not self.metadataRegistry.hasWriter(metadataPrefix):
# Need to create a 'MetadataWriter' for this schema for oaipmh to
# use, and put in self.metadataRegister
schemaId = self.protocolMap.recordNamespaces[metadataPrefix]
txr = self.protocolMap.transformerHash.get(schemaId, None)
mdw = Cheshire3OaiMetadataWriter(txr)
self.metadataRegistry.registerWriter(metadataPrefix, mdw)
q = cqlparse('rec.identifier exact "%s"' % (identifier))
try:
rs = self.db.search(session, q)
except SRWDiagnostics.Diagnostic16:
raise ConfigFileException('Index map for rec.identifier required '
'in protocolMap: %s'
'' % self.db.get_path(session,
'protocolMap').id
)
if not len(rs) or len(rs) > 1:
raise IdDoesNotExistError('%s records exist for this identifier'
'' % (len(rs)))
r = rs[0]
# Handle non-ascii characters in identifier
#.........这里部分代码省略.........