Commit 0e8cb653 authored by Hanno Schlichting's avatar Hanno Schlichting

No longer rely on Acquisition wrappers

parent 786545da
......@@ -19,6 +19,8 @@ from bisect import bisect
from random import randint
import Acquisition
from Acquisition import aq_base
from Acquisition import aq_parent
import ExtensionClass
from Missing import MV
from Persistence import Persistent
......@@ -123,13 +125,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
if type(index) is ttype:
# then it contains a score...
normalized_score, score, key = index
r=self._v_result_class(self.data[key]).__of__(self.aq_parent)
r=self._v_result_class(self.data[key]).__of__(aq_parent(self))
r.data_record_id_ = key
r.data_record_score_ = score
r.data_record_normalized_score_ = normalized_score
else:
# otherwise no score, set all scores to 1
r=self._v_result_class(self.data[index]).__of__(self.aq_parent)
r=self._v_result_class(self.data[index]).__of__(aq_parent(self))
r.data_record_id_ = index
r.data_record_score_ = 1
r.data_record_normalized_score_ = 1
......@@ -590,7 +592,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
"""
score, key = item
r=self._v_result_class(self.data[key])\
.__of__(self.aq_parent)
.__of__(aq_parent(self))
r.data_record_id_ = key
r.data_record_score_ = score
r.data_record_normalized_score_ = int(100. * score / max)
......@@ -623,7 +625,6 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# Try to avoid all non-local attribute lookup inside
# those loops.
assert limit is None or limit > 0, 'Limit value must be 1 or greater'
_lazymap = LazyMap
_intersection = intersection
_self__getitem__ = self.__getitem__
index_key_map = sort_index.documentToKeyMap()
......@@ -820,7 +821,7 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
def getCatalogReport(self, query=None):
"""Reports about the duration of queries.
"""
parent = Acquisition.aq_base(Acquisition.aq_parent(self))
parent = aq_base(aq_parent(self))
threshold = getattr(parent, 'long_query_time', 0.1)
return CatalogReport(self, query, threshold)
......
......@@ -14,6 +14,7 @@
from zope.interface import implements
import Acquisition
from Acquisition import aq_parent
import Record
from ZODB.POSException import ConflictError
......@@ -39,7 +40,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
def getPath(self):
"""Get the physical path for this record"""
return self.aq_parent.getpath(self.data_record_id_)
return aq_parent(self).getpath(self.data_record_id_)
def getURL(self, relative=0):
"""Generate a URL for this record"""
......@@ -51,7 +52,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
Same as getObject, but does not do security checks.
"""
try:
return self.aq_parent.unrestrictedTraverse(self.getPath())
return aq_parent(self).unrestrictedTraverse(self.getPath())
except ConflictError:
raise
except Exception:
......@@ -73,7 +74,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
path = self.getPath().split('/')
if not path:
return None
parent = self.aq_parent
parent = aq_parent(self)
if len(path) > 1:
try:
parent = parent.unrestrictedTraverse(path[:-1])
......
......@@ -26,6 +26,8 @@ from AccessControl.Permissions import manage_zcatalog_entries
from AccessControl.Permissions import manage_zcatalog_indexes
from AccessControl.Permissions import search_zcatalog
from AccessControl.SecurityInfo import ClassSecurityInfo
from Acquisition import aq_base
from Acquisition import aq_parent
from Acquisition import Implicit
from App.Dialogs import MessageDialog
from App.special_dtml import DTMLFile
......@@ -561,7 +563,7 @@ class ZCatalog(Folder, Persistent, Implicit):
def getobject(self, rid, REQUEST=None):
"""Return a cataloged object given a 'data_record_id_'
"""
return self.aq_parent.unrestrictedTraverse(self.getpath(rid))
return aq_parent(self).unrestrictedTraverse(self.getpath(rid))
def getMetadataForUID(self, uid):
"""return the correct metadata given the uid, usually the path"""
......@@ -656,19 +658,10 @@ class ZCatalog(Folder, Persistent, Implicit):
return self._catalog.search(
query_request, sort_index, reverse, limit, merge)
## this stuff is so the find machinery works
## this stuff is so the find machinery works
meta_types=() # Sub-object types that are specific to this object
# Dont need this anymore -- we inherit from object manager
#def all_meta_types(self):
# pmt=()
# if hasattr(self, '_product_meta_types'): pmt=self._product_meta_types
# elif hasattr(self, 'aq_acquire'):
# try: pmt=self.aq_acquire('_product_meta_types')
# except AttributeError: pass
# return self.meta_types+Products.meta_types+pmt
security.declareProtected(search_zcatalog, 'valid_roles')
def valid_roles(self):
"Return list of valid roles"
......@@ -682,10 +675,10 @@ class ZCatalog(Folder, Persistent, Implicit):
for role in roles:
if not dup(role):
dict[role]=1
if not hasattr(obj, 'aq_parent'):
obj = aq_parent(obj)
if obj is None:
break
obj=obj.aq_parent
x=x+1
x = x + 1
roles=dict.keys()
roles.sort()
return roles
......@@ -726,9 +719,7 @@ class ZCatalog(Folder, Persistent, Implicit):
md=td()
obj_expr=(Eval(obj_expr), md, md._push, md._pop)
base=obj
if hasattr(obj, 'aq_base'):
base=obj.aq_base
base = aq_base(obj)
if not hasattr(base, 'objectItems'):
return result
......@@ -750,9 +741,7 @@ class ZCatalog(Folder, Persistent, Implicit):
if hasattr(ob, '_p_changed') and (ob._p_changed == None):
dflag=1
if hasattr(ob, 'aq_base'):
bs=ob.aq_base
else: bs=ob
bs = aq_base(ob)
if (
(not obj_ids or absattr(bs.id) in obj_ids)
......@@ -1055,8 +1044,8 @@ def role_match(ob, permission, roles, lt=type([]), tt=type(())):
p=getattr(ob, permission)
if type(p) is lt:
map(fn, p)
if hasattr(ob, 'aq_parent'):
ob=ob.aq_parent
ob = aq_parent(ob)
if ob is not None:
continue
break
if type(p) is tt:
......@@ -1066,8 +1055,8 @@ def role_match(ob, permission, roles, lt=type([]), tt=type(())):
map(fn, ('Manager', 'Anonymous'))
break
if hasattr(ob, 'aq_parent'):
ob=ob.aq_parent
ob = aq_parent(ob)
if ob is not None:
continue
break
......
......@@ -16,6 +16,8 @@
from AccessControl.class_init import InitializeClass
from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.Permissions import manage_zcatalog_indexes
from Acquisition import aq_base
from Acquisition import aq_parent
from Acquisition import Implicit
from App.special_dtml import DTMLFile
from OFS.Folder import Folder
......@@ -58,26 +60,25 @@ class ZCatalogIndexes(IFAwareObjectManager, Folder, Persistent, Implicit):
# base accessors loop back through our dictionary interface
def _setOb(self, id, object):
indexes = self.aq_parent._catalog.indexes
indexes = aq_parent(self)._catalog.indexes
indexes[id] = object
self.aq_parent._indexes = indexes
#self.aq_parent._p_changed = 1
aq_base(aq_parent(self))._indexes = indexes
def _delOb(self, id):
indexes = self.aq_parent._catalog.indexes
indexes = aq_parent(self)._catalog.indexes
del indexes[id]
self.aq_parent._indexes = indexes
#self.aq_parent._p_changed = 1
aq_base(aq_parent(self))._indexes = indexes
def _getOb(self, id, default=_marker):
indexes = self.aq_parent._catalog.indexes
if default is _marker: return indexes.get(id)
indexes = aq_parent(self)._catalog.indexes
if default is _marker:
return indexes.get(id)
return indexes.get(id, default)
security.declareProtected(manage_zcatalog_indexes, 'objectIds')
def objectIds(self, spec=None):
indexes = self.aq_parent._catalog.indexes
indexes = aq_parent(self)._catalog.indexes
if spec is not None:
if type(spec) == type('s'):
spec = [spec]
......@@ -101,7 +102,7 @@ class ZCatalogIndexes(IFAwareObjectManager, Folder, Persistent, Implicit):
#
def __bobo_traverse__(self, REQUEST, name):
indexes = self.aq_parent._catalog.indexes;
indexes = aq_parent(self)._catalog.indexes;
o = indexes.get(name, None)
if o is not None:
......
......@@ -16,6 +16,7 @@
import unittest
import Acquisition
from Acquisition import aq_base
from zExceptions import Unauthorized
from ZODB.POSException import ConflictError
......@@ -156,7 +157,8 @@ class BrainsTestBase(object):
def testGetObjectHappy(self):
b = self._makeBrain(1)
self.assertEqual(b.getPath(), '/happy')
self.failUnless(b.getObject().aq_base is self.cat.getobject(1).aq_base)
self.failUnless(aq_base(b.getObject()) is
aq_base(self.cat.getobject(1)))
def testGetObjectPropagatesConflictErrors(self):
b = self._makeBrain(0)
......
......@@ -386,7 +386,7 @@ class TestCatalogObject(unittest.TestCase):
for x in range(0, self.upper):
self._catalog.catalogObject(dummy(self.nums[x]), `x`)
self._catalog.aq_parent = dummy('foo') # fake out acquisition
self._catalog = self._catalog.__of__(dummy('foo'))
def tearDown(self):
self._catalog = None
......@@ -589,7 +589,7 @@ class TestRS(unittest.TestCase):
obj = objRS(random.randrange(0, 20000))
self._catalog.catalogObject(obj, i)
self._catalog.aq_parent = objRS(200)
self._catalog = self._catalog.__of__(objRS(200))
def testRangeSearch(self):
for i in range(1000):
......@@ -618,7 +618,7 @@ class TestMerge(unittest.TestCase):
i = ZCTextIndex('title', caller=cat, index_factory=OkapiIndex,
lexicon_id='lexicon')
cat.addIndex('title', i)
cat.aq_parent = zdummy(16336)
cat = cat.__of__(zdummy(16336))
for i in range(10):
obj = zdummy(i)
obj.big = i > 5
......
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