コード例 #1
0
    def add_def(self, sec, key, value):
        if value == "":
            return

        ast = Assertion()
        ast.key = key
        ast.value = value

        if "r" == sec or "p" == sec:
            ast.tokens = ast.value.split(",")
            for i,token in enumerate(ast.tokens):
                ast.tokens[i] = key + "_" + token.strip()
        else:
            ast.value = util.remove_comments(util.escape_assertion(ast.value))

        if sec not in self.model.keys():
            self.model[sec] = {}

        self.model[sec][key] = ast

        return True
コード例 #2
0
ファイル: test_util.py プロジェクト: casbin/pycasbin
 def test_escape_assertion(self):
     self.assertEqual(
         util.escape_assertion("m = r.sub == p.sub && r.obj == p.obj && r.act == p.act"),
         "m = r_sub == p_sub && r_obj == p_obj && r_act == p_act",
     )