Skip to content

Commit 2f742c2

Browse files
author
Prabhu Subramanian
committed
Replace ujson with orjson
1 parent ffba91c commit 2f742c2

File tree

7 files changed

+18
-20
lines changed

7 files changed

+18
-20
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ requests
22
appdirs
33
tabulate
44
msgpack
5-
ujson
5+
orjson
66
semver

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="appthreat-vulnerability-db",
8-
version="1.4.4",
8+
version="1.5.0",
99
author="Team AppThreat",
1010
author_email="cloud@appthreat.com",
1111
description="AppThreat's vulnerability database and package search library with a built-in file based storage. CVE, GitHub, npm are the primary sources of vulnerabilities.",
@@ -14,7 +14,7 @@
1414
long_description_content_type="text/markdown",
1515
url="https://github.com/appthreat/vulnerability-db",
1616
packages=setuptools.find_packages(),
17-
install_requires=["requests", "appdirs", "tabulate", "msgpack", "ujson", "semver"],
17+
install_requires=["requests", "appdirs", "tabulate", "msgpack", "orjson", "semver"],
1818
classifiers=[
1919
"Development Status :: 5 - Production/Stable",
2020
"Intended Audience :: Developers",

test/test_db.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_gha_search_bulk(test_db, test_gha_data):
135135
if d["details"]["max_affected_version_including"] != "*"
136136
]
137137
res = db.bulk_index_search(tmp_list)
138-
assert len(tmp_list)
138+
assert len(res)
139139

140140

141141
def test_index_search(test_db, test_vuln_data):
@@ -151,9 +151,7 @@ def test_index_search(test_db, test_vuln_data):
151151
for d in all_data[:40]:
152152
version = d["details"]["max_affected_version_including"]
153153
if version and version != "*":
154-
tmp_list.append(
155-
{"name": d["details"]["package"], "version": version,}
156-
)
154+
tmp_list.append({"name": d["details"]["package"], "version": version})
157155
res = db.bulk_index_search(tmp_list)
158156
assert len(res)
159157
for r in res:

vdb/lib/gha.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import os
1313
import re
1414

15+
import orjson
1516
import requests
16-
import ujson
1717

1818
from vdb.lib import config as config
1919
from vdb.lib.nvd import NvdSource
20-
from vdb.lib.utils import fix_text, get_default_cve_data
20+
from vdb.lib.utils import get_default_cve_data
2121

2222
logging.basicConfig(
2323
level=logging.INFO, format="%(levelname)s [%(asctime)s] %(message)s"
@@ -238,7 +238,7 @@ def convert(self, cve_data):
238238
cve_id=cve_id,
239239
cwe_id="UNKNOWN",
240240
assigner=assigner,
241-
references=ujson.dumps(references),
241+
references=orjson.dumps(references).decode("utf-8"),
242242
description="",
243243
vectorString=vectorString,
244244
vendor=vendor.lower(),
@@ -260,10 +260,10 @@ def convert(self, cve_data):
260260
lastModifiedDate=cve["updatedAt"],
261261
)
262262
try:
263-
tdata_json = ujson.loads(tdata)
263+
tdata_json = orjson.loads(tdata)
264264
vuln = NvdSource.convert_vuln(tdata_json)
265265
vuln.description = description
266266
ret_data.append(vuln)
267-
except Exception:
268-
LOG.warning(tdata)
267+
except Exception as e:
268+
LOG.debug(e)
269269
return ret_data, page_info

vdb/lib/npm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66
import logging
77

8+
import orjson
89
import requests
9-
import ujson
1010

1111
from vdb.lib import config as config
1212
from vdb.lib.nvd import NvdSource
@@ -227,7 +227,7 @@ def to_vuln(self, v, ret_data):
227227
cve_id=cve_id,
228228
cwe_id=cwe_id,
229229
assigner=assigner,
230-
references=ujson.dumps(references),
230+
references=orjson.dumps(references).decode("utf-8"),
231231
description="",
232232
vectorString=vectorString,
233233
vendor=vendor,
@@ -249,7 +249,7 @@ def to_vuln(self, v, ret_data):
249249
lastModifiedDate=lastModifiedDate,
250250
)
251251
try:
252-
vuln = NvdSource.convert_vuln(ujson.loads(tdata))
252+
vuln = NvdSource.convert_vuln(orjson.loads(tdata))
253253
vuln.description = description
254254
ret_data.append(vuln)
255255
except Exception:

vdb/lib/nvd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import logging
44
import tempfile
55

6+
import orjson
67
import requests
7-
import ujson
88

99
from vdb.lib import CvssV3, Vulnerability, VulnerabilityDetail, VulnerabilitySource
1010
from vdb.lib import config as config
@@ -73,7 +73,7 @@ def fetch(self, year):
7373
with gzip.open(tf.name, "rb") as gzipjf:
7474
cve_data = gzipjf.read()
7575
try:
76-
json_data = ujson.loads(cve_data)
76+
json_data = orjson.loads(cve_data)
7777
return self.convert(json_data)
7878
except Exception:
7979
logging.warning("Exception while parsing NVD CVE feed")

vdb/lib/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import importlib
22
import re
3-
from datetime import datetime, date
3+
from datetime import date, datetime
44
from enum import Enum
55

66
from semver import VersionInfo
@@ -71,7 +71,7 @@ def _load(d):
7171
raise ClassNotFoundError(
7272
"Class '%s' not found in the given module!" % t
7373
)
74-
except TypeError as te:
74+
except TypeError:
7575
raise TypeError(
7676
"Make sure there is an constuctor that doesn't take any arguments (class: %s)"
7777
% t

0 commit comments

Comments
 (0)