Coverage for src/somesy/json_wrapper.py: 100%
8 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-04-30 09:42 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-04-30 09:42 +0000
1"""Utility functions for somesy."""
2import json
4import wrapt
7@wrapt.decorator
8def json_dump_wrapper(wrapped, instance, args, kwargs):
9 """Wrap json.dump to write non-ascii characters with default indentation."""
10 # Ensure ensure_ascii is set to False
11 kwargs["ensure_ascii"] = False
12 # set indent to 2 if not set
13 kwargs["indent"] = kwargs.get("indent", 2)
14 return wrapped(*args, **kwargs)
17# Apply the wrapper
18json.dump = json_dump_wrapper(json.dump)