diff --git a/pyproject.toml b/pyproject.toml index b3ffcae..f2ecede 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "yaml-ld" -version = "1.1.15" +version = "1.1.16" description = "YAML-LD for Python" authors = ["Anatoly Scherbakov "] license = "MIT" diff --git a/yaml_ld/document_loaders/content_types.py b/yaml_ld/document_loaders/content_types.py index 826eb49..32dced8 100644 --- a/yaml_ld/document_loaders/content_types.py +++ b/yaml_ld/document_loaders/content_types.py @@ -15,8 +15,10 @@ # - I've copied it over from pyld; # - It is hard-coded, I think I should handle it dynamically depending on # whatever parsers are available. +APPLICATION_LD_JSON = 'application/ld+json' + DEFAULT_ACCEPT_HEADER = ', '.join([ - 'application/ld+json', + APPLICATION_LD_JSON, 'application/rdf+xml;q=0.8', 'application/json;q=0.5', 'text/html;q=0.8', @@ -48,7 +50,12 @@ def construct_accept_header(url: URI) -> str: if url.startswith('https://w3id.org/fair/fip/terms/'): # Content negotiation will not work correctly because w3id does not # support content type weights. It will return the text/html version. - return 'application/ld+json' + return APPLICATION_LD_JSON + + if url.startswith('http://www.w3.org/ns/prov'): + # Content negotiation will not work correctly because w3.org does not + # handle weights for this namespace and returns the HTML variant. + return 'text/turtle' return DEFAULT_ACCEPT_HEADER @@ -61,9 +68,9 @@ def by_extension(extension: str) -> str | None: """ return { '.json': 'application/json', - '.jsonld': 'application/ld+json', - '.jldt': 'application/ld+json', - '.jldte': 'application/ld+json', + '.jsonld': APPLICATION_LD_JSON, + '.jldt': APPLICATION_LD_JSON, + '.jldte': APPLICATION_LD_JSON, '.yaml': 'application/yaml', '.yamlld': 'application/ld+yaml', '.html': 'text/html', @@ -89,7 +96,7 @@ def parser_by_content_type_map(): return { 'application/json': YAMLDocumentParser, - 'application/ld+json': YAMLDocumentParser, + APPLICATION_LD_JSON: YAMLDocumentParser, 'application/yaml': YAMLDocumentParser, 'application/x-yaml': YAMLDocumentParser, 'application/ld+yaml': YAMLDocumentParser,