]> git.ipfire.org Git - dnsbl.git/commitdiff
util: Refactor is_fqdn
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 17:10:49 +0000 (17:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Dec 2025 17:10:49 +0000 (17:10 +0000)
No functional changes.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/util.py

index 02924dde8c374f42bbffaf7761cb6b48c19bed70..126984c044acd0e9d976a3da0bae3911d5d831d0 100644 (file)
@@ -93,14 +93,14 @@ def is_fqdn(s):
                return False
 
        # Remove final dot
-       if s.endswith("."):
-               s = s[:-1]
+       s = s.removesuffix(".")
 
-       labels = s.split(".")
-
-       for label in labels:
+       for label in s.split("."):
+               # Labels cannot be empty and must be shorter than 64 characters
                if not 1 <= len(label) <= 63:
                        return False
+
+               # Labels my only contain alpha-numerical characters as well as dash and underscore
                for ch in label:
                        if not ch.isalnum() or ch in "-_":
                                return False