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