Skip to content

Commit

Permalink
flake8: fix E401, E722, F541 & W291
Browse files Browse the repository at this point in the history
- E401 multiple imports on one line
- E722 do not use bare 'except'
- F541 f-string is missing placeholders
- W291 trailing whitespace
  • Loading branch information
oh2fih committed Jul 29, 2024
1 parent 54998db commit 2c76323
Show file tree
Hide file tree
Showing 4 changed files with 35,901 additions and 24 deletions.
34 changes: 17 additions & 17 deletions bin/follow-cvelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, args: argparse.Namespace):

if not self.cvelist_repo():
print(
f"Current directory is not the cvelistV5 repository root",
"Current directory is not the cvelistV5 repository root",
file=sys.stderr,
)
exit(1)
Expand Down Expand Up @@ -106,7 +106,7 @@ def header(self):
)
try:
print(f"{''.ljust(os.get_terminal_size()[0], '-')}", file=sys.stderr)
except:
except OSError:
print(f"{''.ljust(80, '-')}", file=sys.stderr)

def history(self):
Expand Down Expand Up @@ -170,7 +170,7 @@ def print_changes(self, current_commit: str, past_commit: str):
else:
# substract one character to fit occasional wide characters like emojis
width = os.get_terminal_size()[0] - 1
except:
except OSError:
width = False

for change in self.get_changes(current_commit, past_commit):
Expand Down Expand Up @@ -316,9 +316,9 @@ def cvss31score(self, cve: dict) -> float:
if metric["cvssV3_1"]["version"] == "3.1":
cvss_adp = metric["cvssV3_1"]["baseScore"]
break
except:
except KeyError:
pass
except:
except KeyError:
pass

cvss_cna = 0.0
Expand All @@ -329,9 +329,9 @@ def cvss31score(self, cve: dict) -> float:
if metric["cvssV3_1"]["version"] == "3.1":
cvss_cna = metric["cvssV3_1"]["baseScore"]
break
except:
except KeyError:
pass
except:
except KeyError:
pass

cvss = max(cvss_adp, cvss_cna)
Expand All @@ -347,9 +347,9 @@ def cvss40score(self, cve: dict) -> float:
if metric["cvssV4_0"]["version"] == "4.0":
cvss_cna = metric["cvssV4_0"]["baseScore"]
break
except:
except KeyError:
pass
except:
except KeyError:
pass
return float("%0.1f" % cvss_cna)

Expand All @@ -359,38 +359,38 @@ def generate_summary(self, cve: dict) -> str:
description = ""
try:
title = cve["containers"]["cna"]["title"]
except:
except KeyError:
try:
for description in cve["containers"]["cna"]["descriptions"]:
if description["lang"] in ("en", "en-US", "en_US"):
description = description["value"]
title = ""
break
except:
except KeyError:
try:
# This is not a very good title, but a last resort.
title = cve["containers"]["adp"][0]["title"]
except:
except KeyError:
pass

vendor = ""
try:
vendor = cve["containers"]["adp"][0]["affected"][0]["vendor"]
except:
except KeyError:
try:
if cve["containers"]["cna"]["affected"][0]["vendor"] != "n/a":
vendor = cve["containers"]["cna"]["affected"][0]["vendor"]
except:
except KeyError:
pass

product = ""
try:
product = cve["containers"]["adp"][0]["affected"][0]["product"]
except:
except KeyError:
try:
if cve["containers"]["cna"]["affected"][0]["product"] != "n/a":
product = cve["containers"]["cna"]["affected"][0]["product"]
except:
except KeyError:
pass

# Title is typically short and likely contains the vendor and product, whereas
Expand Down Expand Up @@ -452,7 +452,7 @@ def cvelist_repo(self):
if "# CVE List V5" in line:
return True
return False
except:
except (FileNotFoundError, PermissionError):
return False


Expand Down
15 changes: 9 additions & 6 deletions bin/make-mac-prefixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
# Author : Esa Jokinen (oh2fih)
# ------------------------------------------------------------------------------

import sys, os, csv, re
import sys
import os
import csv
import re

# Sort the list by MAC prefix: True = sort, False = preserve original order.
SORT = False

HEADER = """\
# MAC prefix list generated with make-mac-prefixes.py by Esa Jokinen (oh2fih).
# Original data comes from IEEE's https://standards-oui.ieee.org/oui/oui.csv
# These values are known as Organizationally Unique Identifiers (OUIs) in
# These values are known as Organizationally Unique Identifiers (OUIs) in
# MAC Address Block Large (MA-L) including large blocks of EUI-48 and EUI-64.
# See https://standards.ieee.org/products-programs/regauth/\
"""
Expand Down Expand Up @@ -48,7 +51,7 @@ def main(csvdata):
print(f"# Invalid prefix '{Row[1]}' in {Row}", file=sys.stderr)

if not OUIs:
print(f"# Incorrect input format; oui.csv expected.", file=sys.stderr)
print("# Incorrect input format; oui.csv expected.", file=sys.stderr)
exit(1)
else:
print(f"# Found {len(OUIs)} registed OUIs.", file=sys.stderr)
Expand All @@ -59,7 +62,7 @@ def main(csvdata):

if SORT:
OUIs.sort()
print(f"# Sorted by MAC prefix.", file=sys.stderr)
print("# Sorted by MAC prefix.", file=sys.stderr)
return OUIs


Expand Down Expand Up @@ -106,7 +109,7 @@ def validatePrefix(prefix):
if __name__ == "__main__":
"""Reads oui.csv from stdin & print nmap-mac-prefixes to stdout"""
if os.isatty(sys.stdin.fileno()):
print(f"# Please provide oui.csv from a pipe.", file=sys.stderr)
print("# Please provide oui.csv from a pipe.", file=sys.stderr)
exit(1)
print(f"{HEADER}")
print(f"\n".join(main(sys.stdin)))
print("\n".join(main(sys.stdin)))
2 changes: 1 addition & 1 deletion bin/test-cache-enabler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def getCacheTime(page):
try:
cached = re.search(b"<!-- Cache Enabler by KeyCDN (.*) -->", page).group(1)
return cached.decode("utf-8")
except:
except AttributeError:
return "Not cached."


Expand Down
Loading

0 comments on commit 2c76323

Please sign in to comment.