diff options
| author | Adam Janovsky | 2023-02-02 13:50:55 +0100 |
|---|---|---|
| committer | Adam Janovsky | 2023-02-02 13:50:55 +0100 |
| commit | 94bd822d6defb26afb7c06c729bba707f92222be (patch) | |
| tree | 3d9aba4212e6f1a229cc27d5939a2ddb2ea091d0 | |
| parent | df3ded1c6d45cf6c813b0ee7a8c14d2656664709 (diff) | |
| download | sec-certs-94bd822d6defb26afb7c06c729bba707f92222be.tar.gz sec-certs-94bd822d6defb26afb7c06c729bba707f92222be.tar.zst sec-certs-94bd822d6defb26afb7c06c729bba707f92222be.zip | |
ruff enforce pathlib
| -rw-r--r-- | pyproject.toml | 1 | ||||
| -rw-r--r-- | src/sec_certs/dataset/fips.py | 2 | ||||
| -rw-r--r-- | src/sec_certs/utils/extract.py | 45 |
3 files changed, 26 insertions, 22 deletions
diff --git a/pyproject.toml b/pyproject.toml index 5b17dfc7..2e4e0c10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,6 +100,7 @@ "C90", # mccabe "UP", # pyupgrade "PL", # pylint + "PTH", # enforce pathlib usage ] ignore = [ "E501", # line-length, should be handled by black diff --git a/src/sec_certs/dataset/fips.py b/src/sec_certs/dataset/fips.py index f6292dca..14bcfcf1 100644 --- a/src/sec_certs/dataset/fips.py +++ b/src/sec_certs/dataset/fips.py @@ -198,7 +198,7 @@ class FIPSDataset(Dataset[FIPSCertificate, FIPSAuxillaryDatasets], ComplexSerial ) def _get_certificates_from_html(self, html_file: Path) -> list[FIPSCertificate]: - with open(html_file, encoding="utf-8") as handle: + with html_file.open("r", encoding="utf-8") as handle: html = BeautifulSoup(handle.read(), "html5lib") table = [x for x in html.find(id="searchResultsTable").tbody.contents if x != "\n"] diff --git a/src/sec_certs/utils/extract.py b/src/sec_certs/utils/extract.py index 37d79f73..82808ca9 100644 --- a/src/sec_certs/utils/extract.py +++ b/src/sec_certs/utils/extract.py @@ -6,7 +6,7 @@ import re from collections import Counter from enum import Enum from pathlib import Path -from typing import Any, Iterator +from typing import Any import numpy as np @@ -585,11 +585,6 @@ def search_only_headers_canada(filepath: Path): # noqa: C901 return constants.RETURNCODE_OK, items_found -def search_files(folder: str | Path) -> Iterator[str]: - for root, _, files in os.walk(str(folder)): - yield from [os.path.join(root, x) for x in files] - - def flatten_matches(dct: dict) -> dict: """ Function to flatten dictionary of matches. @@ -719,7 +714,7 @@ def load_text_file( logger.warning("UnicodeDecodeError, opening as utf8") if was_unicode_decode_error: - with open(file_name, encoding="utf8", errors=FILE_ERRORS_STRATEGY) as f2: + with Path(file_name).open("r", encoding="utf8", errors=FILE_ERRORS_STRATEGY) as f2: # coding failure, try line by line line = " " while line: @@ -746,23 +741,31 @@ def load_text_file( return whole_text, whole_text_with_newlines, was_unicode_decode_error -def load_cert_html_file(file_name: str) -> str: - with open(file_name, errors=FILE_ERRORS_STRATEGY) as f: - try: - return f.read() - except UnicodeDecodeError: - logger.warning("UnicodeDecodeError, opening as utf8") +def rules_get_subset(desired_path: str) -> dict: + """ + + + + + + + + + + + + + + + + + + + + - with open(file_name, encoding="utf8", errors=FILE_ERRORS_STRATEGY) as f2: - try: - return f2.read() - except UnicodeDecodeError: - logger.error(f"Failed to read file {file_name}") - return "" -def rules_get_subset(desired_path: str) -> dict: - """ Recursively applies cc_certs.get(key) on tokens from desired_path, returns the keys of the inner-most layer. """ |
