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:
b2_api.authorize_account("production", b2_application_keyid, b2_application_key)
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!"
raise ValueError(msg)
return [(key.file_name, key.size) for key, _ in bucket.ls()]

View File

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

View File

@ -471,7 +471,7 @@ def build_sshfp_records():
for key in keys:
if key.strip() == "" or key[0] == "#": continue
try:
host, keytype, pubkey = key.split(" ")
_host, keytype, pubkey = key.split(" ")
yield "%d %d ( %s )" % (
algorithm_number[keytype],
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:"):
# Resolve hostname.
try:
response = resolver.resolve(item, "A")
resolver.resolve(item, "A")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
try:
response = resolver.resolve(item, "AAAA")
resolver.resolve(item, "AAAA")
except (dns.resolver.NoNameservers, dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
raise ValueError("Could not resolve the IP address of %s." % item)
else:
# Validate IP address.
try:
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:
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:
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:
return True
date, system, service, log = m.groups()
date, _system, service, log = m.groups()
collector["scan_count"] += 1
# 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)
if m:
_, client, method, user = m.groups()
_, client, _method, user = m.groups()
if user_match(user):
# 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 binascii import hexlify
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" % (
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
@ -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
# the certificate.
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
# 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:
s.connect((ip, service["port"]))
return True
except OSError as e:
except OSError:
# timed out or some other odd error
return False
finally:
@ -294,7 +294,7 @@ def run_network_checks(env, output):
# 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.
# 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:
output.print_ok("Outbound mail (SMTP port 25) is not blocked.")
else:

View File

@ -82,7 +82,7 @@ def pop_test():
M.user('fakeuser')
try:
M.pass_('fakepassword')
except poplib.error_proto as e:
except poplib.error_proto:
# Authentication should fail.
M = None # don't .quit()
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'},
timeout=8,
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()
except requests.exceptions.ConnectionError as e:
if "Connection refused" in str(e):