src/mercurialserver/ruleset.py
changeset 301 f88549f44c8e
parent 300 31c2c6b383fd
child 311 3cbde66305e4
equal deleted inserted replaced
300:31c2c6b383fd 301:f88549f44c8e
    40 
    40 
    41     def __init__(self):
    41     def __init__(self):
    42         self.rules = []
    42         self.rules = []
    43         self.preset = {}
    43         self.preset = {}
    44 
    44 
    45     def add(self, action, conditions):
       
    46         # Unrecognized actions are off the high end
       
    47         if action in self.levels:
       
    48             self.rules.append((self.levels.index(action), conditions))
       
    49         else:
       
    50             self.rules.append((len(self.levels), conditions))
       
    51 
       
    52     def set(self, **kw):
    45     def set(self, **kw):
    53         self.preset.update(kw)
    46         self.preset.update(kw)
    54         
    47         
    55     def get(self, k):
    48     def get(self, k):
    56         return self.preset.get(k, None)
    49         return self.preset.get(k, None)
    76             for l in f:
    69             for l in f:
    77                 l = l.strip()
    70                 l = l.strip()
    78                 if len(l) == 0 or l.startswith("#"):
    71                 if len(l) == 0 or l.startswith("#"):
    79                     continue
    72                     continue
    80                 l = l.split()
    73                 l = l.split()
    81                 self.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
    74                 # Unrecognized actions are off the high end
       
    75                 if l[0] in self.levels:
       
    76                     ix = self.levels.index(l[0])
       
    77                 else:
       
    78                     ix = len(self.levels)
       
    79                 self.rules.append((ix, 
       
    80                     rule([c.split("=", 1) for c in l[1:]])))
    82         finally:
    81         finally:
    83             f.close()
    82             f.close()
    84 
    83 
    85 rules = Ruleset()
    84 rules = Ruleset()
    86 
    85