From a7a6d7568546dcc88d836653cce8e69916f1e442 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 1 May 2009 08:02:55 +0000 Subject: - The ``repoze.bfg.location.LocationProxy`` class and the ``repoze.bfg.location.ClassAndInstanceDescr`` class have both been removed in order to be able to eventually shed a dependency on ``zope.proxy``. Neither of these classes was ever an API. - In all previous releases, the ``repoze.bfg.location.locate`` function worked like so: if a model did not explicitly provide the ``repoze.bfg.interfaces.ILocation`` interface, ``locate`` returned a ``LocationProxy`` object representing ``model`` with its ``__parent__`` attribute assigned to ``parent`` and a ``__name__`` attribute assigned to ``__name__``. In this release, the ``repoze.bfg.location.locate`` function simply jams the ``__name__`` and ``__parent__`` attributes on to the supplied model unconditionally, no matter if the object implements ILocation or not, and it never returns a proxy. This was done because the LocationProxy behavior has now moved into an add-on package (``repoze.bfg.traversalwrapper``), in order to eventually be able to shed a dependency on ``zope.proxy``. - In all previous releases, by default, if traversal was used (as opposed to URL-dispatch), and the root object supplied the``repoze.bfg.interfaces.ILocation`` interface, but the children returned via its ``__getitem__`` returned an object that did not implement the same interface, :mod:`repoze.bfg` provided some implicit help during traversal. This traversal feature wrapped subobjects from the root (and thereafter) that did not implement ``ILocation`` in proxies which automatically provided them with a ``__name__`` and ``__parent__`` attribute based on the name being traversed and the previous object traversed. This feature has now been removed from the base ``repoze.bfg`` package for purposes of eventually shedding a dependency on ``zope.proxy``. In order to re-enable the wrapper behavior for older applications which cannot be changed, register the "traversalwrapper" ``ModelGraphTraverser`` as the traversal policy, rather than the default ``ModelGraphTraverser``. To use this feature, you will need to install the ``repoze.bfg.traversalwrapper`` package (an add-on package, available at http://svn.repoze.org/repoze.bfg.traversalwrapper) Then change your application's ``configure.zcml`` to include the following stanza: When this ITraverserFactory is used instead of the default, no object in the graph (even the root object) must supply a ``__name__`` or ``__parent__`` attribute. Even if subobjects returned from the root *do* implement the ILocation interface, these will still be wrapped in proxies that override the object's "real" ``__parent__`` and ``__name__`` attributes. See also changes to the "Models" chapter of the documentation (in the "Location-Aware Model Instances") section. --- repoze/bfg/tests/test_traversal.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'repoze/bfg/tests/test_traversal.py') diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py index 942f84684..f361d0a79 100644 --- a/repoze/bfg/tests/test_traversal.py +++ b/repoze/bfg/tests/test_traversal.py @@ -189,40 +189,6 @@ class ModelGraphTraverserTests(unittest.TestCase): environ = self._getEnviron(PATH_INFO='/%s' % segment) self.assertRaises(TypeError, policy, environ) -class WrappingModelGraphTraverserTests(ModelGraphTraverserTests): - - def _getTargetClass(self): - from repoze.bfg.traversal import WrappingModelGraphTraverser - return WrappingModelGraphTraverser - - def test_call_proxies(self): - baz = DummyContext() - bar = DummyContext(baz) - foo = DummyContext(bar) - root = DummyContext(foo) - from zope.proxy import isProxy - policy = self._makeOne(root) - environ = self._getEnviron(PATH_INFO='/foo/bar/baz') - ctx, name, subpath, traversed, vroot, vroot_path = policy(environ) - self.assertEqual(name, '') - self.assertEqual(subpath, []) - self.assertEqual(ctx, baz) - self.failUnless(isProxy(ctx)) - self.assertEqual(ctx.__name__, 'baz') - self.assertEqual(ctx.__parent__, bar) - self.failUnless(isProxy(ctx.__parent__)) - self.assertEqual(ctx.__parent__.__name__, 'bar') - self.assertEqual(ctx.__parent__.__parent__, foo) - self.failUnless(isProxy(ctx.__parent__.__parent__)) - self.assertEqual(ctx.__parent__.__parent__.__name__, 'foo') - self.assertEqual(ctx.__parent__.__parent__.__parent__, root) - self.failUnless(isProxy(ctx.__parent__.__parent__.__parent__)) - self.assertEqual(ctx.__parent__.__parent__.__parent__.__name__, None) - self.assertEqual(ctx.__parent__.__parent__.__parent__.__parent__, None) - self.assertEqual(traversed, [u'foo', u'bar', u'baz']) - self.assertEqual(vroot, root) - self.assertEqual(vroot_path, []) - class FindInterfaceTests(unittest.TestCase): def _callFUT(self, context, iface): from repoze.bfg.traversal import find_interface -- cgit v1.2.3