Commit 86a623e5 authored by Hanno Schlichting's avatar Hanno Schlichting

Stop mixing in `Five.bbb.AcquisitionBBB` into browser components.

parent cc059e24
...@@ -30,6 +30,8 @@ Features Added ...@@ -30,6 +30,8 @@ Features Added
Restructuring Restructuring
+++++++++++++ +++++++++++++
- Stop mixing in `Five.bbb.AcquisitionBBB` into browser components.
- Integrate `five.pt` code directly into `Products.PageTemplates`. - Integrate `five.pt` code directly into `Products.PageTemplates`.
- Move `Products.SiteAccess` into ZServer distribution. - Move `Products.SiteAccess` into ZServer distribution.
......
...@@ -90,7 +90,7 @@ class ProductDispatcher(Implicit): ...@@ -90,7 +90,7 @@ class ProductDispatcher(Implicit):
FactoryDispatcher) FactoryDispatcher)
product = Product(name) product = Product(name)
dispatcher = dispatcher_class(product, self.aq_parent, REQUEST) dispatcher = dispatcher_class(product, self.__parent__, REQUEST)
return dispatcher.__of__(self) return dispatcher.__of__(self)
......
...@@ -24,7 +24,7 @@ from App.config import getConfiguration ...@@ -24,7 +24,7 @@ from App.config import getConfiguration
import Zope2 import Zope2
from Shared.DC.Scripts.Bindings import Bindings from Shared.DC.Scripts.Bindings import Bindings
from Acquisition import Explicit, aq_inner, aq_parent from Acquisition import Explicit, aq_inner, aq_parent, aq_acquire
from DocumentTemplate.DT_String import _marker, DTReturn, render_blocks from DocumentTemplate.DT_String import _marker, DTReturn, render_blocks
from DocumentTemplate.DT_Util import TemplateDict, InstanceDict from DocumentTemplate.DT_Util import TemplateDict, InstanceDict
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
...@@ -166,7 +166,7 @@ class DTMLFile(Bindings, Explicit, ClassicHTMLFile): ...@@ -166,7 +166,7 @@ class DTMLFile(Bindings, Explicit, ClassicHTMLFile):
else: else:
# We're first, so get the REQUEST. # We're first, so get the REQUEST.
try: try:
req = self.aq_acquire('REQUEST') req = aq_acquire(self, 'REQUEST')
if hasattr(req, 'taintWrapper'): if hasattr(req, 'taintWrapper'):
req = req.taintWrapper() req = req.taintWrapper()
except Exception: except Exception:
......
...@@ -127,7 +127,7 @@ class DatabaseChooserTests(ConfigTestBase, unittest.TestCase): ...@@ -127,7 +127,7 @@ class DatabaseChooserTests(ConfigTestBase, unittest.TestCase):
found = dc['foo'] found = dc['foo']
self.assertTrue(isinstance(found, AltDatabaseManager)) self.assertTrue(isinstance(found, AltDatabaseManager))
self.assertEqual(found.id, 'foo') self.assertEqual(found.id, 'foo')
self.assertTrue(found.aq_parent is dc) self.assertTrue(found.__parent__ is dc)
conn = found._p_jar conn = found._p_jar
self.assertTrue(isinstance(conn, FakeConnection)) self.assertTrue(isinstance(conn, FakeConnection))
self.assertTrue(conn.db() is foo) self.assertTrue(conn.db() is foo)
...@@ -150,7 +150,7 @@ class DatabaseChooserTests(ConfigTestBase, unittest.TestCase): ...@@ -150,7 +150,7 @@ class DatabaseChooserTests(ConfigTestBase, unittest.TestCase):
found = dc.__bobo_traverse__(None, 'foo') found = dc.__bobo_traverse__(None, 'foo')
self.assertTrue(isinstance(found, AltDatabaseManager)) self.assertTrue(isinstance(found, AltDatabaseManager))
self.assertEqual(found.id, 'foo') self.assertEqual(found.id, 'foo')
self.assertTrue(found.aq_parent is dc) self.assertTrue(found.__parent__ is dc)
conn = found._p_jar conn = found._p_jar
self.assertTrue(isinstance(conn, FakeConnection)) self.assertTrue(isinstance(conn, FakeConnection))
self.assertTrue(conn.db() is foo) self.assertTrue(conn.db() is foo)
......
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
import time import time
from Acquisition import aq_acquire
from zExceptions import HTTPPreconditionFailed
from zope.interface import implements from zope.interface import implements
from zope.interface import Interface from zope.interface import Interface
from zExceptions import HTTPPreconditionFailed
class EtagBaseInterface(Interface): class EtagBaseInterface(Interface):
"""\ """\
...@@ -108,7 +108,7 @@ class EtagSupport(object): ...@@ -108,7 +108,7 @@ class EtagSupport(object):
# Process if-match and if-none-match headers # Process if-match and if-none-match headers
if REQUEST is None: if REQUEST is None:
REQUEST = self.aq_acquire('REQUEST') REQUEST = aq_acquire(self, 'REQUEST')
matchlist = self.http__parseMatchList(REQUEST, 'if-match') matchlist = self.http__parseMatchList(REQUEST, 'if-match')
nonematch = self.http__parseMatchList(REQUEST, 'if-none-match') nonematch = self.http__parseMatchList(REQUEST, 'if-none-match')
......
...@@ -33,7 +33,7 @@ from AccessControl.Permissions import delete_objects ...@@ -33,7 +33,7 @@ from AccessControl.Permissions import delete_objects
from AccessControl.Permissions import ftp_access from AccessControl.Permissions import ftp_access
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from AccessControl.ZopeSecurityPolicy import getRoles from AccessControl.ZopeSecurityPolicy import getRoles
from Acquisition import aq_base, aq_parent from Acquisition import aq_base, aq_acquire, aq_parent
from Acquisition import Implicit from Acquisition import Implicit
from App.Common import is_acquired from App.Common import is_acquired
from App.config import getConfiguration from App.config import getConfiguration
...@@ -770,7 +770,7 @@ class IFAwareObjectManager: ...@@ -770,7 +770,7 @@ class IFAwareObjectManager:
interfaces = self._product_interfaces interfaces = self._product_interfaces
elif hasattr(self, 'aq_acquire'): elif hasattr(self, 'aq_acquire'):
try: try:
interfaces = self.aq_acquire('_product_interfaces') interfaces = aq_acquire(self, '_product_interfaces')
except Exception: except Exception:
pass pass
......
...@@ -6,7 +6,7 @@ from AccessControl.SecurityManagement import noSecurityManager ...@@ -6,7 +6,7 @@ from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.SecurityManager import setSecurityPolicy from AccessControl.SecurityManager import setSecurityPolicy
from AccessControl.SpecialUsers import emergency_user, nobody, system from AccessControl.SpecialUsers import emergency_user, nobody, system
from AccessControl.User import User # before SpecialUsers from AccessControl.User import User # before SpecialUsers
from Acquisition import Implicit from Acquisition import aq_self, Implicit
from App.config import getConfiguration from App.config import getConfiguration
from logging import getLogger from logging import getLogger
from zExceptions import BadRequest from zExceptions import BadRequest
...@@ -444,8 +444,8 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase): ...@@ -444,8 +444,8 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase):
si1 = SimpleItem('1') si1 = SimpleItem('1')
om['1'] = si1 om['1'] = si1
got = om['1'] got = om['1']
self.assertTrue(got.aq_self is si1) self.assertTrue(aq_self(got) is si1)
self.assertTrue(got.aq_parent is om) self.assertTrue(got.__parent__ is om)
def test_get_miss_wo_default(self): def test_get_miss_wo_default(self):
om = self._makeOne() om = self._makeOne()
...@@ -465,8 +465,8 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase): ...@@ -465,8 +465,8 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase):
si1 = SimpleItem('1') si1 = SimpleItem('1')
om['1'] = si1 om['1'] = si1
got = om.get('1') got = om.get('1')
self.assertTrue(got.aq_self is si1) self.assertTrue(aq_self(got) is si1)
self.assertTrue(got.aq_parent is om) self.assertTrue(got.__parent__ is om)
def test_items(self): def test_items(self):
om = self._makeOne() om = self._makeOne()
......
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Things needed for backward compatibility
"""
import Acquisition
class AcquisitionBBB(object):
"""Emulate a class implementing Acquisition.interfaces.IAcquirer and
IAcquisitionWrapper.
"""
def __of__(self, context):
# Technically this isn't in line with the way Acquisition's
# __of__ works. With Acquisition, you get a wrapper around
# the original object and only that wrapper's parent is the
# new context.
return self
aq_self = aq_inner = aq_base = property(lambda self: self)
aq_chain = property(Acquisition.aq_chain)
aq_parent = property(Acquisition.aq_parent)
def aq_acquire(self, *args, **kw):
return Acquisition.aq_acquire(self, *args, **kw)
def aq_inContextOf(self, *args, **kw):
return Acquisition.aq_inContextOf(self, *args, **kw)
...@@ -14,13 +14,10 @@ ...@@ -14,13 +14,10 @@
"""Provide basic browser functionality """Provide basic browser functionality
""" """
import Acquisition from zope.publisher import browser
import zope.publisher.browser
from Products.Five.bbb import AcquisitionBBB
class BrowserView(browser.BrowserView):
class BrowserView(zope.publisher.browser.BrowserView, AcquisitionBBB):
# Use an explicit __init__ to work around problems with magically inserted # Use an explicit __init__ to work around problems with magically inserted
# super classes when using BrowserView as a base for viewlets. # super classes when using BrowserView as a base for viewlets.
...@@ -28,14 +25,10 @@ class BrowserView(zope.publisher.browser.BrowserView, AcquisitionBBB): ...@@ -28,14 +25,10 @@ class BrowserView(zope.publisher.browser.BrowserView, AcquisitionBBB):
self.context = context self.context = context
self.request = request self.request = request
# Classes which are still based on Acquisition and access
# self.context in a method need to call aq_inner on it, or get a
# funky aq_chain. We do this here for BBB friendly purposes.
def __getParent(self): def __getParent(self):
return getattr(self, '_parent', Acquisition.aq_inner(self.context)) return getattr(self, '_parent', self.context)
def __setParent(self, parent): def __setParent(self, parent):
self._parent = parent self._parent = parent
aq_parent = __parent__ = property(__getParent, __setParent) __parent__ = property(__getParent, __setParent)
...@@ -24,8 +24,6 @@ from AccessControl import getSecurityManager ...@@ -24,8 +24,6 @@ from AccessControl import getSecurityManager
from Products.PageTemplates.Expressions import SecureModuleImporter from Products.PageTemplates.Expressions import SecureModuleImporter
from Products.PageTemplates.Expressions import createTrustedZopeEngine from Products.PageTemplates.Expressions import createTrustedZopeEngine
from Products.Five.bbb import AcquisitionBBB
_engine = createTrustedZopeEngine() _engine = createTrustedZopeEngine()
...@@ -107,12 +105,10 @@ class ViewMapper(object): ...@@ -107,12 +105,10 @@ class ViewMapper(object):
return getMultiAdapter((self.ob, self.request), name=name) return getMultiAdapter((self.ob, self.request), name=name)
# When a view's template is accessed e.g. as template.view, a # When a view's template is accessed e.g. as template.view, a
# BoundPageTemplate object is returned. For BBB reasons, it needs to # BoundPageTemplate object is returned.
# support the aq_* methods and attributes known from Acquisition. For
# that it also needs to be locatable through __parent__.
class BoundPageTemplate(AcquisitionBBB): class BoundPageTemplate(object):
def __init__(self, pt, ob): def __init__(self, pt, ob):
object.__setattr__(self, 'im_func', pt) object.__setattr__(self, 'im_func', pt)
object.__setattr__(self, 'im_self', ob) object.__setattr__(self, 'im_self', ob)
......
...@@ -26,7 +26,6 @@ from zope.publisher.interfaces import NotFound ...@@ -26,7 +26,6 @@ from zope.publisher.interfaces import NotFound
from zope.publisher.interfaces.browser import IBrowserPublisher from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.ptresource.ptresource import PageTemplate from zope.ptresource.ptresource import PageTemplate
from Acquisition import aq_base
from Products.Five.browser import BrowserView from Products.Five.browser import BrowserView
...@@ -175,7 +174,7 @@ class DirectoryResource(Resource, ...@@ -175,7 +174,7 @@ class DirectoryResource(Resource,
# We need to propagate security so that restrictedTraverse() will # We need to propagate security so that restrictedTraverse() will
# work # work
if hasattr(aq_base(self), '__roles__'): if hasattr(self, '__roles__'):
resource.__roles__ = self.__roles__ resource.__roles__ = self.__roles__
return resource return resource
......
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Legacy browser view tests.
Here we nake sure that legacy implementations of views (e.g. those
which mix-in one of the Acquisition base classes without knowing
better) still work.
"""
import Acquisition
import OFS.SimpleItem
from zope.interface import implements
from zope.traversing.interfaces import ITraversable
from zope.contentprovider.interfaces import IContentProvider
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class LegacyAttributes(BrowserView):
"""Make sure that those old aq_* attributes on Five BrowserViews
still work, in particular aq_chain, even though BrowserView may
not be an Acquisition-decendant class anymore...
"""
def __call__(self):
return repr([obj for obj in self.aq_chain])
class ExplicitLegacyAttributes(Acquisition.Explicit):
"""Make sure that those old aq_* attributes work on browser views
that only inherit from Explicit as well."""
def __call__(self):
return repr([obj for obj in self.aq_chain])
class LegacyTemplate(BrowserView):
template = ViewPageTemplateFile('falcon.pt')
def __call__(self):
return self.template()
class LegacyTemplateTwo(BrowserView):
def __init__(self, context, request):
self.__parent__ = context
self.context = context
self.request = request
self.template = ViewPageTemplateFile('falcon.pt')
def __call__(self):
return self.template()
class Explicit(Acquisition.Explicit):
def render(self):
return 'Explicit'
class ExplicitWithTemplate(Acquisition.Explicit):
template = ViewPageTemplateFile('falcon.pt')
class Implicit(Acquisition.Implicit):
index_html = None # we don't want to acquire this!
def render(self):
return 'Implicit'
class ImplicitWithTemplate(Acquisition.Implicit):
template = ViewPageTemplateFile('falcon.pt')
class ExplicitContentProvider(Acquisition.Explicit):
implements(IContentProvider)
def __init__(self, context, request, view):
self.context = context
self.request = request
self.view = view
# A content provider must set __parent__ to view or context.
self.__parent__ = context
def update(self):
pass
def render(self):
return 'Content provider inheriting from Explicit'
class ExplicitViewlet(Acquisition.Explicit):
def __init__(self, context, request, view, manager):
self.context = context
self.request = request
def update(self):
# Make sure that the viewlet has the legacy attributes and
# they point to the right objects.
assert self.aq_parent == self.context
assert self.aq_base == self
def render(self):
return 'Viewlet inheriting from Explicit'
class BrowserViewViewlet(BrowserView):
def __init__(self, context, request, view, manager):
# This is the tricky bit. super(...).__init__ wouldn't
# necessarily have to resolve to BrowserView.__init__ because
# <browser:viewlet /> generates classes on the fly with a
# mix-in base class...
super(BrowserViewViewlet, self).__init__(context, request)
self.view = view
self.manager = manager
def update(self):
pass
def render(self):
return 'BrowserView viewlet'
class LegacyNamespace(object):
implements(ITraversable)
def __init__(self, context, request):
self.context = context
self.request = request
def traverse(self, name, ignored):
return LegacyNamespaceObject(name)
class LegacyNamespaceObject(OFS.SimpleItem.SimpleItem):
def __init__(self, name):
self.id = name
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
for="*"
name="attributes"
class=".aqlegacy.LegacyAttributes"
permission="zope.Public"
/>
<browser:page
for="*"
name="explicitattributes"
class=".aqlegacy.ExplicitLegacyAttributes"
permission="zope.Public"
/>
<browser:page
for="*"
name="template"
class=".aqlegacy.LegacyTemplate"
permission="zope.Public"
/>
<browser:page
for="*"
name="template_two"
class=".aqlegacy.LegacyTemplateTwo"
permission="zope.Public"
/>
<browser:page
for="*"
name="explicit"
class=".aqlegacy.Explicit"
attribute="render"
permission="zope.Public"
/>
<browser:page
for="*"
name="explicit_zcmltemplate"
class=".aqlegacy.Explicit"
template="falcon.pt"
permission="zope.Public"
/>
<browser:page
for="*"
name="explicit_template"
class=".aqlegacy.ExplicitWithTemplate"
attribute="template"
permission="zope.Public"
/>
<browser:page
for="*"
name="implicit"
class=".aqlegacy.Implicit"
attribute="render"
permission="zope.Public"
/>
<browser:page
for="*"
name="implicit_template"
class=".aqlegacy.ImplicitWithTemplate"
attribute="template"
permission="zope.Public"
/>
<browser:page
for="*"
name="implicit_zcmltemplate"
class=".aqlegacy.Implicit"
template="falcon.pt"
permission="zope.Public"
/>
<!-- Content providers and viewlets -->
<adapter
for="* * *"
provides="zope.contentprovider.interfaces.IContentProvider"
factory=".aqlegacy.ExplicitContentProvider"
name="aqlegacyprovider"
/>
<browser:page
for="*"
name="aqlegacyprovider"
template="legacyprovider.pt"
permission="zope.Public"
/>
<browser:viewletManager
name="aqlegacymanager"
permission="zope.Public"
/>
<browser:viewlet
for="*"
class=".aqlegacy.ExplicitViewlet"
name="explicit"
permission="zope.Public"
/>
<browser:viewlet
for="*"
class=".aqlegacy.BrowserViewViewlet"
name="browserview"
permission="zope.Public"
/>
<browser:page
for="*"
name="aqlegacymanager"
template="legacymanager.pt"
permission="zope.Public"
/>
<!-- Namespace traversal -->
<adapter
for="*"
factory=".aqlegacy.LegacyNamespace"
name="aqlegacy"
/>
<adapter
for="* *"
factory=".aqlegacy.LegacyNamespace"
name="aqlegacy"
/>
<browser:page
for=".aqlegacy.LegacyNamespaceObject"
name="index.html"
template="falcon.pt"
permission="zope.Public"
/>
</configure>
\ No newline at end of file
Testing legacy browser views
============================
This test tests publishing aspects of browser pages. Let's register
some:
>>> import Products.Five.browser.tests
>>> from Zope2.App import zcml
>>> zcml.load_config("configure.zcml", Products.Five)
>>> zcml.load_config('aqlegacy.zcml', package=Products.Five.browser.tests)
>>> from Testing.testbrowser import Browser
>>> browser = Browser()
>>> browser.handleErrors = False
Acquisition API legacy on BrowserView
-------------------------------------
Let's make sure that accessing those old aq_* properties on browser
views still works (the printed output is the aq_chain of the view):
>>> browser.open('http://localhost/test_folder_1_/attributes')
>>> print browser.contents
[<Products.Five.browser.metaconfigure.LegacyAttributes object at ...>,
<Folder at /test_folder_1_>,
<Application at >,
<ZPublisher.BaseRequest.RequestContainer object at ...>]
The same goes for browser views that just mix in Acquisition.Explicit:
>>> browser.open('http://localhost/test_folder_1_/explicitattributes')
>>> print browser.contents
[<Products.Five.browser.metaconfigure.ExplicitLegacyAttributes object at ...>,
<Folder at /test_folder_1_>,
<Application at >,
<ZPublisher.BaseRequest.RequestContainer object at ...>]
Let's do some more manual tests with the view object. But first we
must get it:
>>> from zope.component import getMultiAdapter
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> view = getMultiAdapter((self.folder, request), name='attributes')
Let's check for the various aq_* attributes:
>>> view.aq_parent == self.folder
True
>>> view.aq_inner == view
True
>>> view.aq_base == view
True
>>> view.aq_self == view
True
Views also still support the __of__ protocol, at least pro forma:
>>> view == view.__of__(self.app)
True
Mixing in Acquisition.{Ex|Im}plicit
-----------------------------------
Let's make sure that mixing in Acquisition.Explicit or Implicit won't
mess up your views (even though you should never have done it in the
first place...):
>>> browser.open('http://localhost/test_folder_1_/explicit')
>>> print browser.contents
Explicit
>>> browser.open('http://localhost/test_folder_1_/explicit_zcmltemplate')
>>> print browser.contents
<p>The falcon has taken flight</p>
>>> browser.open('http://localhost/test_folder_1_/explicit_template')
>>> print browser.contents
<p>The falcon has taken flight</p>
>>> browser.open('http://localhost/test_folder_1_/implicit')
>>> print browser.contents
Implicit
>>> browser.open('http://localhost/test_folder_1_/implicit_template')
>>> print browser.contents
<p>The falcon has taken flight</p>
>>> browser.open('http://localhost/test_folder_1_/implicit_zcmltemplate')
>>> print browser.contents
<p>The falcon has taken flight</p>
Testing legacy content providers and viewlets
=============================================
>>> browser.open('http://localhost/test_folder_1_/aqlegacyprovider')
>>> print browser.contents
<p>Content provider inheriting from Explicit</p>
>>> browser.open('http://localhost/test_folder_1_/aqlegacymanager')
>>> print browser.contents
<p>BrowserView viewlet
Viewlet inheriting from Explicit</p>
Testing namespace traversal
===========================
Namespace traversal can turn up objects during traversal without
attribute access. That means they might not be wrapped by default.
Here we make sure that they are wrapped and that things like the
request can be acquired.
First let's try ``restrictedTraverse()``:
>>> foo = self.folder.restrictedTraverse('++aqlegacy++foo')
>>> import Acquisition
>>> Acquisition.aq_acquire(foo, 'REQUEST')
<HTTPRequest, URL=http://nohost>
Now let's try URL traversal:
>>> browser.open('http://localhost/test_folder_1_/++aqlegacy++foo/index.html')
>>> print browser.contents
<p>The falcon has taken flight</p>
Testing keyword arguments
=========================
ViewPageTemplateFile's take arbitrary keyword arguments:
>>> view = getMultiAdapter((self.folder, request), name='template')
>>> template = view.template
>>> print template(foo=1, bar=2)
<p>The falcon has taken flight</p>
Passing in an argument called instance was supported by the old Five version
of ViewPageTemplateFile, so we still need to support it.
>>> print template(instance='allowed')
<p>The falcon has taken flight</p>
No arguments required
=====================
ViewPageTemplateFile's require no arguments, but you can only use them as
class variables:
>>> view = getMultiAdapter((self.folder, request), name='template_two')
>>> print view()
Traceback (most recent call last):
...
TypeError: __call__() takes at least 2 arguments (1 given)
Clean up
--------
>>> from zope.component.testing import tearDown
>>> tearDown()
<p tal:content="provider:aqlegacymanager" />
<p tal:content="provider:aqlegacyprovider" />
...@@ -150,7 +150,7 @@ Make sure that global template variables in ZPT pages are correct: ...@@ -150,7 +150,7 @@ Make sure that global template variables in ZPT pages are correct:
>>> print view() >>> print view()
View is a view: True View is a view: True
Context is testoid: True Context is testoid: True
Context.aq_parent is test_folder_1_: True Context.__parent__ is test_folder_1_: True
Container is context: True Container is context: True
Here is context: True Here is context: True
Nothing is None: True Nothing is None: True
...@@ -260,7 +260,7 @@ The parent of the view is the view's context: ...@@ -260,7 +260,7 @@ The parent of the view is the view's context:
The direct parent of the context is The direct parent of the context is
>>> context.aq_inner.aq_parent >>> aq_inner(context).__parent__
<Folder at /test_folder_1_> <Folder at /test_folder_1_>
C methods work the same C methods work the same
...@@ -285,7 +285,7 @@ The same applies to a view registered with <browser:view /> instead of ...@@ -285,7 +285,7 @@ The same applies to a view registered with <browser:view /> instead of
True True
>>> aq_parent(view) == view.context >>> aq_parent(view) == view.context
True True
>>> context.aq_inner.aq_parent >>> aq_inner(context).__parent__
<Folder at /test_folder_1_> <Folder at /test_folder_1_>
>>> aq_parent(aq_inner(context)) >>> aq_parent(aq_inner(context))
<Folder at /test_folder_1_> <Folder at /test_folder_1_>
......
View is a view: <tal:block View is a view: <tal:block
content="python:hasattr(view,'context') and hasattr(view, 'request')" /> content="python:hasattr(view,'context') and hasattr(view, 'request')" />
Context is testoid: <tal:block content="python:context.id == 'testoid'" /> Context is testoid: <tal:block content="python:context.id == 'testoid'" />
Context.aq_parent is test_folder_1_: <tal:block Context.__parent__ is test_folder_1_: <tal:block
content="python:context.aq_parent.id =='test_folder_1_'" /> content="python:context.__parent__.id =='test_folder_1_'" />
Container is context: <tal:block content="python:container is context" /> Container is context: <tal:block content="python:container is context" />
Here is context: <tal:block content="python:here is context"/> Here is context: <tal:block content="python:here is context"/>
Nothing is None: <tal:block content="python:nothing is None"/> Nothing is None: <tal:block content="python:nothing is None"/>
......
...@@ -74,6 +74,4 @@ def test_suite(): ...@@ -74,6 +74,4 @@ def test_suite():
ZopeDocFileSuite('pages.txt', package='Products.Five.browser.tests'), ZopeDocFileSuite('pages.txt', package='Products.Five.browser.tests'),
FunctionalDocFileSuite('pages_ftest.txt', FunctionalDocFileSuite('pages_ftest.txt',
package='Products.Five.browser.tests'), package='Products.Five.browser.tests'),
FunctionalDocFileSuite('aqlegacy_ftest.txt',
package='Products.Five.browser.tests'),
)) ))
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
"""Viewlet manager. """Viewlet manager.
""" """
from Acquisition import aq_base
from AccessControl.ZopeGuards import guarded_hasattr from AccessControl.ZopeGuards import guarded_hasattr
import zope.interface import zope.interface
import zope.security import zope.security
...@@ -76,7 +75,7 @@ class ViewletManagerBase(origManagerBase): ...@@ -76,7 +75,7 @@ class ViewletManagerBase(origManagerBase):
# but it allows the tests to have deterministic results. # but it allows the tests to have deterministic results.
def _key(info): def _key(info):
return aq_base(info[1]) return info[1]
return sorted(viewlets, key=_key) return sorted(viewlets, key=_key)
......
...@@ -16,16 +16,14 @@ ...@@ -16,16 +16,14 @@
import os import os
import zope.viewlet.viewlet import zope.viewlet.viewlet
from Products.Five.bbb import AcquisitionBBB
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class ViewletBase(zope.viewlet.viewlet.ViewletBase, AcquisitionBBB): class ViewletBase(zope.viewlet.viewlet.ViewletBase):
pass pass
class SimpleAttributeViewlet(zope.viewlet.viewlet.SimpleAttributeViewlet, class SimpleAttributeViewlet(zope.viewlet.viewlet.SimpleAttributeViewlet):
AcquisitionBBB):
pass pass
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
import sys import sys
from Acquisition import aq_base from Acquisition import aq_base, aq_inner, aq_parent
import ExtensionClass import ExtensionClass
import zope.pagetemplate.pagetemplate import zope.pagetemplate.pagetemplate
from zope.pagetemplate.pagetemplate import PTRuntimeError from zope.pagetemplate.pagetemplate import PTRuntimeError
...@@ -41,7 +41,7 @@ class PageTemplate(ExtensionClass.Base, ...@@ -41,7 +41,7 @@ class PageTemplate(ExtensionClass.Base,
if parent is not None: if parent is not None:
c['here'] = parent c['here'] = parent
c['context'] = parent c['context'] = parent
c['container'] = self.aq_inner.aq_parent c['container'] = aq_parent(aq_inner(self))
while parent is not None: while parent is not None:
self = parent self = parent
parent = getattr(self, '__parent__', None) parent = getattr(self, '__parent__', None)
......
...@@ -23,8 +23,7 @@ from AccessControl.Permissions import view_management_screens ...@@ -23,8 +23,7 @@ from AccessControl.Permissions import view_management_screens
from AccessControl.PermissionRole import _what_not_even_god_should_do from AccessControl.PermissionRole import _what_not_even_god_should_do
from AccessControl.unauthorized import Unauthorized from AccessControl.unauthorized import Unauthorized
from AccessControl.ZopeGuards import guarded_getattr from AccessControl.ZopeGuards import guarded_getattr
from Acquisition import aq_parent from Acquisition import aq_base, aq_inner, aq_parent
from Acquisition import aq_inner
defaultBindings = {'name_context': 'context', defaultBindings = {'name_context': 'context',
'name_container': 'container', 'name_container': 'container',
...@@ -238,7 +237,7 @@ class Bindings: ...@@ -238,7 +237,7 @@ class Bindings:
path = request['TraversalRequestNameStack'] path = request['TraversalRequestNameStack']
names = self.getBindingAssignments() names = self.getBindingAssignments()
if (not names.isNameAssigned('name_subpath') or if (not names.isNameAssigned('name_subpath') or
(path and hasattr(self.aq_base, path[-1]))): (path and hasattr(aq_base(self), path[-1]))):
return return
subpath = path[:] subpath = path[:]
path[:] = [] path[:] = []
......
...@@ -22,7 +22,7 @@ way of getting started. ...@@ -22,7 +22,7 @@ way of getting started.
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Acquisition import aq_base from Acquisition import aq_base, aq_inner
from AccessControl import getSecurityManager from AccessControl import getSecurityManager
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder from OFS.Folder import Folder
...@@ -61,11 +61,11 @@ class DummyMembershipTool(SimpleItem): ...@@ -61,11 +61,11 @@ class DummyMembershipTool(SimpleItem):
def createMemberarea(self, member_id): def createMemberarea(self, member_id):
self._called.append('createMemberarea') self._called.append('createMemberarea')
portal = self.aq_inner.aq_parent portal = aq_inner(self).__parent__
portal.Members.manage_addFolder(member_id) portal.Members.manage_addFolder(member_id)
def getHomeFolder(self, member_id): def getHomeFolder(self, member_id):
portal = self.aq_inner.aq_parent portal = aq_inner(self).__parent__
return getattr(portal.Members, member_id) return getattr(portal.Members, member_id)
...@@ -73,7 +73,7 @@ class NewMembershipTool(DummyMembershipTool): ...@@ -73,7 +73,7 @@ class NewMembershipTool(DummyMembershipTool):
def createMemberArea(self, member_id): def createMemberArea(self, member_id):
self._called.append('createMemberArea') self._called.append('createMemberArea')
portal = self.aq_inner.aq_parent portal = aq_inner(self).__parent__
portal.Members.manage_addFolder(member_id) portal.Members.manage_addFolder(member_id)
...@@ -434,8 +434,9 @@ class TestPlainUserFolder(ZopeTestCase.PortalTestCase): ...@@ -434,8 +434,9 @@ class TestPlainUserFolder(ZopeTestCase.PortalTestCase):
self.assertEqual(user.getId(), user_name) self.assertEqual(user.getId(), user_name)
self.assertTrue(hasattr(user, 'aq_base')) self.assertTrue(hasattr(user, 'aq_base'))
self.assertTrue(user.__class__.__name__, 'User') self.assertTrue(user.__class__.__name__, 'User')
self.assertTrue(user.aq_parent.__class__.__name__, 'UserFolder') self.assertTrue(user.__parent__.__class__.__name__, 'UserFolder')
self.assertTrue(user.aq_parent.aq_parent.__class__.__name__, 'Folder') self.assertTrue(
user.__parent__.__parent__.__class__.__name__, 'Folder')
class TestWrappingUserFolder(ZopeTestCase.PortalTestCase): class TestWrappingUserFolder(ZopeTestCase.PortalTestCase):
...@@ -453,7 +454,7 @@ class TestWrappingUserFolder(ZopeTestCase.PortalTestCase): ...@@ -453,7 +454,7 @@ class TestWrappingUserFolder(ZopeTestCase.PortalTestCase):
self.assertTrue(hasattr(user, 'aq_base')) self.assertTrue(hasattr(user, 'aq_base'))
self.assertFalse(user is aq_base(user)) self.assertFalse(user is aq_base(user))
self.assertTrue( self.assertTrue(
user.aq_parent.__class__.__name__, 'WrappingUserFolder') user.__parent__.__class__.__name__, 'WrappingUserFolder')
def testLoggedInUserIsWrapped(self): def testLoggedInUserIsWrapped(self):
user = getSecurityManager().getUser() user = getSecurityManager().getUser()
...@@ -461,8 +462,9 @@ class TestWrappingUserFolder(ZopeTestCase.PortalTestCase): ...@@ -461,8 +462,9 @@ class TestWrappingUserFolder(ZopeTestCase.PortalTestCase):
self.assertTrue(hasattr(user, 'aq_base')) self.assertTrue(hasattr(user, 'aq_base'))
self.assertTrue(user.__class__.__name__, 'User') self.assertTrue(user.__class__.__name__, 'User')
self.assertTrue( self.assertTrue(
user.aq_parent.__class__.__name__, 'WrappingUserFolder') user.__parent__.__class__.__name__, 'WrappingUserFolder')
self.assertTrue(user.aq_parent.aq_parent.__class__.__name__, 'Folder') self.assertTrue(
user.__parent__.__parent__.__class__.__name__, 'Folder')
# Because we override setUp we need to test again # Because we override setUp we need to test again
......
...@@ -364,8 +364,9 @@ class TestPlainUserFolder(ZopeTestCase.ZopeTestCase): ...@@ -364,8 +364,9 @@ class TestPlainUserFolder(ZopeTestCase.ZopeTestCase):
self.assertEqual(user.getId(), user_name) self.assertEqual(user.getId(), user_name)
self.assertTrue(hasattr(user, 'aq_base')) self.assertTrue(hasattr(user, 'aq_base'))
self.assertTrue(user.__class__.__name__, 'User') self.assertTrue(user.__class__.__name__, 'User')
self.assertTrue(user.aq_parent.__class__.__name__, 'UserFolder') self.assertTrue(user.__parent__.__class__.__name__, 'UserFolder')
self.assertTrue(user.aq_parent.aq_parent.__class__.__name__, 'Folder') self.assertTrue(
user.__parent__.__parent__.__class__.__name__, 'Folder')
class TestWrappingUserFolder(ZopeTestCase.ZopeTestCase): class TestWrappingUserFolder(ZopeTestCase.ZopeTestCase):
...@@ -379,7 +380,7 @@ class TestWrappingUserFolder(ZopeTestCase.ZopeTestCase): ...@@ -379,7 +380,7 @@ class TestWrappingUserFolder(ZopeTestCase.ZopeTestCase):
self.assertTrue(hasattr(user, 'aq_base')) self.assertTrue(hasattr(user, 'aq_base'))
self.assertFalse(user is aq_base(user)) self.assertFalse(user is aq_base(user))
self.assertTrue( self.assertTrue(
user.aq_parent.__class__.__name__, 'WrappingUserFolder') user.__parent__.__class__.__name__, 'WrappingUserFolder')
def testLoggedInUserIsWrapped(self): def testLoggedInUserIsWrapped(self):
user = getSecurityManager().getUser() user = getSecurityManager().getUser()
...@@ -387,8 +388,9 @@ class TestWrappingUserFolder(ZopeTestCase.ZopeTestCase): ...@@ -387,8 +388,9 @@ class TestWrappingUserFolder(ZopeTestCase.ZopeTestCase):
self.assertTrue(hasattr(user, 'aq_base')) self.assertTrue(hasattr(user, 'aq_base'))
self.assertTrue(user.__class__.__name__, 'User') self.assertTrue(user.__class__.__name__, 'User')
self.assertTrue( self.assertTrue(
user.aq_parent.__class__.__name__, 'WrappingUserFolder') user.__parent__.__class__.__name__, 'WrappingUserFolder')
self.assertTrue(user.aq_parent.aq_parent.__class__.__name__, 'Folder') self.assertTrue(
user.__parent__.__parent__.__class__.__name__, 'Folder')
def test_suite(): def test_suite():
......
...@@ -18,7 +18,7 @@ import types ...@@ -18,7 +18,7 @@ import types
import xmlrpc import xmlrpc
from AccessControl.ZopeSecurityPolicy import getRoles from AccessControl.ZopeSecurityPolicy import getRoles
from Acquisition import aq_base from Acquisition import aq_base, aq_inner
from Acquisition.interfaces import IAcquirer from Acquisition.interfaces import IAcquirer
from ExtensionClass import Base from ExtensionClass import Base
from zExceptions import Forbidden from zExceptions import Forbidden
...@@ -469,7 +469,8 @@ class BaseRequest: ...@@ -469,7 +469,8 @@ class BaseRequest:
hasattr(object, 'aq_base') and hasattr(object, 'aq_base') and
not hasattr(object, '__bobo_traverse__')): not hasattr(object, '__bobo_traverse__')):
if object.aq_parent is not object.aq_inner.aq_parent: if (object.__parent__ is not
aq_inner(object).__parent__):
object = NullResource(parents[-2], object.getId(), object = NullResource(parents[-2], object.getId(),
self).__of__(parents[-2]) self).__of__(parents[-2])
...@@ -556,7 +557,7 @@ class BaseRequest: ...@@ -556,7 +557,7 @@ class BaseRequest:
if (no_acquire_flag and if (no_acquire_flag and
hasattr(parents[1], 'aq_base') and hasattr(parents[1], 'aq_base') and
not hasattr(parents[1], '__bobo_traverse__')): not hasattr(parents[1], '__bobo_traverse__')):
base = parents[1].aq_base base = aq_base(parents[1])
if not hasattr(base, entry_name): if not hasattr(base, entry_name):
try: try:
if entry_name not in base: if entry_name not in base:
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"""Simple Tree classes """Simple Tree classes
""" """
from Acquisition import aq_acquire
from Tree import TreeMaker, TreeNode, b2a from Tree import TreeMaker, TreeNode, b2a
...@@ -23,13 +24,13 @@ class SimpleTreeNode(TreeNode): ...@@ -23,13 +24,13 @@ class SimpleTreeNode(TreeNode):
if self.state < 0: if self.state < 0:
setst = 'expand' setst = 'expand'
exnum = self.aq_parent.expansion_number exnum = self.__parent__.expansion_number
else: else:
setst = 'collapse' setst = 'collapse'
exnum = self.expansion_number exnum = self.expansion_number
obid = self.id obid = self.id
pre = self.aq_acquire('tree_pre') pre = aq_acquire(self, 'tree_pre')
return {'link': '?%s-setstate=%s,%s,%s#%s' % return {'link': '?%s-setstate=%s,%s,%s#%s' %
(pre, setst[0], exnum, obid, obid), (pre, setst[0], exnum, obid, obid),
......
...@@ -53,7 +53,7 @@ class TreeNode(Explicit): ...@@ -53,7 +53,7 @@ class TreeNode(Explicit):
child.__of__(self).walk(f, data) child.__of__(self).walk(f, data)
def _depth(self): def _depth(self):
return self.aq_parent.depth + 1 return self.__parent__.depth + 1
depth = ComputedAttribute(_depth, 1) depth = ComputedAttribute(_depth, 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment