Skip to content

Commit

Permalink
fix DCAT output to support str or dict
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Sep 30, 2022
1 parent 936104c commit 15ac95c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pygeometa/schemas/dcat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import json
import os
from typing import Union

from pygeometa.helpers import json_serial
from pygeometa.schemas.base import BaseOutputSchema
Expand All @@ -64,13 +65,15 @@ def __init__(self):

super().__init__('dcat', 'json', THISDIR)

def write(self, mcf: dict) -> str:
def write(self, mcf: dict, stringify: str = True) -> Union[dict, str]:
"""
Write outputschema to JSON string buffer
Write MCF to DCAT
:param mcf: dict of MCF content model
:param stringify: whether to return a string representation (default)
else native (dict, etree)
:returns: MCF as a dcat representation
:returns: `dict` or `str` of MCF as a DCAT representation
"""

dcat = {
Expand Down Expand Up @@ -203,4 +206,7 @@ def write(self, mcf: dict) -> str:
else:
dcat[key] = value

return json.dumps(dcat, default=json_serial, indent=4)
if stringify:
return json.dumps(dcat, default=json_serial, indent=4)

return dcat

0 comments on commit 15ac95c

Please sign in to comment.