Commit caffc57c authored by Casey Duncan's avatar Casey Duncan

Fixed and documented is_acquired so that objects accessible through...

Fixed and documented is_acquired so that objects accessible through __getitem__ on a parent are not considered to be acquired anymore. Workspaces leverage this for FTP traversability.
Demoted the ugly ZClass check (id + space in objectIds) below the hasattr and __getitem__ checks which should help reduce the expense of this function.
parent 9e78041c
......@@ -13,7 +13,7 @@
"""Commonly used utility functions."""
__version__='$Revision: 1.13 $'[11:-2]
__version__='$Revision: 1.14 $'[11:-2]
import sys, os, time
......@@ -64,31 +64,49 @@ def absattr(attr, c=callable):
return attr()
return attr
def aq_base(ob, hasattr=hasattr):
def aq_base(ob, getattr=getattr):
# Return the aq_base of an object.
if hasattr(ob, 'aq_base'):
return ob.aq_base
return ob
return getattr(ob, 'aq_base', ob)
def is_acquired(ob, hasattr=hasattr, aq_base=aq_base, absattr=absattr):
# Return true if this object is not a direct
# subobject of its aq_parent object.
# Return true if this object is not considered to be
# a direct subobject of its acquisition parent
# Used to prevent acquisition side-affects in FTP traversal
# 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
return 0
parent = aq_base(ob.aq_parent)
absId = absattr(ob.id)
if hasattr(parent, absId):
# Consider direct attributes not acquired
return 0
if hasattr(parent, '__getitem__'):
# Use __getitem__ as opposed to has_key to avoid TTW namespace
# issues, and to support the most minimal mapping objects
try:
if aq_base(parent[absId]) is aq_base(ob):
# This object is an item of the aq_parent, its not acquired
return 0
except KeyError:
pass
if hasattr(parent,'_objects'):
# XXX This is really icky
# This ugly mess is for ZClass methods I think
if absId+' ' in parent.objectIds():
return 0
if hasattr(parent, absId):
return 0
if hasattr(aq_base(ob), 'isTopLevelPrincipiaApplicationObject') and \
ob.isTopLevelPrincipiaApplicationObject:
# This object the top level
return 0
return 1
return 1 # This object is acquired by our measure
def package_home(globals_dict):
......
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