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