forked from ijl/orjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
29 lines (21 loc) · 684 Bytes
/
Copy pathutil.py
File metadata and controls
29 lines (21 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import lzma
import os
from functools import lru_cache
from pathlib import Path
from typing import Any
import orjson
dirname = os.path.join(os.path.dirname(__file__), "../data")
if hasattr(os, "sched_setaffinity"):
os.sched_setaffinity(os.getpid(), {0, 1})
@lru_cache(maxsize=None)
def read_fixture(filename: str) -> bytes:
path = Path(dirname, filename)
if path.suffix == ".xz":
contents = lzma.decompress(path.read_bytes())
else:
contents = path.read_bytes()
return contents
@lru_cache(maxsize=None)
def read_fixture_obj(filename: str) -> Any:
return orjson.loads(read_fixture(filename))