[svn] commit: r1930 - /branches/tingting-loadzone/src/lib/python/isc/datasrc/master.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed May 26 08:16:50 UTC 2010
Author: shentingting
Date: Wed May 26 08:16:49 2010
New Revision: 1930
Log:
support extension ttl in rr and directive. the ttl formal can be numeric string or extension form, but which must match ([0-9]+[wdhms]?)+ regular expression
Modified:
branches/tingting-loadzone/src/lib/python/isc/datasrc/master.py
Modified: branches/tingting-loadzone/src/lib/python/isc/datasrc/master.py
==============================================================================
--- branches/tingting-loadzone/src/lib/python/isc/datasrc/master.py (original)
+++ branches/tingting-loadzone/src/lib/python/isc/datasrc/master.py Wed May 26 08:16:49 2010
@@ -104,7 +104,7 @@
# isttl: check whether a string is a valid TTL specifier.
# returns: boolean
#########################################################################
-ttl_regex = re.compile('[0-9]+[wdhms]?', re.I)
+ttl_regex = re.compile('([0-9]+[wdhms]?)+', re.I)
def isttl(s):
global ttl_regex
if ttl_regex.match(s):
@@ -123,19 +123,25 @@
# MasterFileError
#########################################################################
def parse_ttl(s):
- m = re.match('([0-9]+)(.*)', s)
- if not m:
- raise MasterFileError('Invalid TTL: ' + s)
- ttl, suffix = int(m.group(1)), m.group(2)
- if suffix.lower() == 'w':
- ttl *= 604800
- elif suffix.lower() == 'd':
- ttl *= 86400
- elif suffix.lower() == 'h':
- ttl *= 3600
- elif suffix.lower() == 'm':
- ttl *= 60
- return str(ttl)
+ group = re.split('([0-9]+[wdhms]?)', s, 0, re.I)
+ sum = 0
+ for el in group:
+ if not el:
+ continue
+ m = re.match('([0-9]+)(.*)', el)
+ if not m:
+ raise MasterFileError('Invalid TTL: ' + s)
+ ttl, suffix = int(m.group(1)), m.group(2)
+ if suffix.lower() == 'w':
+ ttl *= 604800
+ elif suffix.lower() == 'd':
+ ttl *= 86400
+ elif suffix.lower() == 'h':
+ ttl *= 3600
+ elif suffix.lower() == 'm':
+ ttl *= 60
+ sum += ttl
+ return str(sum)
#########################################################################
# records: generator function to return complete RRs from the zone file,
@@ -499,6 +505,12 @@
if not MasterFile.__ttl and not ttl:
MasterFile.__ttl = MasterFile.__ttl or parse_ttl(soa[-1])
ttl = MasterFile.__ttl
+
+ for index in range(3, len(soa)):
+ if isttl(soa[index]):
+ soa[index] = parse_ttl(soa[index])
+ else :
+ raise MasterFileError("No TTL specified; in soa record!")
rdata = ' '.join(soa)
if not ttl:
More information about the bind10-changes
mailing list