- From: Rob Sanderson via GitHub <sysbot+gh@w3.org>
- Date: Wed, 09 Sep 2015 19:12:49 +0000
- To: public-annotation@w3.org
Assuming a JSON based system, the code to produce Turtle for requests
is pretty easy, even including parsing the Accept header:
```python
def do_conneg(output):
accept = request.headers.get('Accept', '')
ct = default_json_content_type
if accept:
prefs = []
for item in value.split(","):
parts = item.split(";")
main = parts.pop(0).strip()
params = []
q = 1.0
for part in parts:
(key, value) = part.lstrip().split("=", 1)
key = key.strip()
value = value.strip().replace('"', '')
if key == "q":
q = float(value)
else:
params.append((key, value))
prefs.append((main, dict(params), q))
prefs.sort(lambda x, y: -cmp(x[2], y[2]))
format = ""
for p in prefs:
if self.rdflib_format_map.has_key(p[0]):
ct = p[0]
format = self.rdflib_format_map[p[0]]
break
elif p[0] in ['application/json',
'application/ld+json']:
ct = p[0]
break
if format:
g = Graph()
g.parse(data=output, format='json-ld')
output = g.serialize(format=format)
response['content_type'] = ct
return output
```
So given the above 35 line implementation in python, I'm -1 to making
it optional.
A second implementation (or port of the above) is sought to close the
issue.
--
GitHub Notif of comment by azaroth42
See
https://github.com/w3c/web-annotation/issues/34#issuecomment-139017048
Received on Wednesday, 9 September 2015 19:12:50 UTC