src/mercurialserver/ruleset.py
changeset 109 72100d3ed1bd
parent 106 0519745e7a57
child 237 d30f3f312ece
equal deleted inserted replaced
108:00b48d7bdfa0 109:72100d3ed1bd
    25         for k, m in matchers:
    25         for k, m in matchers:
    26             if k not in kw or not m(kw[k]):
    26             if k not in kw or not m(kw[k]):
    27                 return False
    27                 return False
    28         return True
    28         return True
    29     return c
    29     return c
    30 
       
    31 class AccessException(Exception):
       
    32     pass
       
    33 
    30 
    34 class Ruleset(object):
    31 class Ruleset(object):
    35     '''Class representing the rules in a rule file'''
    32     '''Class representing the rules in a rule file'''
    36     
    33     
    37     levels = ["init", "write", "read", "deny"]
    34     levels = ["init", "write", "read", "deny"]
    59 
    56 
    60     def allow(self, level, **kw):
    57     def allow(self, level, **kw):
    61         a = self.matchrule(kw)
    58         a = self.matchrule(kw)
    62         return a in self.levels and self.levels.index(a) <= self.levels.index(level)
    59         return a in self.levels and self.levels.index(a) <= self.levels.index(level)
    63     
    60     
    64     def check(self, level, **kw):
       
    65         if not self.allow(level, **kw):
       
    66             raise AccessException()
       
    67     
       
    68     def readfile(self, fn):
    61     def readfile(self, fn):
    69         try:
    62         try:
    70             f = open(fn)
    63             f = open(fn)
    71             try:
    64             try:
    72                 for l in f:
    65                 for l in f: