From f662908175abb6ac9c638dbdeeea2635956ac80c Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 22 Jan 2009 08:08:02 +0000 Subject: - The Allowed and Denied classes in ``repoze.bfg.security`` now are lazier about constructing the representation of a reason message for speed; ``repoze.bfg.view_execution_permitted`` takes advantage of this. - The ``is_response`` check was sped up by about half at the expense of making its code slightly uglier. --- repoze/bfg/security.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'repoze/bfg/security.py') diff --git a/repoze/bfg/security.py b/repoze/bfg/security.py index 1f7c80028..ccc223919 100644 --- a/repoze/bfg/security.py +++ b/repoze/bfg/security.py @@ -231,8 +231,13 @@ class Denied(PermitsResult): or other ``repoze.bfg`` code denies an action unlrelated to an ACL check. It evaluates equal to all boolean false types. It has an attribute named ``msg`` describing the circumstances for the deny.""" - def __init__(self, msg): - self.msg = msg + def __init__(self, s, *args): + self.s = s + self.args = args + + @property + def msg(self): + return self.s % self.args def __nonzero__(self): return False @@ -246,8 +251,13 @@ class Allowed(PermitsResult): check. It evaluates equal to all boolean true types. It has an attribute named ``msg`` describing the circumstances for the allow.""" - def __init__(self, msg): - self.msg = msg + def __init__(self, s, *args): + self.s = s + self.args = args + + @property + def msg(self): + return self.s % self.args def __nonzero__(self): return True @@ -262,15 +272,17 @@ class ACLPermitsResult: self.acl = acl self.principals = principals self.context = context - msg = ('%s permission %r via ACE %r in ACL %r on context %r for ' - 'principals %r') - msg = msg % (self.__class__.__name__, - self.permission, - self.ace, - self.acl, - self.context, - self.principals) - self.msg = msg + + @property + def msg(self): + s = ('%s permission %r via ACE %r in ACL %r on context %r for ' + 'principals %r') + return s % (self.__class__.__name__, + self.permission, + self.ace, + self.acl, + self.context, + self.principals) class ACLDenied(ACLPermitsResult, Denied): """ An instance of ``ACLDenied`` represents that a security check -- cgit v1.2.3