Skip to content

Commit 9edede3

Browse files
author
renaud gaudin
committed
replace orjson with ujson which compiles on arm
1 parent cc2cc6d commit 9edede3

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ build-backend = "setuptools.build_meta"
55
[dependencies]
66
runtime = [
77
"jinja2 >=3.0,<4.0.0",
8-
"fastapi[all] >=0.70.0,<1.0",
8+
"fastapi >=0.70.0,<1.0",
99
"python-multipart",
1010
"requests >=2.26.0,<3.0",
11-
"httpx >=0.21.1,<1.0",
11+
"itsdangerous >=1.1.0,<3.0.0",
12+
"pyyaml >=5.3.1,<6.0.0",
13+
"ujson >=4.0.1,<5.0.0",
1214
]
1315
test = [
1416
"pytest >=6.2.4,<7.0.0",

src/contentfilter/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pathlib
22

3-
import orjson
3+
import usjon
44

55
from contentfilter.constants import Conf
66

@@ -9,15 +9,15 @@ class Database(list):
99
def __init__(self, fpath: pathlib.Path):
1010
if fpath.exists():
1111
with open(fpath, "r") as fh:
12-
super().__init__(orjson.loads(fh.read()))
12+
super().__init__(usjon.loads(fh.read()))
1313
else:
1414
super().__init__()
1515
self.fpath = fpath
1616

1717
def _sync(self):
1818
"""sync db to JSON on disk"""
1919
with open(self.fpath, "wb") as fh:
20-
fh.write(orjson.dumps(self))
20+
fh.write(usjon.dumps(self))
2121

2222
def add(self, item):
2323
if item not in self:

src/contentfilter/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import uuid
1010

1111
import jinja2
12-
import orjson
12+
import ujson
1313
from fastapi import (
1414
FastAPI,
1515
HTTPException,
@@ -43,9 +43,7 @@ def url_path_for(context: dict, name: str, **path_params: typing.Any) -> str:
4343

4444
class PrettyJSONResponse(JSONResponse):
4545
def render(self, content: typing.Any) -> bytes:
46-
return orjson.dumps(
47-
database, option=orjson.OPT_APPEND_NEWLINE | orjson.OPT_INDENT_2
48-
)
46+
return ujson.dumps(database, indent=4)
4947

5048

5149
def encode(text):
@@ -256,7 +254,7 @@ async def import_json(
256254
logger.info("RECEIVED FILE ?")
257255
try:
258256
content = await file.read()
259-
urls = orjson.loads(content)
257+
urls = ujson.loads(content)
260258
if not isinstance(urls, list):
261259
raise ValueError(f"JSON document is not a list: {type(urls)}")
262260
except Exception as exc:

0 commit comments

Comments
 (0)