Fixed F841 (unused-variable)

This commit is contained in:
Teal Dulcet 2023-12-22 07:15:14 -08:00 committed by Joshua Tauberer
parent 2b426851f9
commit 13b38cc04d
7 changed files with 15 additions and 15 deletions

View File

@ -534,7 +534,7 @@ def list_target_files(config):
try: try:
b2_api.authorize_account("production", b2_application_keyid, b2_application_key) b2_api.authorize_account("production", b2_application_keyid, b2_application_key)
bucket = b2_api.get_bucket_by_name(b2_bucket) bucket = b2_api.get_bucket_by_name(b2_bucket)
except NonExistentBucket as e: except NonExistentBucket:
msg = "B2 Bucket does not exist. Please double check your information!" msg = "B2 Bucket does not exist. Please double check your information!"
raise ValueError(msg) raise ValueError(msg)
return [(key.file_name, key.size) for key, _ in bucket.ls()] return [(key.file_name, key.size) for key, _ in bucket.ls()]

View File

@ -174,7 +174,7 @@ def logout():
try: try:
email, _ = auth_service.authenticate(request, env, logout=True) email, _ = auth_service.authenticate(request, env, logout=True)
app.logger.info(f"{email} logged out") app.logger.info(f"{email} logged out")
except ValueError as e: except ValueError:
pass pass
finally: finally:
return json_response({ "status": "ok" }) return json_response({ "status": "ok" })

View File

@ -471,7 +471,7 @@ def build_sshfp_records():
for key in keys: for key in keys:
if key.strip() == "" or key[0] == "#": continue if key.strip() == "" or key[0] == "#": continue
try: try:
host, keytype, pubkey = key.split(" ") _host, keytype, pubkey = key.split(" ")
yield "%d %d ( %s )" % ( yield "%d %d ( %s )" % (
algorithm_number[keytype], algorithm_number[keytype],
2, # specifies we are using SHA-256 on next line 2, # specifies we are using SHA-256 on next line
@ -1049,19 +1049,19 @@ def set_secondary_dns(hostnames, env):
if not item.startswith("xfr:"): if not item.startswith("xfr:"):
# Resolve hostname. # Resolve hostname.
try: try:
response = resolver.resolve(item, "A") resolver.resolve(item, "A")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout): except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
try: try:
response = resolver.resolve(item, "AAAA") resolver.resolve(item, "AAAA")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout): except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
raise ValueError("Could not resolve the IP address of %s." % item) raise ValueError("Could not resolve the IP address of %s." % item)
else: else:
# Validate IP address. # Validate IP address.
try: try:
if "/" in item[4:]: if "/" in item[4:]:
v = ipaddress.ip_network(item[4:]) # raises a ValueError if there's a problem ipaddress.ip_network(item[4:]) # raises a ValueError if there's a problem
else: else:
v = ipaddress.ip_address(item[4:]) # raises a ValueError if there's a problem ipaddress.ip_address(item[4:]) # raises a ValueError if there's a problem
except ValueError: except ValueError:
raise ValueError("'%s' is not an IPv4 or IPv6 address or subnet." % item[4:]) raise ValueError("'%s' is not an IPv4 or IPv6 address or subnet." % item[4:])

View File

@ -332,7 +332,7 @@ def scan_mail_log_line(line, collector):
if not m: if not m:
return True return True
date, system, service, log = m.groups() date, _system, service, log = m.groups()
collector["scan_count"] += 1 collector["scan_count"] += 1
# print() # print()
@ -554,7 +554,7 @@ def scan_postfix_submission_line(date, log, collector):
m = re.match("([A-Z0-9]+): client=(\S+), sasl_method=(PLAIN|LOGIN), sasl_username=(\S+)(?<!,)", log) m = re.match("([A-Z0-9]+): client=(\S+), sasl_method=(PLAIN|LOGIN), sasl_username=(\S+)(?<!,)", log)
if m: if m:
_, client, method, user = m.groups() _, client, _method, user = m.groups()
if user_match(user): if user_match(user):
# Get the user data, or create it if the user is new # Get the user data, or create it if the user is new

View File

@ -449,7 +449,7 @@ def install_cert_copy_file(fn, env):
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
from binascii import hexlify from binascii import hexlify
cert = load_pem(load_cert_chain(fn)[0]) cert = load_pem(load_cert_chain(fn)[0])
all_domains, cn = get_certificate_domains(cert) _all_domains, cn = get_certificate_domains(cert)
path = "%s-%s-%s.pem" % ( path = "%s-%s-%s.pem" % (
safe_domain_name(cn), # common name, which should be filename safe because it is IDNA-encoded, but in case of a malformed cert make sure it's ok to use as a filename safe_domain_name(cn), # common name, which should be filename safe because it is IDNA-encoded, but in case of a malformed cert make sure it's ok to use as a filename
cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date cert.not_valid_after.date().isoformat().replace("-", ""), # expiration date
@ -521,7 +521,7 @@ def check_certificate(domain, ssl_certificate, ssl_private_key, warn_if_expiring
# First check that the domain name is one of the names allowed by # First check that the domain name is one of the names allowed by
# the certificate. # the certificate.
if domain is not None: if domain is not None:
certificate_names, cert_primary_name = get_certificate_domains(cert) certificate_names, _cert_primary_name = get_certificate_domains(cert)
# Check that the domain appears among the acceptable names, or a wildcard # Check that the domain appears among the acceptable names, or a wildcard
# form of the domain name (which is a stricter check than the specs but # form of the domain name (which is a stricter check than the specs but

View File

@ -124,7 +124,7 @@ def check_service(i, service, env):
try: try:
s.connect((ip, service["port"])) s.connect((ip, service["port"]))
return True return True
except OSError as e: except OSError:
# timed out or some other odd error # timed out or some other odd error
return False return False
finally: finally:
@ -294,7 +294,7 @@ def run_network_checks(env, output):
# Stop if we cannot make an outbound connection on port 25. Many residential # Stop if we cannot make an outbound connection on port 25. Many residential
# networks block outbound port 25 to prevent their network from sending spam. # networks block outbound port 25 to prevent their network from sending spam.
# See if we can reach one of Google's MTAs with a 5-second timeout. # See if we can reach one of Google's MTAs with a 5-second timeout.
code, ret = shell("check_call", ["/bin/nc", "-z", "-w5", "aspmx.l.google.com", "25"], trap=True) _code, ret = shell("check_call", ["/bin/nc", "-z", "-w5", "aspmx.l.google.com", "25"], trap=True)
if ret == 0: if ret == 0:
output.print_ok("Outbound mail (SMTP port 25) is not blocked.") output.print_ok("Outbound mail (SMTP port 25) is not blocked.")
else: else:

View File

@ -82,7 +82,7 @@ def pop_test():
M.user('fakeuser') M.user('fakeuser')
try: try:
M.pass_('fakepassword') M.pass_('fakepassword')
except poplib.error_proto as e: except poplib.error_proto:
# Authentication should fail. # Authentication should fail.
M = None # don't .quit() M = None # don't .quit()
return return
@ -133,7 +133,7 @@ def http_test(url, expected_status, postdata=None, qsargs=None, auth=None):
headers={'User-Agent': 'Mail-in-a-Box fail2ban tester'}, headers={'User-Agent': 'Mail-in-a-Box fail2ban tester'},
timeout=8, timeout=8,
verify=False) # don't bother with HTTPS validation, it may not be configured yet verify=False) # don't bother with HTTPS validation, it may not be configured yet
except requests.exceptions.ConnectTimeout as e: except requests.exceptions.ConnectTimeout:
raise IsBlocked() raise IsBlocked()
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
if "Connection refused" in str(e): if "Connection refused" in str(e):