#NEWLINE# def response( self , response , kvp , repository , server_url ) : #NEWLINE# #INDENT# 'process OAI-PMH request' #NEWLINE# mode = kvp . pop ( 'mode' , None ) #NEWLINE# if ( 'config' in kvp ) : #NEWLINE# #INDENT# config_val = kvp . pop ( 'config' ) #NEWLINE# #UNINDENT# url = ( '%smode=oaipmh' % util . bind_url ( server_url ) ) #NEWLINE# node = etree . Element ( util . nspath_eval ( 'oai:OAI-PMH' , self . namespaces ) , nsmap = self . namespaces ) #NEWLINE# node . set ( util . nspath_eval ( 'xsi:schemaLocation' , self . namespaces ) , ( '%s http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd' % self . namespaces [ 'oai' ] ) ) #NEWLINE# LOGGER . info ( etree . tostring ( node ) ) #NEWLINE# etree . SubElement ( node , util . nspath_eval ( 'oai:responseDate' , self . namespaces ) ) . text = util . get_today_and_now ( ) #NEWLINE# etree . SubElement ( node , util . nspath_eval ( 'oai:request' , self . namespaces ) , attrib = kvp ) . text = url #NEWLINE# if ( 'verb' not in kvp ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'oai:error' , self . namespaces ) , code = 'badArgument' ) . text = "Missing 'verb' parameter" #NEWLINE# return node #NEWLINE# #UNINDENT# if ( kvp [ 'verb' ] not in self . request_model . keys ( ) ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'oai:error' , self . namespaces ) , code = 'badArgument' ) . text = ( "Unknown verb '%s'" % kvp [ 'verb' ] ) #NEWLINE# return node #NEWLINE# #UNINDENT# if ( util . xmltag_split ( response . tag ) == 'ExceptionReport' ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'oai:error' , self . namespaces ) , code = 'badArgument' ) . text = response . xpath ( '//ows:ExceptionText|//ows20:ExceptionText' , namespaces = self . context . namespaces ) [ 0 ] . text #NEWLINE# return node #NEWLINE# #UNINDENT# verb = kvp . pop ( 'verb' ) #NEWLINE# if ( verb in [ 'GetRecord' , 'ListIdentifiers' , 'ListRecords' ] ) : #NEWLINE# #INDENT# if ( 'metadataprefix' not in kvp ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'oai:error' , self . namespaces ) , code = 'badArgument' ) . text = 'Missing metadataPrefix parameter' #NEWLINE# return node #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( kvp [ 'metadataprefix' ] not in self . metadata_formats . keys ( ) ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'oai:error' , self . namespaces ) , code = 'badArgument' ) . text = 'Invalid metadataPrefix parameter' #NEWLINE# return node #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for ( key , value ) in kvp . items ( ) : #NEWLINE# #INDENT# if ( ( key != 'mode' ) and ( key not in self . request_model [ verb ] ) ) : #NEWLINE# #INDENT# etree . SubElement ( node , util . nspath_eval ( 'oai:error' , self . namespaces ) , code = 'badArgument' ) . text = ( "Illegal parameter '%s'" % key ) #NEWLINE# return node #NEWLINE# #UNINDENT# #UNINDENT# verbnode = etree . SubElement ( node , util . nspath_eval ( ( 'oai:%s' % verb ) , self . namespaces ) ) #NEWLINE# if ( verb == 'Identify' ) : #NEWLINE# #INDENT# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:repositoryName' , self . namespaces ) ) . text = self . config . get ( 'metadata:main' , 'identification_title' ) #NEWLINE# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:baseURL' , self . namespaces ) ) . text = url #NEWLINE# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:protocolVersion' , self . namespaces ) ) . text = '2.0' #NEWLINE# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:adminEmail' , self . namespaces ) ) . text = self . config . get ( 'metadata:main' , 'contact_email' ) #NEWLINE# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:earliestDatestamp' , self . namespaces ) ) . text = repository . query_insert ( 'min' ) #NEWLINE# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:deletedRecord' , self . namespaces ) ) . text = 'no' #NEWLINE# etree . SubElement ( verbnode , util . nspath_eval ( 'oai:granularity' , self . namespaces ) ) . text = 'YYYY-MM-DDThh:mm:ssZ' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( verb == 'ListSets' ) : #NEWLINE# #INDENT# for ( key , value ) in sorted ( self . metadata_sets . items ( ) ) : #NEWLINE# #INDENT# setnode = etree . SubElement ( verbnode , util . nspath_eval ( 'oai:set' , self . namespaces ) ) #NEWLINE# etree . SubElement ( setnode , util . nspath_eval ( 'oai:setSpec' , self . namespaces ) ) . text = key #NEWLINE# etree . SubElement ( setnode , util . nspath_eval ( 'oai:setName' , self . namespaces ) ) . text = value [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( verb == 'ListMetadataFormats' ) : #NEWLINE# #INDENT# for ( key , value ) in sorted ( self . metadata_formats . items ( ) ) : #NEWLINE# #INDENT# mdfnode = etree . SubElement ( verbnode , util . nspath_eval ( 'oai:metadataFormat' , self . namespaces ) ) #NEWLINE# etree . SubElement ( mdfnode , util . nspath_eval ( 'oai:metadataPrefix' , self . namespaces ) ) . text = key #NEWLINE# etree . SubElement ( mdfnode , util . nspath_eval ( 'oai:schema' , self . namespaces ) ) . text = value [ 'schema' ] #NEWLINE# etree . SubElement ( mdfnode , util . nspath_eval ( 'oai:metadataNamespace' , self . namespaces ) ) . text = value [ 'namespace' ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( verb in [ 'GetRecord' , 'ListIdentifiers' , 'ListRecords' ] ) : #NEWLINE# #INDENT# if ( verb == 'GetRecord' ) : #NEWLINE# #INDENT# records = response . getchildren ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# records = response . getchildren ( ) [ 1 ] . getchildren ( ) #NEWLINE# #UNINDENT# for child in records : #NEWLINE# #INDENT# recnode = etree . SubElement ( verbnode , util . nspath_eval ( 'oai:record' , self . namespaces ) ) #NEWLINE# header = etree . SubElement ( recnode , util . nspath_eval ( 'oai:header' , self . namespaces ) ) #NEWLINE# self . _transform_element ( header , response , 'oai:identifier' ) #NEWLINE# self . _transform_element ( header , response , 'oai:dateStamp' ) #NEWLINE# self . _transform_element ( header , response , 'oai:setSpec' ) #NEWLINE# if ( verb in [ 'GetRecord' , 'ListRecords' ] ) : #NEWLINE# #INDENT# metadata = etree . SubElement ( recnode , util . nspath_eval ( 'oai:metadata' , self . namespaces ) ) #NEWLINE# if ( ( 'metadataprefix' in kvp ) and ( kvp [ 'metadataprefix' ] == 'oai_dc' ) ) : #NEWLINE# #INDENT# child . tag = util . nspath_eval ( 'oai_dc:dc' , self . namespaces ) #NEWLINE# #UNINDENT# metadata . append ( child ) #NEWLINE# #UNINDENT# #UNINDENT# if ( verb != 'GetRecord' ) : #NEWLINE# #INDENT# complete_list_size = response . xpath ( '//@numberOfRecordsMatched' ) [ 0 ] #NEWLINE# next_record = response . xpath ( '//@nextRecord' ) [ 0 ] #NEWLINE# cursor = str ( ( ( int ( complete_list_size ) - int ( next_record ) ) - 1 ) ) #NEWLINE# resumption_token = etree . SubElement ( verbnode , util . nspath_eval ( 'oai:resumptionToken' , self . namespaces ) , completeListSize = complete_list_size , cursor = cursor ) . text = next_record #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return node