class MetadataXML(object): """ WSGI app for downloading metadata in XML format """ def __init__(self): from medin.dws import MetadataRequest self.request = MetadataRequest() self.obfuscate_emails = ObfuscateEmails( ) # ensure emails are obfuscated when rendered def prepareSOAP(self, environ): gid = environ['selector.vars']['gid'] # the global metadata identifier fmt = environ['selector.vars']['format'] # the requested format if fmt not in self.request.getMetadataFormats( environ['logging.logger']): raise HTTPError('404 Not Found', 'The metadata format is not supported: %s' % fmt) self.gid = gid self.fmt = fmt return self.request.prepareCaller(environ['logging.logger'], gid, fmt) def __call__(self, environ, start_response): from os.path import splitext self.prepareSOAP(environ) gid, fmt = self.gid, self.fmt response = self.request() if not response: raise HTTPError('404 Not Found', 'The metadata record does not exist: %s' % gid) document = self.obfuscate_emails(response.xml) if not document: raise HTTPError( '404 Not Found', 'The metadata format does not contain any data: %s' % fmt) # Check if the client needs a new version headers = [] date = response.date if date: etag = check_etag(environ, date) headers.extend([('Etag', etag), ('Cache-Control', 'no-cache, must-revalidate')]) filename = gid if splitext(filename)[1] != '.xml': filename += '.xml' headers.extend([('Content-disposition', 'attachment; filename="%s"' % filename), ('Content-Type', 'application/xml')]) start_response('200 OK', headers) return [document]
class MetadataXML(object): """ WSGI app for downloading metadata in XML format """ def __init__(self): from medin.dws import MetadataRequest self.request = MetadataRequest() self.obfuscate_emails = ObfuscateEmails() # ensure emails are obfuscated when rendered def prepareSOAP(self, environ): gid = environ['selector.vars']['gid'] # the global metadata identifier fmt = environ['selector.vars']['format'] # the requested format if fmt not in self.request.getMetadataFormats(environ['logging.logger']): raise HTTPError('404 Not Found', 'The metadata format is not supported: %s' % fmt) self.gid = gid self.fmt = fmt return self.request.prepareCaller(environ['logging.logger'], gid, fmt) def __call__(self, environ, start_response): from os.path import splitext self.prepareSOAP(environ) gid, fmt = self.gid, self.fmt response = self.request() if not response: raise HTTPError('404 Not Found', 'The metadata record does not exist: %s' % gid) document = self.obfuscate_emails(response.xml) if not document: raise HTTPError('404 Not Found', 'The metadata format does not contain any data: %s' % fmt) # Check if the client needs a new version headers = [] date = response.date if date: etag = check_etag(environ, date) headers.extend([('Etag', etag), ('Cache-Control', 'no-cache, must-revalidate')]) filename = gid if splitext(filename)[1] != '.xml': filename += '.xml' headers.extend([('Content-disposition', 'attachment; filename="%s"' % filename), ('Content-Type', 'application/xml')]) start_response('200 OK', headers) return [document]
def __init__(self): from medin.dws import MetadataRequest self.request = MetadataRequest() self.obfuscate_emails = ObfuscateEmails( ) # ensure emails are obfuscated when rendered
def __init__(self): from medin.dws import MetadataRequest self.request = MetadataRequest() self.obfuscate_emails = ObfuscateEmails() # ensure emails are obfuscated when rendered