Download data/copilotj/util/json.py from introvoyz045/CopilotJ: direct link, hf CLI and curl.
- Browser
- Download file 931 Bytes
-
https://huggingface.co/datasets/introvoyz045/CopilotJ/resolve/main/data/copilotj/util/json.py
- Command line
-
hf download hf://datasets/introvoyz045/CopilotJ/data/copilotj/util/json.py
-
curl -L -o json.py https://huggingface.co/datasets/introvoyz045/CopilotJ/resolve/main/data/copilotj/util/json.py
931 Bytes
| # SPDX-FileCopyrightText: Copyright contributors to the CopilotJ project. | |
| # | |
| # SPDX-License-Identifier: Apache-2.0 | |
| from typing import Any, Protocol | |
| import ujson | |
| __all__ = ["IndentedJson", "IndentedRawJson"] | |
| class IndentedJson: | |
| """A custom formatter for logging that formats JSON data lazily.""" | |
| def __init__(self, data: Any, indent: int = 2): | |
| super().__init__() | |
| self._data = data | |
| self._indent = indent | |
| def __str__(self): | |
| return ujson.dumps(self._data, indent=self._indent) | |
| class _StrLike(Protocol): | |
| def __str__(self) -> str: ... | |
| class IndentedRawJson: | |
| """A custom formatter for logging that formats JSON data lazily.""" | |
| def __init__(self, data: str | _StrLike, indent: int = 2): | |
| super().__init__() | |
| self._data = data | |
| self._indent = indent | |
| def __str__(self): | |
| return ujson.dumps(ujson.loads(str(self._data)), indent=self._indent) | |