[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ - Use zapi.isinstance() as appropriate.

Fred L. Drake, Jr. fdrake at gmail.com
Wed Sep 1 11:51:16 EDT 2004


Log message for revision 27385:
  - Use zapi.isinstance() as appropriate.
    
    Always use zapi.isinstance(o) instead of isinstance(removeSecurityProxy(o))
    when the unproxied object is not otherwise needed.
  
  - Explain a call to removeSecurityProxy() that can't be removed, but
    isn't obvious in context.
  
  (merged from ZopeX3-3.0 branch revisions 27378, 27384)
  


Changed:
  U   Zope3/trunk/src/zope/app/component/tests/test_factory.py
  U   Zope3/trunk/src/zope/app/interface/vocabulary.py
  U   Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py


-=-
Modified: Zope3/trunk/src/zope/app/component/tests/test_factory.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_factory.py	2004-09-01 15:42:18 UTC (rev 27384)
+++ Zope3/trunk/src/zope/app/component/tests/test_factory.py	2004-09-01 15:51:16 UTC (rev 27385)
@@ -21,7 +21,6 @@
 from zope.configuration.xmlconfig import xmlconfig
 from zope.configuration.xmlconfig import XMLConfig
 from zope.component import createObject
-from zope.security.proxy import removeSecurityProxy
 from zope.app.tests.placelesssetup import PlacelessSetup
 
 from zope.app import zapi
@@ -64,9 +63,7 @@
 </content>''')
         xmlconfig(f)
         obj = createObject(None, 'test.Example')
-        # isinstance() doesn't work with proxies, so remove if present
-        obj = removeSecurityProxy(obj)
-        self.failUnless(isinstance(obj, ExampleClass))
+        self.failUnless(zapi.isinstance(obj, ExampleClass))
 
 def test_suite():
     loader=unittest.TestLoader()

Modified: Zope3/trunk/src/zope/app/interface/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/interface/vocabulary.py	2004-09-01 15:42:18 UTC (rev 27384)
+++ Zope3/trunk/src/zope/app/interface/vocabulary.py	2004-09-01 15:51:16 UTC (rev 27385)
@@ -52,6 +52,8 @@
     """
 
     def __init__(self, context):
+        # Remove the security proxy so the values from the vocabulary
+        # are the actual interfaces and not proxies.
         component = removeSecurityProxy(context)
         interfaces = providedBy(component).flattened()
         terms = [SimpleTerm(interface, interfaceToName(context, interface))

Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py	2004-09-01 15:42:18 UTC (rev 27384)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py	2004-09-01 15:51:16 UTC (rev 27385)
@@ -99,14 +99,13 @@
         resource = DirectoryResourceFactory(path, checker, 'files')(request)
 
         image = resource['test.gif']
-        self.assert_(isinstance(removeSecurityProxy(image), FileResource))
+        self.assert_(zapi.isinstance(image, FileResource))
         template = resource['test.pt']
-        self.assert_(isinstance(removeSecurityProxy(template),
-                                PageTemplateResource))
+        self.assert_(zapi.isinstance(template, PageTemplateResource))
         file = resource['test.txt']
-        self.assert_(isinstance(removeSecurityProxy(file), FileResource))
+        self.assert_(zapi.isinstance(file, FileResource))
         file = resource['png']
-        self.assert_(isinstance(removeSecurityProxy(file), FileResource))
+        self.assert_(zapi.isinstance(file, FileResource))
 
 def test_suite():
     return makeSuite(Test)



More information about the Zope3-Checkins mailing list