[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/ Deprecated zope.security.trustedRemoveSecurityProxy and

Jim Fulton jim at zope.com
Fri Aug 20 13:02:04 EDT 2004


Log message for revision 27188:
  Deprecated zope.security.trustedRemoveSecurityProxy and
  zope.security.getProxiedObject. Use zope.security.removeSecurityProxy
  instead.  (This should also be used rather than removeAllProxies.)
  


Changed:
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/component/localservice.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/i18n/browser/synchronize.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/interface/vocabulary.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/publication/zopepublication.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/security/adapter.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/zopepolicy.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/app/utility/browser/__init__.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/security/checker.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_checker.py
  U   Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_proxy.py


-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/component/localservice.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/component/localservice.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/component/localservice.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -24,7 +24,7 @@
 from zope.testing.cleanup import addCleanUp
 from zope.app.component.hooks import setSite
 from zope.component.service import IGlobalServiceManager
-from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.security.proxy import removeSecurityProxy
 
 # placeful service manager convenience tools
 
@@ -77,7 +77,7 @@
     """
     services = getLocalServices(context).next
     if IGlobalServiceManager.providedBy(services):
-        services = trustedRemoveSecurityProxy(services)
+        services = removeSecurityProxy(services)
     return services
 
 def queryNextServices(context, default=None):

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/container/contained.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -16,7 +16,6 @@
 $Id$
 """
 
-from zope.proxy import getProxiedObject
 from zope.exceptions import DuplicationError
 from zope.security.checker import selectChecker, CombinedChecker
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/i18n/browser/synchronize.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/i18n/browser/synchronize.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/i18n/browser/synchronize.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -20,7 +20,7 @@
 import xmlrpclib
 from base64 import encodestring
 
-from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.security.proxy import removeSecurityProxy
 
 from zope.app.i18n.browser import BaseView
 from zope.app.i18n import ZopeMessageIDFactory as _
@@ -122,7 +122,7 @@
 
     def queryMessageItems(self):
         items = self.queryMessages().items()
-        items = trustedRemoveSecurityProxy(items)
+        items = removeSecurityProxy(items)
         items.sort(lambda x, y: cmp(x[0][0] + x[0][1], y[0][0]+y[0][1]))
         return items
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/interface/vocabulary.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/interface/vocabulary.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/interface/vocabulary.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -16,7 +16,7 @@
 $Id$
 """
 from zope.interface import providedBy
-from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.security.proxy import removeSecurityProxy
 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 
 from zope.app.introspector import interfaceToName
 
@@ -50,7 +50,7 @@
     """
 
     def __init__(self, context):
-        component = trustedRemoveSecurityProxy(context)
+        component = removeSecurityProxy(context)
         interfaces = providedBy(component).flattened()
         terms = [SimpleTerm(interface, interfaceToName(context, interface))
                  for interface in interfaces]

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/publication/zopepublication.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/publication/zopepublication.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/publication/zopepublication.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -31,7 +31,7 @@
 from zope.publisher.interfaces import IRequest, IPublication
 from zope.security.management import newInteraction, endInteraction
 from zope.security.checker import ProxyFactory
-from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.security.proxy import removeSecurityProxy
 
 from zope.app import zapi
 from zope.app.applicationcontrol.applicationcontrol \
@@ -170,7 +170,7 @@
         txn.setUser(request.principal.id)
 
         # Work around methods that are usually used for views
-        bare = trustedRemoveSecurityProxy(ob)
+        bare = removeSecurityProxy(ob)
         if isinstance(bare, instancemethod):
             ob = bare.im_self
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/security/adapter.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/security/adapter.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/security/adapter.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -17,7 +17,7 @@
 """
 
 from zope.security.checker import ProxyFactory
-from zope.security.proxy import getProxiedObject
+from zope.security.proxy import removeSecurityProxy
 from zope.app.location import ILocation, Location
 
 class TrustedAdapterFactory(object):
@@ -68,7 +68,7 @@
        And the object proxied is not.  (We actually have to remove the
        adapter to get to the adapted object in this case.)
 
-         >>> a = getProxiedObject(a)
+         >>> a = removeSecurityProxy(a)
          >>> type(a.context).__name__
          'list'
 
@@ -86,14 +86,14 @@
          >>> a = TM(p, o2, o3)
          >>> type(a).__name__
          '_Proxy'
-         >>> a = getProxiedObject(a)
+         >>> a = removeSecurityProxy(a)
          >>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3
          (True, True, True)
 
          >>> a = TM(p, ProxyFactory(o2), ProxyFactory(o3))
          >>> type(a).__name__
          '_Proxy'
-         >>> a = getProxiedObject(a)
+         >>> a = removeSecurityProxy(a)
          >>> a.context[0] is o, a.context[1] is o2, a.context[2] is o3
          (True, True, True)
 
@@ -116,10 +116,11 @@
 
          >>> TL(o).__parent__ is o
          True
-         >>> getProxiedObject(TL(p)).__parent__ is o
+         >>> removeSecurityProxy(TL(p)).__parent__ is o
          True
 
-       The factory adapter has the __name__ and __module__ of the factory it adapts:
+       The factory adapter has the __name__ and __module__ of the
+       factory it adapts:
 
          >>> (TA.__module__, TA.__name__) == (A.__module__, A.__name__)
          True
@@ -133,8 +134,8 @@
 
     def __call__(self, *args):
         for arg in args:
-            if getProxiedObject(arg) is not arg:
-                args = map(getProxiedObject, args)
+            if removeSecurityProxy(arg) is not arg:
+                args = map(removeSecurityProxy, args)
                 adapter = self.factory(*args)
                 if (ILocation.providedBy(adapter)
                     and adapter.__parent__ is None):

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/zopepolicy.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/zopepolicy.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/securitypolicy/zopepolicy.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -21,7 +21,7 @@
 from zope.security.management import system_user
 from zope.security.simplepolicies import ParanoidSecurityPolicy
 from zope.security.interfaces import ISecurityPolicy
-from zope.security.proxy import getProxiedObject
+from zope.security.proxy import removeSecurityProxy
 
 from zope.app.security.settings import Allow, Deny
 
@@ -125,7 +125,7 @@
                 cache_prin_per[permission] = prinper
                 return prinper
 
-        parent = getProxiedObject(getattr(parent, '__parent__', None))
+        parent = removeSecurityProxy(getattr(parent, '__parent__', None))
         prinper = self.cached_prinper(parent, principal, permission)
         cache_prin_per[permission] = prinper
         return prinper
@@ -152,7 +152,7 @@
             return roles
 
         roles = self.cached_roles(
-            getProxiedObject(getattr(parent, '__parent__', None)),
+            removeSecurityProxy(getattr(parent, '__parent__', None)),
             permission)
         roleper = IRolePermissionMap(parent, None)
         if roleper:
@@ -189,7 +189,7 @@
             return roles
             
         roles = self.cached_principal_roles(
-            getProxiedObject(getattr(parent, '__parent__', None)),
+            removeSecurityProxy(getattr(parent, '__parent__', None)),
             principal)
         prinrole = IPrincipalRoleMap(parent, None)
         if prinrole:
@@ -215,8 +215,8 @@
         if not principals:
             return True
 
-        object = getProxiedObject(object)
-        parent = getProxiedObject(getattr(object, '__parent__', None))
+        object = removeSecurityProxy(object)
+        parent = removeSecurityProxy(getattr(object, '__parent__', None))
 
         grant_info = IGrantInfo(object, None)
         if not grant_info:

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/utility/browser/__init__.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/utility/browser/__init__.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/utility/browser/__init__.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -21,7 +21,7 @@
 from zope.app.registration.interfaces import UnregisteredStatus
 from zope.app import zapi
 from zope.interface import providedBy
-from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.security.proxy import removeSecurityProxy
 from zope.app.introspector import interfaceToName
 
 
@@ -173,7 +173,7 @@
         folder = zapi.getParent(self.context)
         iface = folder.resolve(self.request['interface'])
         name = self.request['name']
-        iface = trustedRemoveSecurityProxy(iface)
+        iface = removeSecurityProxy(iface)
         regstack = self.context.queryRegistrations(name, iface)
         form = zapi.getView(regstack, "ChangeRegistrations", self.request)
         form.update()

Modified: Zope3/branches/ZopeX3-3.0/src/zope/security/checker.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/checker.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/checker.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -372,10 +372,6 @@
 
 _getChecker = _checkers.get
 
-
-# Marker type used by bogus zope.security.proxy.trustedRemoveSecurityProxy
-TrustedCheckerBase = Checker
-
 class CombinedChecker(Checker):
     """A checker that combines two other checkers in a logical-or fashion.
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/proxy.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -16,31 +16,33 @@
 $Id$
 """
 
+from warnings import warn
+
 from zope.security._proxy import getChecker, getObject
 from zope.security._proxy import _Proxy as Proxy
-from zope.security.checker import TrustedCheckerBase
 
-getProxiedObject = getObject
 removeSecurityProxy = getObject
 
 # This import represents part of the API for this module
 from zope.security.checker import ProxyFactory
 
 def trustedRemoveSecurityProxy(object):
-    """Remove a security proxy if its checker came from a trusted source.
+    """Deprecated, use removeSecurityProxy instead"""
+    warn("trustedRemoveSecurityProxy is deprecated."
+         " It will disappear in Zope X3.1. "
+         " Use removeSecurityProxy instead",
+         DeprecationWarning, 2)
 
-    The rationale is that it is OK to do this since the caller is
-    trusted and the proxy can always be recreated by calling the
-    proxy factory and getting back a proxy with the same checker.
+    return removeSecurityProxy(object)
 
-    TODO: More thought needs to be given to assuring this contract.
-    """
-    if ((type(object) is Proxy) and
-        isinstance(getChecker(object), TrustedCheckerBase)
-        ):
-        return getProxiedObject(object)
+def getProxiedObject(object):
+    """Deprecated, use removeSecurityProxy instead"""
+    warn("getProxiedObject is deprecated."
+         " It will disappear in Zope X3.1. "
+         " Use removeSecurityProxy instead",
+         DeprecationWarning, 2)
 
-    return object
+    return removeSecurityProxy(object)
 
 def getTestProxyItems(proxy):
     """Try to get checker names and permissions for testing

Modified: Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_checker.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_checker.py	2004-08-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_checker.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -25,7 +25,7 @@
 from zope.security.interfaces import Unauthorized
 from zope.security.management import setSecurityPolicy, newInteraction
 from zope.security.management import endInteraction, getInteraction
-from zope.proxy import getProxiedObject
+from zope.security.proxy import removeSecurityProxy
 from zope.security.proxy import getChecker
 from zope.security.checker import defineChecker, ProxyFactory
 from zope.security.proxy import Proxy
@@ -218,7 +218,7 @@
 
             for ob in inst, class_:
                 proxy = checker.proxy(ob)
-                self.failUnless(getProxiedObject(proxy) is ob)
+                self.failUnless(removeSecurityProxy(proxy) is ob)
                 checker = getChecker(proxy)
                 if ob is inst:
                     self.assertEqual(checker.permission_id('__str__'),
@@ -235,7 +235,7 @@
             #
             #for ob in inst, TransparentProxy(inst):
             #    proxy = checker.proxy(ob)
-            #    self.failUnless(getProxiedObject(proxy) is ob)
+            #    self.failUnless(removeSecurityProxy(proxy) is ob)
             #
             #    checker = getChecker(proxy)
             #    self.failUnless(checker is special,

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-19 20:57:07 UTC (rev 27187)
+++ Zope3/branches/ZopeX3-3.0/src/zope/security/tests/test_proxy.py	2004-08-20 17:02:03 UTC (rev 27188)
@@ -17,7 +17,7 @@
 """
 
 import unittest
-from zope.security.proxy import getChecker, ProxyFactory, getProxiedObject
+from zope.security.proxy import getChecker, ProxyFactory, removeSecurityProxy
 from zope.proxy import ProxyBase as proxy
 
 class Checker(object):
@@ -119,7 +119,7 @@
                         s)
 
     def testGetAttrOK(self):
-        self.assertEqual(getProxiedObject(self.p.foo), [1,2,3])
+        self.assertEqual(removeSecurityProxy(self.p.foo), [1,2,3])
 
     def testGetAttrFail(self):
         self.assertRaises(RuntimeError, lambda: self.p.bar)
@@ -169,7 +169,7 @@
         self.shouldFail(lambda: self.p == self.x)
 
     def testIterOK(self):
-        self.assertEqual(getProxiedObject(iter(self.p)), self.x)
+        self.assertEqual(removeSecurityProxy(iter(self.p)), self.x)
 
     def testIterFail(self):
         self.shouldFail(iter, self.p)
@@ -205,7 +205,7 @@
         self.shouldFail(len, self.p)
 
     def testSliceOK(self):
-        self.assertEqual(getProxiedObject(self.p[:]), [42])
+        self.assertEqual(removeSecurityProxy(self.p[:]), [42])
 
     def testSliceFail(self):
         self.shouldFail(lambda: self.p[:])
@@ -224,7 +224,7 @@
         self.shouldFail(lambda: 42 in self.p)
 
     def testGetObject(self):
-        self.assertEqual(self.x, getProxiedObject(self.p))
+        self.assertEqual(self.x, removeSecurityProxy(self.p))
 
     def testGetChecker(self):
         self.assertEqual(self.c, getChecker(self.p))
@@ -260,7 +260,7 @@
             # Make sure 'x' is a proxy always:
             x = ProxyFactory(1, self.c)
             z = eval(expr)
-            self.assertEqual(getProxiedObject(z), y,
+            self.assertEqual(removeSecurityProxy(z), y,
                              "x=%r; expr=%r" % (x, expr))
             self.shouldFail(lambda x: eval(expr), x)
 
@@ -286,7 +286,7 @@
                         z = eval(expr)
                         first = 0
                     else:
-                        self.assertEqual(getProxiedObject(eval(expr)), z,
+                        self.assertEqual(removeSecurityProxy(eval(expr)), z,
                                          "x=%r; y=%r; expr=%r" % (x, y, expr))
                         self.shouldFail(lambda x, y: eval(expr), x, y)
 
@@ -296,7 +296,7 @@
 
         pa = P(1)
         pa += 2
-        self.assertEqual(getProxiedObject(pa), 3)
+        self.assertEqual(removeSecurityProxy(pa), 3)
 
         a = [1, 2, 3]
         pa = qa = P(a)
@@ -311,7 +311,7 @@
 
         pa = P(2)
         pa **= 2
-        self.assertEqual(getProxiedObject(pa), 4)
+        self.assertEqual(removeSecurityProxy(pa), 4)
 
         def doit():
             pa = P(2)
@@ -333,16 +333,16 @@
         x = P(1)
         y = P(2.1)
         a, b = coerce(x, y)
-        self.failUnless(getProxiedObject(a) == 1.0 and b is y)
+        self.failUnless(removeSecurityProxy(a) == 1.0 and b is y)
         if fixed_coerce:
-            self.failUnless(type(getProxiedObject(a)) is float and b is y)
+            self.failUnless(type(removeSecurityProxy(a)) is float and b is y)
 
         x = P(1.1)
         y = P(2)
         a, b = coerce(x, y)
-        self.failUnless(a is x and getProxiedObject(b) == 2.0)
+        self.failUnless(a is x and removeSecurityProxy(b) == 2.0)
         if fixed_coerce:
-            self.failUnless(a is x and type(getProxiedObject(b)) is float)
+            self.failUnless(a is x and type(removeSecurityProxy(b)) is float)
 
         x = P(1)
         y = 2
@@ -352,12 +352,12 @@
         x = P(1)
         y = 2.1
         a, b = coerce(x, y)
-        self.failUnless(type(getProxiedObject(a)) is float and b is y)
+        self.failUnless(type(removeSecurityProxy(a)) is float and b is y)
 
         x = P(1.1)
         y = 2
         a, b = coerce(x, y)
-        self.failUnless(a is x and type(getProxiedObject(b)) is float)
+        self.failUnless(a is x and type(removeSecurityProxy(b)) is float)
 
         x = 1
         y = P(2)
@@ -367,12 +367,12 @@
         x = 1.1
         y = P(2)
         a, b = coerce(x, y)
-        self.failUnless(a is x and type(getProxiedObject(b)) is float)
+        self.failUnless(a is x and type(removeSecurityProxy(b)) is float)
 
         x = 1
         y = P(2.1)
         a, b = coerce(x, y)
-        self.failUnless(type(getProxiedObject(a)) is float and b is y)
+        self.failUnless(type(removeSecurityProxy(a)) is float and b is y)
 
 def test_using_mapping_slots_hack():
     """The security proxy will use mapping slots, on the checker to go faster



More information about the Zope3-Checkins mailing list