# Own modules
-__version__ = '0.5.2'
+__version__ = '0.5.3'
LOG = logging.getLogger(__name__)
# =============================================================================
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:
if y is None:
return 1
+ # Check for empty FQDNs
xs = str(x).strip().lower()
ys = str(y).strip().lower()
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
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)
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)