def resource(label, type_=None): """ Do ContentNegotiation for some resource and redirect to the appropriate place """ mimetype=mimeutils.best_match([mimeutils.RDFXML_MIME, mimeutils.N3_MIME, mimeutils.NTRIPLES_MIME, mimeutils.HTML_MIME], request.headers["Accept"]) if mimetype and mimetype!=mimeutils.HTML_MIME: path="data" ext="."+mimeutils.mime_to_format(mimetype) else: path="page" ext="" #print "label", label if type_: if ext!='' : url=url_for(path, type_=type_, label=label, format_=ext) else: url=url_for(path, type_=type_, label=label) else: if ext!='': url=url_for(path, label=label, format_=ext) else: url=url_for(path, label=label) return redirect(url, 303)
def negotiate(self, resulttype, accept_header): #TODO: Find all mimetypes supported by the serializers #automatically instead of hardcoded import logging if resulttype == self.RESULT_GRAPH: available = ['application/n-triples', 'text/n3', 'text/turtle', 'application/rdf+xml'] assert available, "Invalid resulttype" import mimeutils best = mimeutils.best_match(available, accept_header) or available[-1] return best, best
def negotiate(self, resulttype, accept_header): #TODO: Find all mimetypes supported by the serializers #automatically instead of hardcoded import logging if resulttype == self.RESULT_GRAPH: available = [ 'application/n-triples', 'text/n3', 'text/turtle', 'application/rdf+xml' ] assert available, "Invalid resulttype" import mimeutils best = mimeutils.best_match(available, accept_header) or available[-1] return best, best