Coverage for apis_core/generic/renderers.py: 0%
23 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1import logging
3from rdflib import Graph
4from rest_framework import renderers
6logger = logging.getLogger(__name__)
9class GenericRDFBaseRenderer(renderers.BaseRenderer):
10 def render(self, data, accepted_media_type=None, renderer_context=None):
11 g = Graph()
12 for result in data.get("results", []):
13 match result:
14 case tuple(_, _, _):
15 g.add(result)
16 case other:
17 logger.debug("Could not add %s to RDF graph: not a tuple", other)
18 return g.serialize(format=self.media_type)
21class GenericRDFXMLRenderer(GenericRDFBaseRenderer):
22 media_type = "application/rdf+xml"
23 format = "rdf+xml"
26class GenericRDFTurtleRenderer(GenericRDFBaseRenderer):
27 media_type = "text/turtle"
28 format = "rdf+turtle"
31class GenericRDFN3Renderer(GenericRDFBaseRenderer):
32 media_type = "text/n3"
33 format = "rdf+n3"