def _get_graph(self): uri = self._uri() content_type, format = self._accept(uri) if uri.endswith("bibtex"): content_type = "text/x-bibtex" format = "bibtex" uri_str, _ = uri.rsplit(".", 1) uri = URIRef(uri_str) graph = handler.get(uri) if len(graph) == 0: graph.rollback() cursor = handler.rdflib.store.cursor() cursor.execute("SET result_timeout = 10000") q = construct_graph % {"agent": uri.n3()} graph = handler.rdflib.store.sparql_query(q, cursor=cursor) graph = Graph(graph.store, identifier=graph.identifier) # ordf extensions cursor.close() if len(graph) == 0: abort(404, "No such graph: %s" % uri) if format == "html": c.graph = graph c.model = model.Entry.get_by_uri(uri) response.content_type = str(content_type) # should really iterate through the potential views if URIRef("http://purl.org/ontology/bibo/Book") in list( c.model.type): data = render("view_bibo_book.html") else: data = self._render_graph() elif format == "bibtex": b = Bibtex() b.load_from_graph(graph) data = b.to_bibtex() response.content_type = str(content_type) response.headers['Content-Location'] = "%s.bibtex" % b.uniquekey response.headers['Location'] = "%s.bibtex" % b.uniquekey else: data = graph.serialize(format=format) response.content_type = str(content_type) graph.rollback() # log.warn("XXX cursor: %s" % handler.rdflib.store._cursor) return data
def _get_graph(self): uri = self._uri() content_type, format = self._accept(uri) if uri.endswith("bibtex"): content_type = "text/x-bibtex" format = "bibtex" uri_str, _ = uri.rsplit(".", 1) uri = URIRef(uri_str) graph = handler.get(uri) if len(graph) == 0: graph.rollback() cursor = handler.rdflib.store.cursor() cursor.execute("SET result_timeout = 10000") q = construct_graph % {"agent": uri.n3()} graph = handler.rdflib.store.sparql_query(q, cursor=cursor) graph = Graph(graph.store, identifier=graph.identifier) # ordf extensions cursor.close() if len(graph) == 0: abort(404, "No such graph: %s" % uri) if format == "html": c.graph = graph data = self._render_graph() elif format == "bibtex": b = Bibtex() b.load_from_graph(graph) data = b.to_bibtex() response.content_type = str(content_type) response.headers['Content-Location'] = "%s.bibtex" % b.uniquekey response.headers['Location'] = "%s.bibtex" % b.uniquekey else: data = graph.serialize(format=format) response.content_type = str(content_type) graph.rollback() # log.warn("XXX cursor: %s" % handler.rdflib.store._cursor) return data