Beispiel #1
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 urlencode(kw)
Beispiel #2
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
     return envelope
Beispiel #3
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)
         del kw['from_']
     until = kw.get('until')
     if until is not None:
         kw['until'] = datetime_to_datestamp(until,
                                             self._day_granularity)
     # now call underlying implementation
     method_name = verb + '_impl'
     return getattr(self, method_name)(
         kw, self.makeRequestErrorHandling(verb=verb, **kw))
Beispiel #4
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
Beispiel #5
0
 def _outputBasicEnvelope(self, **kw):
     e_oaipmh = Element(nsoai('OAI-PMH'), nsmap=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