def identify(self, arguments, **httpkwargs): responseDate = zuluTime() if arguments.keys() != ['verb']: additionalMessage = 'Argument(s) %s is/are illegal.' % ", ".join('"%s"' % key for key in arguments.keys() if key != 'verb') yield oaiError('badArgument', additionalMessage=additionalMessage, arguments=arguments, requestUrl=self._repository.requestUrl(**httpkwargs), **httpkwargs) return repositoryIdentifier = self._repository.identifier descriptionRepositoryIdentifier = '' if not repositoryIdentifier else DESCRIPTION_REPOSITORY_IDENTIFIER % {'repositoryIdentifier': escapeXml(repositoryIdentifier)} values = { 'repositoryName': escapeXml(self._repository.name), 'baseURL': escapeXml(self._repository.requestUrl(**httpkwargs)), 'adminEmails': ''.join([ADMIN_EMAIL % escapeXml(email) for email in [self._repository.adminEmail]]), 'deletedRecord': self.call.getDeletedRecordType(), } values.update(hardcoded_values) yield oaiHeader(self, responseDate) yield oaiRequestArgs(arguments, requestUrl=self._repository.requestUrl(**httpkwargs), **httpkwargs) yield '<Identify>' yield IDENTIFY % values yield descriptionRepositoryIdentifier yield TOOLKIT_DESCRIPTION yield self.all.description() yield '</Identify>' yield oaiFooter()
def oaiError(statusCode, additionalMessage, arguments, requestUrl, **httpkwargs): responseDate = zuluTime() space = additionalMessage and " " or "" message = ERROR_CODES[statusCode] + space + additionalMessage yield oaiHeader(responseDate=responseDate) if statusCode in ["badArgument", "badResumptionToken", "badVerb"]: """in these cases it is illegal to echo the arguments back; since the arguments are not valid in the first place the response will not validate either""" yield oaiRequestArgs({}, requestUrl=requestUrl, **httpkwargs) else: yield oaiRequestArgs(arguments, requestUrl=requestUrl, **httpkwargs) yield """<error code="%(statusCode)s">%(message)s</error>""" % locals() yield oaiFooter()
def getRecord(self, arguments, **httpkwargs): responseDate = zuluTime() verb = arguments.get('verb', [None])[0] if not verb == 'GetRecord': return try: validatedArguments = self._validateArguments(arguments) identifier = validatedArguments['identifier'] if self._repository: identifier = self._repository.unprefixIdentifier(identifier) metadataPrefix = validatedArguments['metadataPrefix'] record = self.call.getRecord(identifier=identifier, metadataPrefix=metadataPrefix) self._validateValues(record, metadataPrefix) except OaiException, e: yield oaiError(e.statusCode, e.additionalMessage, arguments, requestUrl=self._repository.requestUrl(**httpkwargs), **httpkwargs) return
def listSets(self, arguments, **httpkwargs): responseDate = zuluTime() verb = arguments.get('verb', [None])[0] if not verb == 'ListSets': return try: validatedArguments = self._validateArguments(arguments) if 'resumptionToken' in validatedArguments: raise OaiException('badResumptionToken') sets = self.call.getAllSets(includeSetNames=True) if len(sets) == 0: raise OaiException('noSetHierarchy') except OaiException, e: yield oaiError(e.statusCode, e.additionalMessage, arguments, requestUrl=self._repository.requestUrl(**httpkwargs), **httpkwargs) return
def listMetadataFormats(self, arguments, **httpkwargs): responseDate = zuluTime() verb = arguments.get('verb', [None])[0] if not verb == 'ListMetadataFormats': return try: validatedArguments = self._validateArguments(arguments) metadataFormats = self.call.getAllMetadataFormats() if 'identifier' in validatedArguments: identifier = validatedArguments['identifier'] if self._repository: identifier = self._repository.unprefixIdentifier(identifier) record = self.call.getRecord(identifier=identifier) if record is None: raise OaiException('idDoesNotExist') metadataFormats = [(prefix, xsd, ns) for prefix, xsd, ns in metadataFormats if prefix in record.prefixes] displayedMetadataFormats = sorted(metadataFormats) except OaiException, e: yield oaiError(e.statusCode, e.additionalMessage, arguments, requestUrl=self._repository.requestUrl(**httpkwargs), **httpkwargs) return