[Checkins] SVN: zope.security/trunk/ - Added compatibility with Python 2.6 abstract base classes.

Jim Fulton jim at zope.com
Tue Nov 10 09:35:16 EST 2009


Log message for revision 105559:
  - Added compatibility with Python 2.6 abstract base classes.
  

Changed:
  U   zope.security/trunk/CHANGES.txt
  U   zope.security/trunk/src/zope/security/checker.py
  U   zope.security/trunk/src/zope/security/tests/test_standard_checkers.py

-=-
Modified: zope.security/trunk/CHANGES.txt
===================================================================
--- zope.security/trunk/CHANGES.txt	2009-11-10 13:49:51 UTC (rev 105558)
+++ zope.security/trunk/CHANGES.txt	2009-11-10 14:35:15 UTC (rev 105559)
@@ -2,9 +2,11 @@
 CHANGES
 =======
 
-3.7.2 (unreleased)
+3.7.2 (2009-11-10)
 ------------------
 
+- Added compatibility with Python 2.6 abstract base classes.
+
 3.7.1 (2009-08-13)
 ------------------
 

Modified: zope.security/trunk/src/zope/security/checker.py
===================================================================
--- zope.security/trunk/src/zope/security/checker.py	2009-11-10 13:49:51 UTC (rev 105558)
+++ zope.security/trunk/src/zope/security/checker.py	2009-11-10 14:35:15 UTC (rev 105559)
@@ -727,12 +727,16 @@
     zope.interface.declarations.Declaration: _Declaration_checker,
 }
 
-if sys.version_info[:2] < (2, 6):
+if sys.version_info < (2, 6):
     import sets
     _default_checkers[sets.Set] = _setChecker
     _default_checkers[sets.ImmutableSet] = _setChecker
 
+if sys.version_info >= (2, 6):
+    import abc
+    _default_checkers[abc.ABCMeta] = _typeChecker
 
+
 def _clear():
     _checkers.clear()
     _checkers.update(_default_checkers)

Modified: zope.security/trunk/src/zope/security/tests/test_standard_checkers.py
===================================================================
--- zope.security/trunk/src/zope/security/tests/test_standard_checkers.py	2009-11-10 13:49:51 UTC (rev 105558)
+++ zope.security/trunk/src/zope/security/tests/test_standard_checkers.py	2009-11-10 14:35:15 UTC (rev 105559)
@@ -15,12 +15,11 @@
 
 This is a test of the assertions made in
 zope.security.checkers._default_checkers.
-
-$Id$
 """
 from zope.security.checker import ProxyFactory, NamesChecker
 from zope.security.interfaces import ForbiddenAttribute
 
+import sys
 
 def check_forbidden_get(object, attr):
     try:
@@ -490,7 +489,66 @@
     True
     """
 
+if sys.version_info >= (2, 6):
+    def test_ABCMeta():
+        """
+        Test that we work with the ABCMeta meta class
 
+        >>> import abc
+        >>> class MyABC:
+        ...     __metaclass__ = abc.ABCMeta
+
+        >>> class Foo(MyABC): pass
+
+        >>> class Bar(Foo): pass
+
+        >>> PBar = ProxyFactory(Bar)
+        >>> [c.__name__ for c in PBar.__mro__]
+        ['Bar', 'Foo', 'MyABC', 'object']
+
+        >>> issubclass(PBar, Foo)
+        True
+
+        >>> issubclass(Bar, Foo)
+        True
+
+        >>> PBar = ProxyFactory(PBar)
+        >>> check_forbidden_call(PBar)
+        'ForbiddenAttribute: __call__'
+        >>> check_forbidden_get(PBar, '__dict__')
+        'ForbiddenAttribute: __dict__'
+        >>> s = str(PBar)
+        >>> s = `PBar`
+        >>> int(PBar.__module__ == __name__)
+        1
+        >>> len(PBar.__bases__)
+        1
+
+        Always available:
+
+        >>> int(PBar < PBar)
+        0
+        >>> int(PBar > PBar)
+        0
+        >>> int(PBar <= PBar)
+        1
+        >>> int(PBar >= PBar)
+        1
+        >>> int(PBar == PBar)
+        1
+        >>> int(PBar != PBar)
+        0
+        >>> int(bool(PBar))
+        1
+        >>> int(PBar.__class__ == abc.ABCMeta)
+        1
+
+
+
+        """
+
+
+
 from zope.testing.doctestunit import DocTestSuite
 
 def test_suite():



More information about the checkins mailing list