aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sec_certs/utils
diff options
context:
space:
mode:
authoradamjanovsky2023-11-10 12:54:00 +0100
committerGitHub2023-11-10 12:54:00 +0100
commit1ccca9ae8afa8e6574e1cbba2c93b8d5428e2b2e (patch)
treec0c2f35f921f3551f2bf0a146c1cbd6c0494f7a9 /src/sec_certs/utils
parent5968e53d9f78d744c1bd151be0d754282e65baee (diff)
parent10aa312c5e83c197a2d41fec710c5301bfff169e (diff)
downloadsec-certs-1ccca9ae8afa8e6574e1cbba2c93b8d5428e2b2e.tar.gz
sec-certs-1ccca9ae8afa8e6574e1cbba2c93b8d5428e2b2e.tar.zst
sec-certs-1ccca9ae8afa8e6574e1cbba2c93b8d5428e2b2e.zip
Merge pull request #373 from crocs-muni/switch-black-to-ruff
switch black -> ruff format
Diffstat (limited to 'src/sec_certs/utils')
-rw-r--r--src/sec_certs/utils/extract.py2
-rw-r--r--src/sec_certs/utils/helpers.py6
-rw-r--r--src/sec_certs/utils/pandas.py4
-rw-r--r--src/sec_certs/utils/pdf.py3
4 files changed, 9 insertions, 6 deletions
diff --git a/src/sec_certs/utils/extract.py b/src/sec_certs/utils/extract.py
index 933db4b8..e6312b8d 100644
--- a/src/sec_certs/utils/extract.py
+++ b/src/sec_certs/utils/extract.py
@@ -353,7 +353,7 @@ def search_only_headers_bsi(filepath: Path): # noqa: C901
for m in re.finditer(rule_and_sep, whole_text):
# check if previous rules had at least one match
- if constants.TAG_CERT_ID not in items_found.keys():
+ if constants.TAG_CERT_ID not in items_found:
logger.error(f"ERROR: front page not found for file: {filepath}")
match_groups = m.groups()
diff --git a/src/sec_certs/utils/helpers.py b/src/sec_certs/utils/helpers.py
index 596ecf62..c103a2d3 100644
--- a/src/sec_certs/utils/helpers.py
+++ b/src/sec_certs/utils/helpers.py
@@ -28,7 +28,11 @@ def download_file(
time.sleep(delay)
# See https://github.com/psf/requests/issues/3953 for header justification
r = requests.get(
- url, allow_redirects=True, timeout=constants.REQUEST_TIMEOUT, stream=True, headers={"Accept-Encoding": None} # type: ignore
+ url,
+ allow_redirects=True,
+ timeout=constants.REQUEST_TIMEOUT,
+ stream=True,
+ headers={"Accept-Encoding": None}, # type: ignore
)
ctx: Any
if show_progress_bar:
diff --git a/src/sec_certs/utils/pandas.py b/src/sec_certs/utils/pandas.py
index 5b0a668d..661b669c 100644
--- a/src/sec_certs/utils/pandas.py
+++ b/src/sec_certs/utils/pandas.py
@@ -141,7 +141,7 @@ def get_sar_level_from_set(sars: set[SAR], sar_family: str) -> int | None:
Given a set of SARs and a family name, will return level of the seeked SAR from the set.
"""
family_sars_dict = {x.family: x for x in sars} if (sars and not pd.isnull(sars)) else {}
- if sar_family not in family_sars_dict.keys():
+ if sar_family not in family_sars_dict:
return None
return family_sars_dict[sar_family].level
@@ -211,7 +211,7 @@ def compute_cve_correlations(
tuples = list(
zip(n_cves_corrs, n_cves_pvalues, worst_cve_corrs, worst_cve_pvalues, avg_cve_corrs, avg_cve_pvalues, supports)
)
- dct = {family: correlations for family, correlations in zip(["eal"] + families, tuples)}
+ dct = dict(zip(["eal"] + families, tuples))
df_corr = pd.DataFrame.from_dict(
dct,
orient="index",
diff --git a/src/sec_certs/utils/pdf.py b/src/sec_certs/utils/pdf.py
index 7736b5d0..f2c2c58e 100644
--- a/src/sec_certs/utils/pdf.py
+++ b/src/sec_certs/utils/pdf.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import glob
import logging
import subprocess
from datetime import datetime, timedelta, timezone
@@ -54,7 +53,7 @@ def ocr_pdf_file(pdf_path: Path) -> str:
if ppm.returncode != 0:
raise ValueError(f"pdftoppm failed: {ppm.returncode}")
- for ppm_path in map(Path, glob.glob(str(tmppath / "image*.ppm"))):
+ for ppm_path in tmppath.rglob("image*.ppm"):
base = ppm_path.with_suffix("")
content = pytesseract.image_to_string(Image.open(ppm_path), lang="eng+deu+fra")