[Zope-Checkins] SVN: Zope/trunk/src/Products/ZCatalog/ No longer rely on Acquisition wrappers
Hanno Schlichting
hannosch at hannosch.eu
Sat Jul 31 18:13:57 EDT 2010
Log message for revision 115298:
No longer rely on Acquisition wrappers
Changed:
U Zope/trunk/src/Products/ZCatalog/Catalog.py
U Zope/trunk/src/Products/ZCatalog/CatalogBrains.py
U Zope/trunk/src/Products/ZCatalog/ZCatalog.py
U Zope/trunk/src/Products/ZCatalog/ZCatalogIndexes.py
U Zope/trunk/src/Products/ZCatalog/tests/test_brains.py
U Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py
-=-
Modified: Zope/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-07-31 21:56:19 UTC (rev 115297)
+++ Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-07-31 22:13:56 UTC (rev 115298)
@@ -19,6 +19,8 @@
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 @@
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 @@
"""
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 @@
# 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 @@
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)
Modified: Zope/trunk/src/Products/ZCatalog/CatalogBrains.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/CatalogBrains.py 2010-07-31 21:56:19 UTC (rev 115297)
+++ Zope/trunk/src/Products/ZCatalog/CatalogBrains.py 2010-07-31 22:13:56 UTC (rev 115298)
@@ -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 @@
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 @@
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 @@
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])
Modified: Zope/trunk/src/Products/ZCatalog/ZCatalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/ZCatalog.py 2010-07-31 21:56:19 UTC (rev 115297)
+++ Zope/trunk/src/Products/ZCatalog/ZCatalog.py 2010-07-31 22:13:56 UTC (rev 115298)
@@ -26,6 +26,8 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
Modified: Zope/trunk/src/Products/ZCatalog/ZCatalogIndexes.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/ZCatalogIndexes.py 2010-07-31 21:56:19 UTC (rev 115297)
+++ Zope/trunk/src/Products/ZCatalog/ZCatalogIndexes.py 2010-07-31 22:13:56 UTC (rev 115298)
@@ -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 @@
# 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 @@
#
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:
Modified: Zope/trunk/src/Products/ZCatalog/tests/test_brains.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/tests/test_brains.py 2010-07-31 21:56:19 UTC (rev 115297)
+++ Zope/trunk/src/Products/ZCatalog/tests/test_brains.py 2010-07-31 22:13:56 UTC (rev 115298)
@@ -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 @@
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)
Modified: Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py 2010-07-31 21:56:19 UTC (rev 115297)
+++ Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py 2010-07-31 22:13:56 UTC (rev 115298)
@@ -386,7 +386,7 @@
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 @@
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 @@
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
More information about the Zope-Checkins
mailing list