[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - Exceptions.py:1.1.2.1 protectClass.py:1.1.2.7
Paul Everitt
paul@zope.com
Thu, 28 Feb 2002 18:22:05 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv3926
Modified Files:
Tag: Zope-3x-branch
protectClass.py
Added Files:
Tag: Zope-3x-branch
Exceptions.py
Log Message:
Added checks for misspelled permission ids.
=== Added File Zope3/lib/python/Zope/App/Security/Exceptions.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
Revision information:
$Id: Exceptions.py,v 1.1.2.1 2002/02/28 23:22:04 paul Exp $
"""
class UndefinedPermissionError(Exception):
"""Somebody tried to use a permission before it was defined.
"""
=== Zope3/lib/python/Zope/App/Security/protectClass.py 1.1.2.6 => 1.1.2.7 ===
from Zope.Configuration.name import resolve
from Interface.Method import Method
+from Exceptions import UndefinedPermissionError
+from PermissionRegistry import permissionRegistry
from Zope.Configuration.ConfigurationDirectiveInterfaces \
import INonEmptyDirective
@@ -61,6 +63,13 @@
else:
return permission_id
+ def __checkPermission(self, permission_id):
+ """Check to make sure that the permission is valid.
+ """
+
+ if not permissionRegistry.definedPermission(permission_id):
+ raise UndefinedPermissionError(permission_id)
+
def protect(self, permission_id=None, interface=None,
method=None, methods=None):
"Protect a specific aspect"
@@ -92,6 +101,7 @@
return r
def __inst(self, permission_id):
+ self.__checkPermission(permission_id)
self.__class.__permission__ = permission_id
def __instances(self, permission_id, r):
@@ -109,6 +119,7 @@
def __method(self, method, permission_id):
"Set a permission on a particular method."
+ self.__checkPermission(permission_id)
m = getattr(self.__class, method)
try:
setattr(m, "__permission__", permission_id)