[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/ Moved the
proxy-aware isinstance to zope.security.proxy
Jim Fulton
jim at zope.com
Fri Aug 27 20:43:48 EDT 2004
Log message for revision 27318:
Moved the proxy-aware isinstance to zope.security.proxy
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/__init__.py
D Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/tests.py
U Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py
U Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_proxy.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/__init__.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/__init__.py 2004-08-28 00:13:56 UTC (rev 27317)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/__init__.py 2004-08-28 00:43:48 UTC (rev 27318)
@@ -21,7 +21,7 @@
from interfaces import IZAPI
from zope.interface import moduleProvides
-from zope.security.proxy import removeSecurityProxy
+from zope.security.proxy import isinstance
from zope.app import servicenames
from zope.app.interface import queryType
@@ -36,38 +36,3 @@
from zope.app.exception.interfaces import UserError
name = getName
-
-builtin_isinstance = isinstance
-def isinstance(object, cls):
- """Test whether an object is an instance of a type.
-
- This works even if the object is security proxied:
-
- >>> class C1(object):
- ... pass
-
- >>> c = C1()
- >>> isinstance(c, C1)
- True
-
- >>> from zope.security.checker import ProxyFactory
- >>> isinstance(ProxyFactory(c), C1)
- True
-
- >>> class C2(C1):
- ... pass
-
- >>> c = C2()
- >>> isinstance(c, C1)
- True
-
- >>> from zope.security.checker import ProxyFactory
- >>> isinstance(ProxyFactory(c), C1)
- True
-
- """
-
- # The removeSecurityProxy call is OK here because it is *only*
- # being used for isinstance
-
- return builtin_isinstance(removeSecurityProxy(object), cls)
Deleted: Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/tests.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/tests.py 2004-08-28 00:13:56 UTC (rev 27317)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/zapi/tests.py 2004-08-28 00:43:48 UTC (rev 27318)
@@ -1,28 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Test zapi-provided implementation
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-
-def test_suite():
- return unittest.TestSuite((
- DocTestSuite('zope.app.zapi.__init__'),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py 2004-08-28 00:13:56 UTC (rev 27317)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py 2004-08-28 00:43:48 UTC (rev 27318)
@@ -54,3 +54,39 @@
items = checker.get_permissions.items()
items.sort()
return items
+
+
+builtin_isinstance = isinstance
+def isinstance(object, cls):
+ """Test whether an object is an instance of a type.
+
+ This works even if the object is security proxied:
+
+ >>> class C1(object):
+ ... pass
+
+ >>> c = C1()
+ >>> isinstance(c, C1)
+ True
+
+ >>> from zope.security.checker import ProxyFactory
+ >>> isinstance(ProxyFactory(c), C1)
+ True
+
+ >>> class C2(C1):
+ ... pass
+
+ >>> c = C2()
+ >>> isinstance(c, C1)
+ True
+
+ >>> from zope.security.checker import ProxyFactory
+ >>> isinstance(ProxyFactory(c), C1)
+ True
+
+ """
+
+ # The removeSecurityProxy call is OK here because it is *only*
+ # being used for isinstance
+
+ return builtin_isinstance(removeSecurityProxy(object), cls)
Modified: Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_proxy.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_proxy.py 2004-08-28 00:13:56 UTC (rev 27317)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_proxy.py 2004-08-28 00:43:48 UTC (rev 27318)
@@ -436,6 +436,7 @@
suite = unittest.makeSuite(ProxyTests)
from doctest import DocTestSuite
suite.addTest(DocTestSuite())
+ suite.addTest(DocTestSuite('zope.security.proxy'))
return suite
if __name__=='__main__':
More information about the Zope3-Checkins
mailing list