Пример #1
0
    def handleVerb(self, verb, kw):
        # validate kw first
        validation.validateArguments(verb, kw)
        # encode datetimes as datestamps
        from_ = kw.get('from_')
        if from_ is not None:
            # turn it into 'from', not 'from_' before doing actual request
            kw['from'] = datetime_to_datestamp(from_,
                                               self._day_granularity)
        if 'from_' in kw:
            # always remove it from the kw, no matter whether it be None or not
            del kw['from_']

        until = kw.get('until')
        if until is not None:
            kw['until'] = datetime_to_datestamp(until,
                                                self._day_granularity)
        elif 'until' in kw:
            # until is None but is explicitly in kw, remove it
            del kw['until']

        # now call underlying implementation
        method_name = verb + '_impl'
        return getattr(self, method_name)(
            kw, self.makeRequestErrorHandling(verb=verb, **kw))
Пример #2
0
    def handleVerb(self, verb, kw):
        # validate kw first

        #ich musste handleverb ueberschreiben, da ich die Validation mit einer speziellen Spezifikation fuer rero aufrufen muss
        #source=uc in ListRecords
        swissbibUtilities.validateArguments(verb, kw)
        # encode datetimes as datestamps
        from_ = kw.get('from_')
        if from_ is not None:
            # turn it into 'from', not 'from_' before doing actual request
            kw['from'] = datetime_to_datestamp(from_, self._day_granularity)
        if 'from_' in kw:
            # always remove it from the kw, no matter whether it be None or not
            del kw['from_']

        until = kw.get('until_')
        if until is not None:
            kw['until'] = datetime_to_datestamp(until, self._day_granularity)
        if 'until_' in kw:
            # until is None but is explicitly in kw, remove it
            del kw['until_']

        if 'source' in kw and kw.get('source') is None:
            del kw['source']
        if 'resumptionToken' in kw and kw.get('resumptionToken') is None:
            del kw['resumptionToken']
        if 'set' in kw and kw.get('set') is None:
            del kw['set']

        # now call underlying implementation
        method_name = verb + '_impl'
        return getattr(self,
                       method_name)(kw,
                                    self.makeRequestErrorHandling(verb=verb,
                                                                  **kw))
    def handleVerb(self, verb, kw):
        # validate kw first

        # ich musste handleverb ueberschreiben, da ich die Validation mit einer speziellen Spezifikation fuer rero aufrufen muss
        # source=uc in ListRecords
        swissbibUtilities.validateArguments(verb, kw)
        # encode datetimes as datestamps
        from_ = kw.get("from_")
        if from_ is not None:
            # turn it into 'from', not 'from_' before doing actual request
            kw["from"] = datetime_to_datestamp(from_, self._day_granularity)
        if "from_" in kw:
            # always remove it from the kw, no matter whether it be None or not
            del kw["from_"]

        until = kw.get("until_")
        if until is not None:
            kw["until"] = datetime_to_datestamp(until, self._day_granularity)
        if "until_" in kw:
            # until is None but is explicitly in kw, remove it
            del kw["until_"]

        if "source" in kw and kw.get("source") is None:
            del kw["source"]
        if "resumptionToken" in kw and kw.get("resumptionToken") is None:
            del kw["resumptionToken"]
        if "set" in kw and kw.get("set") is None:
            del kw["set"]

        # now call underlying implementation
        method_name = verb + "_impl"
        return getattr(self, method_name)(kw, self.makeRequestErrorHandling(verb=verb, **kw))
Пример #4
0
def encodeResumptionToken(kw, cursor):
    kw = kw.copy()
    kw['cursor'] = str(cursor)
    from_ = kw.get('from_')
    if from_ is not None:
        kw['from_'] = datetime_to_datestamp(from_)
    until = kw.get('until')
    if until is not None:
        kw['until'] = datetime_to_datestamp(until)
    return quote(urlencode(kw))
Пример #5
0
def encodeResumptionToken(kw, cursor):
    kw = kw.copy()
    kw['cursor'] = str(cursor)
    from_ = kw.get('from_')
    if from_ is not None:
        kw['from_'] = datetime_to_datestamp(from_)
    until = kw.get('until')
    if until is not None:
        kw['until'] = datetime_to_datestamp(until)
    return quote(urlencode(kw))
Пример #6
0
    def identify(self):
        envelope, e_identify = self._outputEnvelope(verb='Identify')
        identify = self._server.identify()
        e_repositoryName = SubElement(e_identify, nsoai('repositoryName'))
        e_repositoryName.text = identify.repositoryName()
        e_baseURL = SubElement(e_identify, nsoai('baseURL'))
        e_baseURL.text = identify.baseURL()
        e_protocolVersion = SubElement(e_identify, nsoai('protocolVersion'))
        e_protocolVersion.text = identify.protocolVersion()
        for adminEmail in identify.adminEmails():
            e = SubElement(e_identify, nsoai('adminEmail'))
            e.text = adminEmail
        e_earliestDatestamp = SubElement(e_identify,
                                         nsoai('earliestDatestamp'))
        e_earliestDatestamp.text = datetime_to_datestamp(
            identify.earliestDatestamp())
        e_deletedRecord = SubElement(e_identify,
                                     nsoai('deletedRecord'))
        e_deletedRecord.text = identify.deletedRecord()
        e_granularity = SubElement(e_identify, nsoai('granularity'))
        e_granularity.text = identify.granularity()
        compressions = identify.compression()
        if compressions != ['identity']:
            for compression in compressions:
                e_compression = SubElement(e_identify, nsoai('compression'))
                e_compression.text = compression

        for description in identify.descriptions():
            e_description = SubElement(e_identify, nsoai('description'))
            e_description.append(etree.fromstring(description))
        return envelope
Пример #7
0
    def identify(self):
        envelope, e_identify = self._outputEnvelope(verb='Identify')
        identify = self._server.identify()
        e_repositoryName = SubElement(e_identify, nsoai('repositoryName'))
        e_repositoryName.text = identify.repositoryName()
        e_baseURL = SubElement(e_identify, nsoai('baseURL'))
        e_baseURL.text = identify.baseURL()
        e_protocolVersion = SubElement(e_identify, nsoai('protocolVersion'))
        e_protocolVersion.text = identify.protocolVersion()
        for adminEmail in identify.adminEmails():
            e = SubElement(e_identify, nsoai('adminEmail'))
            e.text = adminEmail
        e_earliestDatestamp = SubElement(e_identify,
                                         nsoai('earliestDatestamp'))
        e_earliestDatestamp.text = datetime_to_datestamp(
            identify.earliestDatestamp())
        e_deletedRecord = SubElement(e_identify,
                                     nsoai('deletedRecord'))
        e_deletedRecord.text = identify.deletedRecord()
        e_granularity = SubElement(e_identify, nsoai('granularity'))
        e_granularity.text = identify.granularity()
        compressions = identify.compression()
        if compressions != ['identity']:
            for compression in compressions:
                e_compression = SubElement(e_identify, nsoai('compression'))
                e_compression.text = compression

        for description in identify.descriptions():
            e_description = SubElement(e_identify, nsoai('description'))
            e_description.append(etree.fromstring(description))
        return envelope
Пример #8
0
    def handleVerb(self, verb, kw):
        # if kw contains 'setSpec' transform the keymap to 'set'
        if kw.has_key('setSpec'):
            kw['set'] = kw['setSpec']
            del kw['setSpec']
        # validate kw first
        validation.validateArguments(verb, kw)
        # encode datetimes as datestamps
        from_ = kw.get('from_')
        if from_ is not None:
            # turn it into 'from', not 'from_' before doing actual request
            kw['from'] = datetime_to_datestamp(from_,
                                               self._day_granularity)
        if 'from_' in kw:
            # always remove it from the kw, no matter whether it be None or not
            del kw['from_']

        until = kw.get('until')
        if until is not None:
            kw['until'] = datetime_to_datestamp(until,
                                                self._day_granularity)
        elif 'until' in kw:
            # until is None but is explicitly in kw, remove it
            del kw['until']

        # There can be no resumptionToken and metadataPrefix at the same time.
        # Otherwise, we will receive an error when doing the request.
        # However, we may need both if we are recovering from a network
        # problem. thus, we will save kw[metadataPrefix] in
        # metadataPrefixSaved.
        if verb == 'ListRecords' and kw.get('resumptionToken'):
            metadataPrefixSaved = kw['metadataPrefix']
            del(kw['metadataPrefix'])
        else:
            metadataPrefixSaved = None
        # Do the request
        tree = self.makeRequestErrorHandling(verb=verb, **kw)
        # We need to add the metadataPrefixSaved back, if exists
        if metadataPrefixSaved:
            kw['metadataPrefix'] = metadataPrefixSaved
        # now call underlying implementation
        method_name = verb + '_impl'
        return getattr(self, method_name)(kw, tree)
Пример #9
0
 def _outputHeader(self, element, header):
     e_header = SubElement(element, nsoai('header'))
     if header.isDeleted():
         e_header.set('status', 'deleted')
     e_identifier = SubElement(e_header, nsoai('identifier'))
     e_identifier.text = header.identifier()
     e_datestamp = SubElement(e_header, nsoai('datestamp'))
     e_datestamp.text = datetime_to_datestamp(header.datestamp())
     for set in header.setSpec():
         e = SubElement(e_header, nsoai('setSpec'))
         e.text = set
Пример #10
0
 def _outputBasicEnvelope(self, **kw):
     e_oaipmh = Element(nsoai('OAI-PMH'), nsmap=self._nsmap)
     e_oaipmh.set('{%s}schemaLocation' % NS_XSI,
                  ('http://www.openarchives.org/OAI/2.0/ '
                   'http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd'))
     e_tree = ElementTree(element=e_oaipmh)
     e_responseDate = SubElement(e_oaipmh, nsoai('responseDate'))
     # date should be first possible moment
     e_responseDate.text = datetime_to_datestamp(
         datetime.utcnow().replace(microsecond=0))
     e_request = SubElement(e_oaipmh, nsoai('request'))
     for key, value in kw.items():
         if key == 'from_':
             key = 'from'
         if key == 'from' or key == 'until':
             value = datetime_to_datestamp(value)
         e_request.set(key, value)
     # XXX this is potentially slow..
     e_request.text = self._server.identify().baseURL()
     return e_tree, e_oaipmh
Пример #11
0
 def _outputHeader(self, element, header):
     e_header = SubElement(element, nsoai('header'))
     if header.isDeleted():
         e_header.set('status', 'deleted')
     e_identifier = SubElement(e_header, nsoai('identifier'))
     e_identifier.text = header.identifier()
     e_datestamp = SubElement(e_header, nsoai('datestamp'))
     e_datestamp.text = datetime_to_datestamp(header.datestamp())
     for set in header.setSpec():
         e = SubElement(e_header, nsoai('setSpec'))
         e.text = set
Пример #12
0
 def _outputBasicEnvelope(self, **kw):
     e_oaipmh = Element(nsoai('OAI-PMH'), nsmap=self._nsmap)
     e_oaipmh.set('{%s}schemaLocation' % NS_XSI,
                  ('http://www.openarchives.org/OAI/2.0/ '
                   'http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd'))
     e_tree = ElementTree(element=e_oaipmh)
     e_responseDate = SubElement(e_oaipmh, nsoai('responseDate'))
     # date should be first possible moment
     e_responseDate.text = datetime_to_datestamp(
         datetime.utcnow().replace(microsecond=0))
     e_request = SubElement(e_oaipmh, nsoai('request'))
     for key, value in kw.items():
         if key == 'from_':
             key = 'from'
         if key == 'from' or key == 'until':
             value = datetime_to_datestamp(value)
         e_request.set(key, value)
     # XXX this is potentially slow..
     e_request.text = self._server.identify().baseURL()
     return e_tree, e_oaipmh
Пример #13
0
 def _outputHeader(self, element, header):
     if(type(header)==tuple):
         #we need to strip out token
         header=header[0]
     e_header = SubElement(element, nsoai('header'))
     if header.isDeleted():
         e_header.set('status', 'deleted')
     e_identifier = SubElement(e_header, nsoai('identifier'))
     e_identifier.text = header.identifier()
     e_datestamp = SubElement(e_header, nsoai('datestamp'))
     e_datestamp.text = datetime_to_datestamp(header.datestamp())
     for set in header.setSpec():
         e = SubElement(e_header, nsoai('setSpec'))
         e.text = set