Skip to content

Commit

Permalink
perf: reposition build_role_links()
Browse files Browse the repository at this point in the history
Signed-off-by: Zxilly <zhouxinyu1001@gmail.com>
  • Loading branch information
Zxilly committed Feb 25, 2021
1 parent d4780fd commit 396ef7a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions casbin/core_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def load_filtered_policy(self, filter):
self.model.print_policy()
if self.auto_build_role_links:
self.build_role_links()
def load_increment_filtered_policy(self,filter):

def load_increment_filtered_policy(self, filter):
"""LoadIncrementalFilteredPolicy append a filtered policy from file/database."""
if not hasattr(self.adapter, "is_filtered"):
raise ValueError("filtered policies are not supported by this adapter")
Expand Down Expand Up @@ -214,7 +214,8 @@ def build_role_links(self):

for rm in self.rm_map.values():
rm.clear()
self.model.build_role_links(self.rm_map)

self.model.build_role_links(self.rm_map)

def add_named_matching_func(self, ptype, fn):
"""add_named_matching_func add MatchingFunc by ptype RoleManager"""
Expand Down Expand Up @@ -261,7 +262,7 @@ def enforce(self, *rvals):

exp_string = self.model.model["m"]["m"].value
has_eval = util.has_eval(exp_string)
if not has_eval:
if not has_eval:
expression = self._get_expression(exp_string, functions)

policy_effects = set()
Expand Down Expand Up @@ -346,12 +347,10 @@ def enforce(self, *rvals):

return result



@staticmethod
def _get_expression(expr, functions=None):
expr = expr.replace("&&", "and")
expr = expr.replace("||", "or")
expr = expr.replace("!","not")
expr = expr.replace("!", "not")

return SimpleEval(expr, functions)

0 comments on commit 396ef7a

Please sign in to comment.