summaryrefslogtreecommitdiff
path: root/repoze/bfg/security.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-01-22 08:08:02 +0000
committerChris McDonough <chrism@agendaless.com>2009-01-22 08:08:02 +0000
commitf662908175abb6ac9c638dbdeeea2635956ac80c (patch)
tree77911b9c9a3aa14dc4ed6cb3b496a35499c77c54 /repoze/bfg/security.py
parent2bb9b76c01019f3c82776429c07d34bd1c439f2b (diff)
downloadpyramid-f662908175abb6ac9c638dbdeeea2635956ac80c.tar.gz
pyramid-f662908175abb6ac9c638dbdeeea2635956ac80c.tar.bz2
pyramid-f662908175abb6ac9c638dbdeeea2635956ac80c.zip
- 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.
Diffstat (limited to 'repoze/bfg/security.py')
-rw-r--r--repoze/bfg/security.py38
1 files changed, 25 insertions, 13 deletions
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