pvl.dns.labels: handle origin=.
authorTero Marttila <tero.marttila@aalto.fi>
Thu, 26 Feb 2015 18:54:15 +0200
changeset 515 996ccf5356b8
parent 514 f19d86b20f24
child 516 9615ffc647a0
pvl.dns.labels: handle origin=.
pvl/dns/labels.py
--- a/pvl/dns/labels.py	Thu Feb 26 18:42:43 2015 +0200
+++ b/pvl/dns/labels.py	Thu Feb 26 18:54:15 2015 +0200
@@ -19,12 +19,22 @@
     
     return fqdn
 
+def contains (origin, fqdn):
+    """
+        Determine if the given FQDN is within the given origin.
+    """
+
+    return origin == '.' or fqdn.endswith('.' + origin)
+
 def split (origin, fqdn):
     """
         Determine the relative label from the given zone origin to the given host fqnd.
     """
 
-    if fqdn.endswith('.' + origin) :
+    if origin == '.':
+        return fqdn[:-1]
+
+    elif fqdn.endswith('.' + origin) :
         # strip
         return fqdn[:(len(fqdn) - len(origin) - 1)]
     else:
@@ -56,6 +66,8 @@
         Traceback (most recent call last):
             ...
         ValueError: host.domain: fqdn host.domain. out of zone origin.
+        >>> print relative('.', 'domain', 'host')
+        host.domain
     """
 
     if origin:
@@ -73,7 +85,7 @@
     elif domain == origin:
          return name
 
-    elif host_fqdn.endswith('.' + origin):
+    elif contains(origin, host_fqdn):
         return split(origin, host_fqdn)
 
     elif domain: