[Checkins] SVN: zope.app.publication/trunk/ Added a proxy method that can be overridden in subclasses to control
Jim Fulton
jim at zope.com
Sat Jun 20 06:59:31 EDT 2009
Log message for revision 101160:
Added a proxy method that can be overridden in subclasses to control
how/if security proxies are created.
Changed:
U zope.app.publication/trunk/CHANGES.txt
U zope.app.publication/trunk/src/zope/app/publication/browser.py
A zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py
U zope.app.publication/trunk/src/zope/app/publication/zopepublication.py
-=-
Modified: zope.app.publication/trunk/CHANGES.txt
===================================================================
--- zope.app.publication/trunk/CHANGES.txt 2009-06-20 09:20:28 UTC (rev 101159)
+++ zope.app.publication/trunk/CHANGES.txt 2009-06-20 10:59:31 UTC (rev 101160)
@@ -2,11 +2,14 @@
CHANGES
=======
-3.7.1 (unreleased)
+3.8.0 (2009-06-20)
------------------
-- Replaced zope.deprecation dependency with BBB imports
+- Added a proxy method that can be overridden in subclasses to control
+ how/if security proxies are created.
+- Replaced zope.deprecation dependency with backward-compatible imports
+
3.7.0 (2009-05-23)
------------------
Modified: zope.app.publication/trunk/src/zope/app/publication/browser.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/browser.py 2009-06-20 09:20:28 UTC (rev 101159)
+++ zope.app.publication/trunk/src/zope/app/publication/browser.py 2009-06-20 10:59:31 UTC (rev 101160)
@@ -22,7 +22,6 @@
from zope.component import queryMultiAdapter
from zope.publisher.interfaces.browser import IBrowserPublisher
-from zope.security.checker import ProxyFactory
from zope.app.publication.http import BaseHTTPPublication
@@ -39,7 +38,7 @@
adapter = queryMultiAdapter((ob, request), IBrowserPublisher)
if adapter is not None:
ob, path = adapter.browserDefault(request)
- ob = ProxyFactory(ob)
+ ob = self.proxy(ob)
return ob, path
else:
# ob is already proxied
Added: zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py (rev 0)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py 2009-06-20 10:59:31 UTC (rev 101160)
@@ -0,0 +1,112 @@
+##############################################################################
+#
+# Copyright (c) Zope Foundation 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.
+#
+##############################################################################
+from zope.testing import doctest, cleanup
+import unittest
+import zope.app.publication.browser
+import zope.component
+import zope.publisher.interfaces.browser
+
+class Proxy:
+
+ def __init__(self, context):
+ print "Proxy called"
+ self.context = context
+
+class Publication(zope.app.publication.browser.BrowserPublication):
+
+ def proxy(self, ob):
+ return Proxy(ob)
+
+
+class Sample:
+ "Sample object for testing"
+
+class Response:
+ def reset(self):
+ pass
+ def handleException(self, *args):
+ pass
+
+class Request:
+ principal = None
+ method = 'GET'
+ def __init__(self):
+ self.annotations = {}
+ self.response = Response()
+ def hold(self, ob):
+ pass
+ def getTraversalStack(self):
+ return []
+ def getURL(self):
+ return '/'
+
+class DB:
+ def open(self):
+ return self
+ def root(self):
+ return self
+ def get(self, key, default=None):
+ assert key == 'Application'
+ return Sample()
+ def close(self):
+ pass
+
+class Publisher:
+
+ def __init__(self, context, request):
+ self.context = context
+
+ def browserDefault(self, request):
+ return self.context, ['foo']
+
+def proxy_control():
+ """You can override proxy control in a subclass
+
+ This test makes sure the override is called in the cases where the
+ publication wants to call ProxyFactory.
+
+ >>> cleanup.cleanUp()
+
+ >>> zope.component.provideAdapter(
+ ... Publisher, (Sample, Request),
+ ... zope.publisher.interfaces.browser.IBrowserPublisher)
+
+ >>> pub = Publication(DB())
+ >>> request = Request()
+
+ >>> ob = pub.getApplication(request)
+ Proxy called
+ >>> isinstance(ob, Proxy) and isinstance(ob.context, Sample)
+ True
+
+ >>> sample = Sample()
+ >>> ob, path = pub.getDefaultTraversal(request, sample)
+ Proxy called
+ >>> isinstance(ob, Proxy) and ob.context == sample and path == ['foo']
+ True
+
+ >>> pub.handleException(sample, request, (ValueError, ValueError(), None))
+ Proxy called
+
+ >>> cleanup.cleanUp()
+ """
+
+def test_suite():
+ return unittest.TestSuite((
+ doctest.DocTestSuite(),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
Modified: zope.app.publication/trunk/src/zope/app/publication/zopepublication.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/zopepublication.py 2009-06-20 09:20:28 UTC (rev 101159)
+++ zope.app.publication/trunk/src/zope/app/publication/zopepublication.py 2009-06-20 10:59:31 UTC (rev 101160)
@@ -77,6 +77,14 @@
# db is a ZODB.DB.DB object.
self.db = db
+ def proxy(self, ob):
+ """Security-proxy an object
+
+ Subclasses may override this to use a different proxy (or
+ checker) implementation or to not proxy at all.
+ """
+ return ProxyFactory(ob)
+
def beforeTraversal(self, request):
# Try to authenticate against the root authentication utility.
auth = zope.component.getGlobalSiteManager().getUtility(
@@ -161,7 +169,7 @@
if app is None:
raise SystemError("Zope Application Not Found")
- return ProxyFactory(app)
+ return self.proxy(app)
def callObject(self, request, ob):
return mapply(ob, request.getPositionalArguments(), request)
@@ -310,7 +318,7 @@
loc = getattr(loc, 'im_self', loc)
loc = getattr(loc, '__self__', loc)
# Protect the location with a security proxy
- loc = ProxyFactory(loc)
+ loc = self.proxy(loc)
# Give the exception instance its location and look up the
# view.
More information about the Checkins
mailing list