]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Applying flake8 rules to pp_lib/common.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Feb 2018 15:12:08 +0000 (16:12 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 6 Feb 2018 15:12:08 +0000 (16:12 +0100)
pp_lib/common.py

index de32918187043478be6a8a41909e59417d5f88de..55b6207e7f7d64ffabaf0e68861f0b0183c54c59 100644 (file)
@@ -21,7 +21,7 @@ import six
 
 # Own modules
 
-__version__ = '0.5.2'
+__version__ = '0.5.3'
 
 LOG = logging.getLogger(__name__)
 
@@ -295,7 +295,7 @@ def caller_search_path():
 # =============================================================================
 def compare_fqdn(x, y):
 
-    #LOG.debug("Comparing {!r} <=> {!r}.".format(x, y))
+    # LOG.debug("Comparing {!r} <=> {!r}.".format(x, y))
 
     # First check for None values
     if x is None and y is None:
@@ -305,6 +305,7 @@ def compare_fqdn(x, y):
     if y is None:
         return 1
 
+    # Check for empty FQDNs
     xs = str(x).strip().lower()
     ys = str(y).strip().lower()
 
@@ -315,12 +316,14 @@ def compare_fqdn(x, y):
     if ys == '':
         return 1
 
+    # Ensure a dot at end
     xs = RE_DOT_AT_END.sub('.', xs)
     ys = RE_DOT_AT_END.sub('.', ys)
 
     if xs == ys:
         return 0
 
+    # Reverse IPv4 zones first, then reverse IPv6 zones
     if RE_IPV4_PTR.search(xs):
         if not RE_IPV4_PTR.search(ys):
             return -1
@@ -334,6 +337,11 @@ def compare_fqdn(x, y):
         if not RE_IPV6_PTR.search(xs):
             return 1
 
+    return compare_fqdn_tokens(xs, ys)
+
+# =============================================================================
+def compare_fqdn_tokens(xs, ys):
+
     xa = RE_DOT.split(xs)
     xa.reverse()
     xa.pop(0)
@@ -342,6 +350,7 @@ def compare_fqdn(x, y):
     ya.reverse()
     ya.pop(0)
 
+    # Compare token from the last to the first
     nr_tokens = min(len(xa), len(ya))
     while nr_tokens > 0:
         token_x = xa.pop(0)