Skip to content

Commit

Permalink
Merge pull request #175 from iiif-prezi/171_ascii_escaping
Browse files Browse the repository at this point in the history
ASCII Escaping
  • Loading branch information
digitaldogsbody authored Mar 10, 2023
2 parents 08209f3 + 147c426 commit d3787de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/recipes/scripts/0118-multivalue-method1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

canvas.items[0].items[0].id = "https://iiif.io/api/cookbook/recipe/0118_multivalue/canvas/1/page/1/annotation/1"

print(manifest.json(indent=2, ensure_ascii=False))
print(manifest.json(indent=2))
11 changes: 9 additions & 2 deletions iiif_prezi3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ def json(self, **kwargs):

def jsonld(self, **kwargs):
# approach 6- use the pydantic .dict() function to get the dict with pydantic options, add the context at the top and dump to json with modified kwargs
excluded_args = ["exclude_unset", "exclude_defaults", "exclude_none", "by_alias"]
excluded_args = ["exclude_unset", "exclude_defaults", "exclude_none", "by_alias", "ensure_ascii", "default"]
pydantic_args = ["include", "exclude", "encoder"]
dict_kwargs = dict([(arg, kwargs[arg]) for arg in kwargs.keys() if arg in pydantic_args])

json_kwargs = dict([(arg, kwargs[arg]) for arg in kwargs.keys() if arg not in pydantic_args + excluded_args])
return json.dumps({"@context": "http://iiif.io/api/presentation/3/context.json",
**self.dict(exclude_unset=False, exclude_defaults=False, exclude_none=True, by_alias=True, **dict_kwargs)}, default=pydantic_encoder, **json_kwargs)
**self.dict(exclude_unset=False,
exclude_defaults=False,
exclude_none=True,
by_alias=True,
**dict_kwargs)},
ensure_ascii=False,
default=pydantic_encoder,
**json_kwargs)

def jsonld_dict(self, **kwargs):
pydantic_args = ["include", "exclude", "encoder"]
Expand Down

0 comments on commit d3787de

Please sign in to comment.