コード例 #1
0
ファイル: oaiidentify.py プロジェクト: seecr/meresco-oai
    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()
コード例 #2
0
ファイル: oaierror.py プロジェクト: seecr/meresco-oai
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()