[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Add new parse function to handle retry intervals



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv2000/lib/mixminion

Modified Files:
	Config.py 
Log Message:
Add new parse function to handle retry intervals

Index: Config.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Config.py,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- Config.py	8 Jan 2003 07:56:24 -0000	1.34
+++ Config.py	13 Jan 2003 06:15:10 -0000	1.35
@@ -60,7 +60,8 @@
 
 import mixminion.Common
 import mixminion.Crypto
-from mixminion.Common import MixError, LOG, isPrintingAscii, stripSpace
+from mixminion.Common import MixError, LOG, ceilDiv, isPrintingAscii, \
+   stripSpace, stringContains
 
 class ConfigError(MixError):
     """Thrown when an error is found in a configuration file."""
@@ -99,8 +100,8 @@
     return s
 
 # re to match strings of the form '9 seconds', '1 month', etc.
-_interval_re = re.compile(r'''(\d+\.?\d*|\.\d+)\s+
-                     (sec|second|min|minute|hour|day|week|mon|month|year)s?''',
+_interval_re = re.compile(r'''^(\d+\.?\d*|\.\d+)\s+
+                     (sec|second|min|minute|hour|day|week|mon|month|year)s?$''',
                           re.X)
 _seconds_per_unit = {
     'second': 1,
@@ -127,6 +128,33 @@
     nsec = num * _seconds_per_unit[unit]
     return num, _canonical_unit_names.get(unit,unit), nsec
 
+
+def _parseIntervalList(s):
+    """DOCDOC"""
+    items = s.strip().lower().split(",")
+    ilist = []
+    for item in items:
+        item = item.strip()
+        if stringContains(item, " for "):
+            if item.startswith("every "):
+                item = item[6:]
+            interval, duration = item.split(" for ", 1)
+            interval = int(_parseInterval(interval)[2])
+            duration = int(_parseInterval(duration)[2])
+            if interval < 1:
+                raise ConfigError("Repeated interval too small in %s"%s)
+
+            for _ in xrange(ceilDiv(duration, interval)):
+                ilist.append(interval)
+        elif item.startswith("every "):
+            raise ConfigError(
+                "Bad syntax on interval %s. (Did you mean %s for X days?)",
+                item, item)
+        else:
+            interval = _parseInterval(item)[2]
+            ilist.append(interval)
+    return ilist
+
 def _parseInt(integer):
     """Validation function.  Converts a config value to an int.
        Raises ConfigError on failure."""
@@ -137,7 +165,7 @@
         raise ConfigError("Expected an integer but got %r" % (integer))
 
 # Regular expression to match a dotted quad.
-_ip_re = re.compile(r'\d+\.\d+\.\d+\.\d+')
+_ip_re = re.compile(r'^\d+\.\d+\.\d+\.\d+$')
 
 def _parseIP(ip):
     """Validation function.  Converts a config value to an IP address.
@@ -158,12 +186,12 @@
 
 # Regular expression to match 'address sets' as used in Allow/Deny
 # configuration lines. General format is "<IP|*> ['/'MASK] [PORT['-'PORT]]"
-_address_set_re = re.compile(r'''(\d+\.\d+\.\d+\.\d+|\*)
+_address_set_re = re.compile(r'''^(\d+\.\d+\.\d+\.\d+|\*)
                                  \s*
                                  (?:/\s*(\d+\.\d+\.\d+\.\d+))?\s*
                                  (?:(\d+)\s*
                                            (?:-\s*(\d+))?
-                                        )?''',re.X)
+                                        )?$''',re.X)
 def _parseAddressSet_allow(s, allowMode=1):
     """Validation function.  Converts an address set string of the form
        'IP/mask port-port' into a tuple of (IP, Mask, Portmin, Portmax).
@@ -256,7 +284,7 @@
     return key
 
 # Regular expression to match YYYY/MM/DD
-_date_re = re.compile(r"(\d\d\d\d)/(\d\d)/(\d\d)")
+_date_re = re.compile(r"^(\d\d\d\d)/(\d\d)/(\d\d)$")
 def _parseDate(s):
     """Validation function.  Converts from YYYY/MM/DD format to a (long)
        time value for midnight on that date."""
@@ -271,7 +299,7 @@
     return calendar.timegm((yyyy,MM,dd,0,0,0,0,0,0))
 
 # Regular expression to match YYYY/MM/DD HH:MM:SS
-_time_re = re.compile(r"(\d\d\d\d)/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d)")
+_time_re = re.compile(r"^(\d\d\d\d)/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d)$")
 def _parseTime(s):
     """Validation function.  Converts from YYYY/MM/DD HH:MM:SS format
        to a (float) time value for GMT."""