Coverage for apis_core/generic/renderers.py: 0%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.8, created at 2024-12-20 09:24 +0000

1import logging 

2 

3from rdflib import Graph 

4from rest_framework import renderers 

5 

6logger = logging.getLogger(__name__) 

7 

8 

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) 

19 

20 

21class GenericRDFXMLRenderer(GenericRDFBaseRenderer): 

22 media_type = "application/rdf+xml" 

23 format = "rdf+xml" 

24 

25 

26class GenericRDFTurtleRenderer(GenericRDFBaseRenderer): 

27 media_type = "text/turtle" 

28 format = "rdf+turtle" 

29 

30 

31class GenericRDFN3Renderer(GenericRDFBaseRenderer): 

32 media_type = "text/n3" 

33 format = "rdf+n3"