mirror of
https://github.com/oskar456/dzonegit.git
synced 2024-05-11 05:55:41 +00:00
Refactor get_zone_origin()
This commit is contained in:
10
dzonegit.py
10
dzonegit.py
@@ -112,15 +112,15 @@ def get_altered_files(against, diff_filter=None):
|
||||
return (Path(p) for p in r.stdout.rstrip("\0").split("\0"))
|
||||
|
||||
|
||||
def get_zone_origin(zonedata, maxlines=10):
|
||||
def get_zone_origin(zonedata):
|
||||
"""
|
||||
Parse $ORIGIN directive in first maxlines lines of zone file.
|
||||
Parse $ORIGIN directive before the SOA record.
|
||||
Return zone name without the trailing dot.
|
||||
"""
|
||||
for i, line in enumerate(zonedata.splitlines()):
|
||||
if i >= maxlines:
|
||||
for line in zonedata.splitlines():
|
||||
if re.match(r"^[^\s;]+\s+([0-9]+\s+)?(IN\s+)?SOA\s+", line, re.I):
|
||||
break
|
||||
m = re.match(r"^\$ORIGIN\s+([^ ]+)\.\s*(;.*)?$", line)
|
||||
m = re.match(r"^\$ORIGIN\s+([^ ]+)\.\s*(;.*)?$", line, re.I)
|
||||
if m:
|
||||
return m.group(1).lower()
|
||||
|
||||
|
||||
@@ -88,16 +88,10 @@ $ORIGIN example.com.
|
||||
testzone = """
|
||||
@ 60 IN SOA ns hostmaster 1 60 60 60 60
|
||||
60 IN NS ns
|
||||
$ORIGIN example.com.
|
||||
ns.example.com. 60 IN A 192.0.2.1
|
||||
"""
|
||||
assert get_zone_origin(testzone) is None
|
||||
testzone = """
|
||||
@ 60 IN SOA ns hostmaster 1 60 60 60 60
|
||||
60 IN NS ns
|
||||
ns.example.com. 60 IN A 192.0.2.1
|
||||
$ORIGIN sub.example.com.
|
||||
"""
|
||||
assert get_zone_origin(testzone, 4) is None
|
||||
|
||||
|
||||
def test_get_zone_name():
|
||||
|
||||
Reference in New Issue
Block a user