diff options
| author | adamjanovsky | 2023-11-10 12:54:00 +0100 |
|---|---|---|
| committer | GitHub | 2023-11-10 12:54:00 +0100 |
| commit | 1ccca9ae8afa8e6574e1cbba2c93b8d5428e2b2e (patch) | |
| tree | c0c2f35f921f3551f2bf0a146c1cbd6c0494f7a9 /src | |
| parent | 5968e53d9f78d744c1bd151be0d754282e65baee (diff) | |
| parent | 10aa312c5e83c197a2d41fec710c5301bfff169e (diff) | |
| download | sec-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')
| -rw-r--r-- | src/sec_certs/dataset/dataset.py | 4 | ||||
| -rw-r--r-- | src/sec_certs/dataset/fips_algorithm.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/model/matching.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/sample/cc.py | 15 | ||||
| -rw-r--r-- | src/sec_certs/sample/fips.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/sample/sar.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/utils/extract.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/utils/helpers.py | 6 | ||||
| -rw-r--r-- | src/sec_certs/utils/pandas.py | 4 | ||||
| -rw-r--r-- | src/sec_certs/utils/pdf.py | 3 |
10 files changed, 22 insertions, 20 deletions
diff --git a/src/sec_certs/dataset/dataset.py b/src/sec_certs/dataset/dataset.py index 9e49a347..454e86bd 100644 --- a/src/sec_certs/dataset/dataset.py +++ b/src/sec_certs/dataset/dataset.py @@ -502,7 +502,7 @@ class Dataset(Generic[CertSubType, AuxiliaryDatasetsSubType], ComplexSerializabl candidates = [cpe_dset[x].title for x in cert.heuristics.cpe_matches] candidates += ["No good match"] * (config.cpe_n_max_matches - len(candidates)) options = ["option_" + str(x) for x in range(1, config.cpe_n_max_matches)] - dct.update({o: c for o, c in zip(options, candidates)}) + dct.update(dict(zip(options, candidates))) lst.append(dct) with Path(output_path).open("w") as handle: @@ -634,6 +634,6 @@ class Dataset(Generic[CertSubType, AuxiliaryDatasetsSubType], ComplexSerializabl Enriches the dataset with `certs` :param List[Certificate] certs: new certs to include into the dataset. """ - if any([x not in self for x in certs]): + if any(x not in self for x in certs): logger.warning("Updating dataset with certificates outside of the dataset!") self.certs.update({x.dgst: x for x in certs}) diff --git a/src/sec_certs/dataset/fips_algorithm.py b/src/sec_certs/dataset/fips_algorithm.py index fbc8351a..f3f27c0b 100644 --- a/src/sec_certs/dataset/fips_algorithm.py +++ b/src/sec_certs/dataset/fips_algorithm.py @@ -82,7 +82,7 @@ class FIPSAlgorithmDataset(JSONPathDataset, ComplexSerializableType): if failed_tuples: failed_urls, failed_paths = zip(*failed_tuples) responses = helpers.download_parallel(failed_urls, failed_paths) - if any([x != constants.RESPONSE_OK for x in responses]): + if any(x != constants.RESPONSE_OK for x in responses): raise ValueError("Failed to download the algorithms HTML data, the dataset won't be constructed.") return paths diff --git a/src/sec_certs/model/matching.py b/src/sec_certs/model/matching.py index 7e48f878..9c0591f9 100644 --- a/src/sec_certs/model/matching.py +++ b/src/sec_certs/model/matching.py @@ -28,7 +28,7 @@ class AbstractMatcher(Generic[CertSubType], ABC): ) @staticmethod - def _match_certs(matchers: Sequence["AbstractMatcher"], certs: list[CertSubType], threshold: float): + def _match_certs(matchers: Sequence[AbstractMatcher], certs: list[CertSubType], threshold: float): scores: list[tuple[float, int, int]] = [] matched_is: set[int] = set() matched_js: set[int] = set() diff --git a/src/sec_certs/sample/cc.py b/src/sec_certs/sample/cc.py index c89f67c6..f2087eeb 100644 --- a/src/sec_certs/sample/cc.py +++ b/src/sec_certs/sample/cc.py @@ -247,7 +247,7 @@ class CCCertificate( st_filename: str | None = field(default=None) def __bool__(self) -> bool: - return any([x is not None for x in vars(self)]) + return any(x is not None for x in vars(self)) @property def bsi_data(self) -> dict[str, Any] | None: @@ -612,13 +612,12 @@ class CCCertificate( ) for att, val in vars(self).items(): - if not val: - setattr(self, att, getattr(other, att)) - elif other_source == "html" and att == "protection_profiles": - setattr(self, att, getattr(other, att)) - elif other_source == "html" and att == "maintenance_updates": - setattr(self, att, getattr(other, att)) - elif att == "state": + if ( + (not val) + or (other_source == "html" and att == "protection_profiles") + or (other_source == "html" and att == "maintenance_updates") + or (att == "state") + ): setattr(self, att, getattr(other, att)) else: if getattr(self, att) != getattr(other, att): diff --git a/src/sec_certs/sample/fips.py b/src/sec_certs/sample/fips.py index 26510191..e0bcb74a 100644 --- a/src/sec_certs/sample/fips.py +++ b/src/sec_certs/sample/fips.py @@ -64,7 +64,7 @@ class FIPSHTMLParser: ) entries = [(FIPSHTMLParser.normalize_string(key.text), entry) for key, entry in entries] entries = [parse_single_detail_entry(*x) for x in entries if x[0] in DETAILS_KEY_NORMALIZATION_DICT] - entries = {x: y for x, y in entries} + entries = dict(entries) if "caveat" in entries: entries["mentioned_certs"] = FIPSHTMLParser.get_mentioned_certs_from_caveat(entries["caveat"]) diff --git a/src/sec_certs/sample/sar.py b/src/sec_certs/sample/sar.py index 8f48f417..e3d7bd2b 100644 --- a/src/sec_certs/sample/sar.py +++ b/src/sec_certs/sample/sar.py @@ -50,7 +50,7 @@ class SAR(ComplexSerializableType): @staticmethod def matches_re(string: str) -> bool: return any( - [re.match(sar_class + "(?:_[A-Z]{3,4}){1,2}(?:\\.[0-9]){0,2}", string) for sar_class in SAR_CLASS_MAPPING] + re.match(sar_class + "(?:_[A-Z]{3,4}){1,2}(?:\\.[0-9]){0,2}", string) for sar_class in SAR_CLASS_MAPPING ) def __lt__(self, other: Any) -> bool: 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") |
