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