Skip to content

Commit

Permalink
Fix various ruff/pylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hannob committed Dec 2, 2024
1 parent 2d8a007 commit e9cd973
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Empty file modified setup.py
100644 → 100755
Empty file.
27 changes: 11 additions & 16 deletions snallygaster
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # noqa: DUO


def DEFAULT(f):
setattr(f, "_is_default_test", True)
f._is_default_test = True
return f


def INFO(f):
setattr(f, "_is_info_test", True)
f._is_info_test = True
return f


def HOSTNAME(f):
setattr(f, "_is_hostname_test", True)
f._is_hostname_test = True
return f


Expand All @@ -78,11 +78,10 @@ def pout(cause, url, misc="", noisymsg=False):
duplicate_preventer.append(dup_check)
if args.json:
json_out.append({"cause": cause, "url": url, "misc": misc})
elif misc:
print(f"[{cause}] {url} {misc}")
else:
if misc:
print(f"[{cause}] {url} {misc}")
else:
print(f"[{cause}] {url}")
print(f"[{cause}] {url}")


def randstring():
Expand All @@ -100,8 +99,7 @@ def fetcher(fullurl, binary=False, getredir=False, geterrpage=False):
r = pool.request("GET", fullurl, retries=False, redirect=False)
if getredir:
headers = {k.lower(): v for k, v in r.headers.items()}
if "location" in headers:
redir = headers["location"]
redir = headers.get("location", "")
elif (r.status != 200 and not geterrpage):
data = ""
elif binary:
Expand Down Expand Up @@ -192,10 +190,7 @@ def getmainpage(url):
else:
data = ""
headers = {k.lower(): v for k, v in r.headers.items()}
if "location" in headers:
redir = headers["location"]
else:
redir = ""
redir = headers.get("location", "")
except (urllib3.exceptions.HTTPError, UnicodeError,
ConnectionRefusedError):
mainpage_cache[url] = {}
Expand Down Expand Up @@ -813,8 +808,8 @@ def test_axfr(qhost):
ConnectionResetError, ConnectionRefusedError,
EOFError, socket.gaierror, TimeoutError, OSError):
return
for r in ns.rrset:
r = str(r)
for rr in ns.rrset:
r = str(rr)
ipv4 = []
ipv6 = []
try:
Expand Down Expand Up @@ -1039,7 +1034,7 @@ if not args.nowww:
hosts.append("www." + h)

for i, h in enumerate(hosts):
if h.startswith("http://") or h.startswith("https://"):
if h.startswith(("http://", "https://")):
print("ERROR: Please run snallygaster with a hostname, not a URL.")
sys.exit(1)
try:
Expand Down
17 changes: 9 additions & 8 deletions tests/test_codingstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
class TestCodingstyle(unittest.TestCase):
@staticmethod
def test_codingstyle():
pyfiles = ["snallygaster", "setup.py"] + glob.glob("tests/*.py")
subprocess.run(["pycodestyle", "--ignore=W503", "--max-line-length=100"]
+ pyfiles, check=True)
subprocess.run(["pyflakes"] + pyfiles, check=True)
pyfiles = ["snallygaster", "setup.py", *glob.glob("tests/*.py")]
subprocess.run(["pycodestyle", "--ignore=W503", "--max-line-length=100",
*pyfiles], check=True)
subprocess.run(["pyflakes", *pyfiles], check=True)
subprocess.run(["pylint", "--disable=missing-docstring,invalid-name,"
"consider-using-with,too-many-lines"]
+ pyfiles, check=True)
subprocess.run(["flake8", "--select=DUO"] + pyfiles, check=True)
subprocess.run(["pyupgrade", "--py311-plus"] + pyfiles, check=True)
"consider-using-with,too-many-lines,"
"protected-access", *pyfiles],
check=True)
subprocess.run(["flake8", "--select=DUO", *pyfiles], check=True)
subprocess.run(["pyupgrade", "--py311-plus", *pyfiles], check=True)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_docs(self):
fd = open("TESTS.md", encoding="utf-8")
docs = []
ol = ""
for line in fd.readlines():
for line in fd:
if line.startswith("---"):
docs.append(ol.rstrip())
ol = line
Expand Down

0 comments on commit e9cd973

Please sign in to comment.