Commit b5d92f77 authored by Hanno Schlichting's avatar Hanno Schlichting

Fix some more places to check for `__parent__`.

parent 2e99e17c
......@@ -16,7 +16,7 @@ import os
import sys
import time
from Acquisition import aq_base
from Acquisition import aq_base, aq_parent
# BBB
from os.path import realpath # NOQA
......@@ -83,11 +83,11 @@ def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
# Note that this method is misnamed since parents can (and do)
# spoof it. It is not a true measure of whether something is
# acquired, it relies on the parent's parent-ness exclusively
if not hasattr(ob, 'aq_parent'):
# We can't be acquired if we don't have an aq_parent
if not hasattr(ob, '__parent__'):
# We can't be acquired if we don't have an __parent__
return 0
parent = aq_base(ob.aq_parent)
parent = aq_base(aq_parent(ob))
absId = absattr(ob.id)
if hasattr(parent, absId):
......@@ -100,7 +100,7 @@ def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
try:
# We assume that getitem will not acquire which
# is the standard behavior for Zope objects
if aq_base(ob.aq_parent[absId]) is aq_base(ob):
if aq_base(aq_parent(ob)[absId]) is aq_base(ob):
# This object is an item of the aq_parent, its not acquired
return 0
except KeyError:
......
......@@ -14,6 +14,8 @@
"""
import sys
from Acquisition import aq_base
import ExtensionClass
import zope.pagetemplate.pagetemplate
from zope.pagetemplate.pagetemplate import PTRuntimeError
......@@ -35,14 +37,14 @@ class PageTemplate(ExtensionClass.Base,
'request': None,
'modules': SimpleModuleImporter(),
}
parent = getattr(self, 'aq_parent', None)
parent = getattr(self, '__parent__', None)
if parent is not None:
c['here'] = parent
c['context'] = parent
c['container'] = self.aq_inner.aq_parent
while parent is not None:
self = parent
parent = getattr(self, 'aq_parent', None)
parent = getattr(self, '__parent__', None)
c['root'] = self
return c
......@@ -119,6 +121,6 @@ class PageTemplate(ExtensionClass.Base,
# implementation had this as well, but arguably on the wrong class
# (this should be a ZopePageTemplate thing if at all)
def html(self):
if not hasattr(getattr(self, 'aq_base', self), 'is_html'):
if not hasattr(aq_base(self), 'is_html'):
return self.content_type == 'text/html'
return self.is_html
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