[Zope3-checkins] CVS: Zope3/src/zope/security - checker.py:1.32

Marius Gedminas mgedmin@codeworks.lt
Thu, 5 Jun 2003 07:56:25 -0400


Update of /cvs-repository/Zope3/src/zope/security
In directory cvs.zope.org:/tmp/cvs-serv14140/src/zope/security

Modified Files:
	checker.py 
Log Message:
Security checker debugging output now has verbosity levels.


=== Zope3/src/zope/security/checker.py 1.31 => 1.32 ===
--- Zope3/src/zope/security/checker.py:1.31	Thu Jun  5 07:45:03 2003
+++ Zope3/src/zope/security/checker.py	Thu Jun  5 07:56:25 2003
@@ -13,6 +13,13 @@
 ##############################################################################
 """
 $Id$
+
+You can set the environment variable ZOPE_WATCH_CHECKERS to get additional
+security checker debugging output on the standard error.
+
+Setting ZOPE_WATCH_CHECKERS to 1 will display messages about unauthorized or
+forbidden attribute access.  Setting it to a larger number will also display
+messages about granted attribute access.
 """
 
 import os
@@ -36,9 +43,12 @@
 __metaclass__ = type
 
 if os.environ.get('ZOPE_WATCH_CHECKERS'):
-    WATCH_CHECKERS = True
+    try:
+        WATCH_CHECKERS = int(os.environ.get('ZOPE_WATCH_CHECKERS'))
+    except ValueError:
+        WATCH_CHECKERS = 1
 else:
-    WATCH_CHECKERS = False
+    WATCH_CHECKERS = 0
 
 
 def ProxyFactory(object, checker=None):
@@ -347,15 +357,21 @@
 
     Prints verbose debugging information about every performed check to
     sys.stderr.
+
+    If verbosity is set to 1, only displays Unauthorized and Forbidden messages.
+    If verbosity is set to a larger number, displays all messages.
     """
 
+    verbosity = 1
+
     def check(self, object, name):
         try:
             super(CheckerLoggingMixin, self).check(object, name)
-            if name in _always_available:
-                print >> sys.stderr, '[CHK] + Always available: %s on %r' % (name, object)
-            else:
-                print >> sys.stderr, '[CHK] + Granted: %s on %r' % (name, object)
+            if self.verbosity > 1:
+                if name in _always_available:
+                    print >> sys.stderr, '[CHK] + Always available: %s on %r' % (name, object)
+                else:
+                    print >> sys.stderr, '[CHK] + Granted: %s on %r' % (name, object)
         except Unauthorized:
             print >> sys.stderr, '[CHK] - Unauthorized: %s on %r' % (name, object)
             raise
@@ -366,10 +382,11 @@
     def check_getattr(self, object, name):
         try:
             super(CheckerLoggingMixin, self).check(object, name)
-            if name in _always_available:
-                print >> sys.stderr, '[CHK] + Always available getattr: %s on %r' % (name, object)
-            else:
-                print >> sys.stderr, '[CHK] + Granted getattr: %s on %r' % (name, object)
+            if self.verbosity > 1:
+                if name in _always_available:
+                    print >> sys.stderr, '[CHK] + Always available getattr: %s on %r' % (name, object)
+                else:
+                    print >> sys.stderr, '[CHK] + Granted getattr: %s on %r' % (name, object)
         except Unauthorized:
             print >> sys.stderr, '[CHK] - Unauthorized getattr: %s on %r' % (name, object)
             raise
@@ -380,7 +397,8 @@
     def check_setattr(self, object, name):
         try:
             super(CheckerLoggingMixin, self).check_setattr(object, name)
-            print >> sys.stderr, '[CHK] + Granted setattr: %s on %r' % (name, object)
+            if self.verbosity > 1:
+                print >> sys.stderr, '[CHK] + Granted setattr: %s on %r' % (name, object)
         except Unauthorized:
             print >> sys.stderr, '[CHK] - Unauthorized setattr: %s on %r' % (name, object)
             raise
@@ -391,11 +409,11 @@
 
 if WATCH_CHECKERS:
     class Checker(CheckerLoggingMixin, Checker):
-        pass
+        verbosity = WATCH_CHECKERS
     class CombinedChecker(CheckerLoggingMixin, CombinedChecker):
-        pass
+        verbosity = WATCH_CHECKERS
     class DecoratedChecker(CheckerLoggingMixin, DecoratedChecker):
-        pass
+        verbosity = WATCH_CHECKERS
 
 
 # Helper class for __traceback_supplement__