Spaces:
Running
Running
Download python/borderland_eval/json_codec.py from FatUnc6969/borderland-rl: direct link, hf CLI and curl.
- Browser
- Download file 731 Bytes
-
https://huggingface.co/spaces/FatUnc6969/borderland-rl/resolve/main/python/borderland_eval/json_codec.py
- Command line
-
hf download hf://spaces/FatUnc6969/borderland-rl/python/borderland_eval/json_codec.py
-
curl -L -o json_codec.py https://huggingface.co/spaces/FatUnc6969/borderland-rl/resolve/main/python/borderland_eval/json_codec.py
731 Bytes
| import json | |
| import math | |
| def strict_json(value): | |
| def pairs(items): | |
| result = {} | |
| for key, item in items: | |
| if key in result: | |
| raise ValueError("duplicate JSON key") | |
| result[key] = item | |
| return result | |
| def nonfinite(_): | |
| raise ValueError("nonfinite JSON number") | |
| def number(value): | |
| parsed = float(value) | |
| if not math.isfinite(parsed): | |
| raise ValueError("nonfinite JSON number") | |
| return parsed | |
| if isinstance(value, (str, bytes)): | |
| return json.loads(value, object_pairs_hook=pairs, parse_constant=nonfinite, parse_float=number) | |
| return json.loads(json.dumps(value, allow_nan=False), object_pairs_hook=pairs) | |