ruleset.py
changeset 23 9fa62cfd2821
parent 21 59540181a4bb
parent 19 62ee928ac9b3
child 32 4059dbe9f26a
equal deleted inserted replaced
19:62ee928ac9b3 23:9fa62cfd2821
    48     
    48     
    49     levels = ["init", "write", "read", "deny"]
    49     levels = ["init", "write", "read", "deny"]
    50 
    50 
    51     def __init__(self):
    51     def __init__(self):
    52         self.rules = []
    52         self.rules = []
       
    53         self.preset = {}
    53 
    54 
    54     def add(self, action, conditions):
    55     def add(self, action, conditions):
    55         self.rules.append((action, conditions))
    56         self.rules.append((action, conditions))
    56 
    57 
       
    58 
       
    59     def set(self, **kw):
       
    60         self.preset.update(kw)
       
    61         
    57     def matchrule(self, **kw):
    62     def matchrule(self, **kw):
       
    63         d = self.preset.copy()
       
    64         d.update(**kw)
    58         for a, c in self.rules:
    65         for a, c in self.rules:
    59             if c(**kw):
    66             if c(**d):
    60                 return a
    67                 return a
    61         return None
    68         return None
    62 
    69 
    63     def allow(self, level, **kw):
    70     def allow(self, level, **kw):
    64         a = self.matchrule(**kw)
    71         a = self.matchrule(**kw)
    76                 l = l.split()
    83                 l = l.split()
    77                 res.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
    84                 res.add(l[0], rule([c.split("=", 1) for c in l[1:]]))
    78         finally:
    85         finally:
    79             f.close()
    86             f.close()
    80         return res
    87         return res
    81 
       
    82