From: Frank Brehm Date: Tue, 6 Feb 2018 15:12:08 +0000 (+0100) Subject: Applying flake8 rules to pp_lib/common.py X-Git-Tag: 0.1.2~6^2~27 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=33fe8fd8e8b8380c0ec92df28a4c19a764b875a4;p=pixelpark%2Fadmin-tools.git Applying flake8 rules to pp_lib/common.py --- diff --git a/pp_lib/common.py b/pp_lib/common.py index de32918..55b6207 100644 --- a/pp_lib/common.py +++ b/pp_lib/common.py @@ -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)