Skip to content

Commit

Permalink
Typing + Improvement.
Browse files Browse the repository at this point in the history
  • Loading branch information
ausmaster committed Jun 26, 2024
1 parent 7816dfb commit 8b2f024
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from operator import itemgetter
from sys import stdout
from textwrap import wrap
from typing import Callable, Literal, Final
from typing import Callable, Literal, Final, Generator

import nltk
from nltk.tokenize import word_tokenize
Expand Down Expand Up @@ -41,7 +41,7 @@ def cve_to_str(cve: CVESchema) -> str:
"""


def gen_printable_cves(cve_cursor: Cursor[CVESchema]) -> str:
def gen_printable_cves(cve_cursor: Cursor[CVESchema]) -> Generator[str, None, None]:
"""
Generator function that creates a printable representation of each CVE
Expand All @@ -50,7 +50,6 @@ def gen_printable_cves(cve_cursor: Cursor[CVESchema]) -> str:
"""
for cve in cve_cursor:
yield cve_to_str(cve)
return ""


class VaultQuery:
Expand All @@ -67,7 +66,10 @@ def q_cve_id(self, cve_id: str) -> None:
:param cve_id: The CVE ID
:return: None
"""
print(cve_to_str(self.client.cves.find_one({"_id": cve_id})))
if cve := self.client.cves.find_one({"_id": cve_id}):
print(cve_to_str(cve))
else:
print(f"{cve_id} not found.")

def q_cpe_id(self, cpe_id: str) -> CPESchema | None:
"""
Expand Down

0 comments on commit 8b2f024

Please sign in to comment.