[Checkins] SVN: GenericSetup/branches/1.3/ Merged r78272 from the
trunk.
Hanno Schlichting
plone at hannosch.info
Sat Jul 21 16:53:11 EDT 2007
Log message for revision 78273:
Merged r78272 from the trunk.
Changed:
U GenericSetup/branches/1.3/CHANGES.txt
U GenericSetup/branches/1.3/components.py
U GenericSetup/branches/1.3/tests/test_components.py
-=-
Modified: GenericSetup/branches/1.3/CHANGES.txt
===================================================================
--- GenericSetup/branches/1.3/CHANGES.txt 2007-07-21 20:50:45 UTC (rev 78272)
+++ GenericSetup/branches/1.3/CHANGES.txt 2007-07-21 20:53:10 UTC (rev 78273)
@@ -1,5 +1,10 @@
GenericSetup Product Changelog
+ - components: Removed non-functional support for registering objects in
+ nested folders. We only support objects available in the component
+ registry's parent now. The component registry needs to be either
+ acquisition wrapped or have a __parent__ pointer to get to the parent.
+
GenericSetup 1.3-beta (07/12/2007)
- Guard against situations where encoded text may be compared by the
Modified: GenericSetup/branches/1.3/components.py
===================================================================
--- GenericSetup/branches/1.3/components.py 2007-07-21 20:50:45 UTC (rev 78272)
+++ GenericSetup/branches/1.3/components.py 2007-07-21 20:53:10 UTC (rev 78273)
@@ -130,27 +130,35 @@
obj_path = child.getAttribute('object')
if obj_path:
- site = aq_parent(self.context)
- # we support registering aq_wrapped objects only for now
- if hasattr(site, 'aq_base'):
- # filter out empty path segments
- path = [f for f in obj_path.split('/') if f]
- # support for nested folder
- obj = self._recurseFolder(site, path)
- if obj is not None:
- self.context.registerUtility(aq_base(obj), provided, name)
+ # Get the site by either __parent__ or Acquisition
+ site = getattr(self.context, '__parent__', None)
+ if site is None:
+ site = aq_parent(self.context)
+ # Support for registering the site itself
+ if obj_path in ('', '/'):
+ obj = site
else:
- # Log an error, not aq_wrapped
- self._logger.warning("The object %s was not acquisition "
- "wrapped. Registering these is not "
- "supported right now." % obj_path)
+ # BBB: filter out path segments, we did claim to support
+ # nested paths once
+ id_ = [p for p in obj_path.split('/') if p][0]
+ obj = getattr(site, id_, None)
+
+ if obj is not None:
+ self.context.registerUtility(aq_base(obj), provided, name)
+ else:
+ # Log an error, object not found
+ self._logger.warning("The object %s was not found, while "
+ "trying to register an utility. The "
+ "provided object definition was %s. "
+ "The site used was: %s"
+ % (path, obj_path, repr(site)))
elif component:
self.context.registerUtility(component, provided, name)
elif factory is not None:
self.context.registerUtility(factory(), provided, name)
else:
- self._logger.error("Invalid utility registration for "
- "interface %s" % provided)
+ self._logger.warning("Invalid utility registration for "
+ "interface %s" % provided)
def _extractAdapters(self):
fragment = self._doc.createDocumentFragment()
@@ -200,19 +208,10 @@
child.setAttribute('name', name)
comp = registration.component
- # check if the component is acquisition wrapped. If it is export
+ # check if the component is acquisition wrapped. If it is, export
# an object reference instead of a factory reference
- if hasattr(comp, 'aq_base'):
- # if the site is acquistion wrapped as well, get the relative
- # path to the site
- path = '/'.join(comp.getPhysicalPath())
- site = aq_parent(self.context)
- if hasattr(site, 'aq_base'):
- site_path = '/'.join(site.getPhysicalPath())
- rel_path = path[len(site_path):]
- if not rel_path:
- rel_path = '/'
- child.setAttribute('object', rel_path)
+ if getattr(comp, 'aq_base', None) is not None:
+ child.setAttribute('object', comp.getId())
else:
factory = _getDottedName(type(comp))
child.setAttribute('factory', factory)
@@ -221,16 +220,7 @@
return fragment
- def _recurseFolder(self, site, path):
- root = site
- for pathsegment in path:
- if root is None:
- break
- root = getattr(root, pathsegment, None)
- return root
-
-
def dummyGetId():
return ''
Modified: GenericSetup/branches/1.3/tests/test_components.py
===================================================================
--- GenericSetup/branches/1.3/tests/test_components.py 2007-07-21 20:50:45 UTC (rev 78272)
+++ GenericSetup/branches/1.3/tests/test_components.py 2007-07-21 20:53:10 UTC (rev 78273)
@@ -109,10 +109,10 @@
interface="Products.GenericSetup.tests.test_components.IDummyInterface"/>
<utility name="dummy tool name"
interface="Products.GenericSetup.tests.test_components.IDummyInterface"
- object="/dummy_tool"/>
+ object="dummy_tool"/>
<utility name="dummy tool name2"
interface="Products.GenericSetup.tests.test_components.IDummyInterface"
- object="/dummy_tool2"/>
+ object="dummy_tool2"/>
<utility name="foo"
factory="Products.GenericSetup.tests.test_components.DummyUtility"
interface="Products.GenericSetup.tests.test_components.IDummyInterface"/>
@@ -129,10 +129,10 @@
obj.registerUtility(DummyUtility(), IDummyInterface)
obj.registerUtility(DummyUtility(), IDummyInterface, name=u'foo')
- tool = self.app['dummy_tool']
+ tool = aq_base(self.app['dummy_tool'])
obj.registerUtility(tool, IDummyInterface, name=u'dummy tool name')
- tool2 = self.app['dummy_tool2']
+ tool2 = aq_base(self.app['dummy_tool2'])
obj.registerUtility(tool2, IDummyInterface, name=u'dummy tool name2')
def test_body_get(self):
@@ -146,29 +146,20 @@
adapted = getMultiAdapter((self._obj, context), IBody)
adapted.body = self._BODY
self._verifyImport(self._obj)
- # XXX The output isn't the same anymore as we have no way to
- # differentiate between an object based utility creation and a factory
- # based one. Need to adjust tests in a smarter way.
- # self.assertEqual(adapted.body, self._BODY)
+ self.assertEqual(adapted.body, self._BODY)
# now in update mode
context._should_purge = False
adapted = getMultiAdapter((self._obj, context), IBody)
adapted.body = self._BODY
self._verifyImport(self._obj)
- # XXX The output isn't the same anymore as we have no way to
- # differentiate between an object based utility creation and a factory
- # based one. Need to adjust tests in a smarter way.
- # self.assertEqual(adapted.body, self._BODY)
+ self.assertEqual(adapted.body, self._BODY)
# and again in update mode
adapted = getMultiAdapter((self._obj, context), IBody)
adapted.body = self._BODY
self._verifyImport(self._obj)
- # XXX The output isn't the same anymore as we have no way to
- # differentiate between an object based utility creation and a factory
- # based one. Need to adjust tests in a smarter way.
- # self.assertEqual(adapted.body, self._BODY)
+ self.assertEqual(adapted.body, self._BODY)
def _getTargetClass(self):
from Products.GenericSetup.components import \
@@ -241,4 +232,3 @@
if __name__ == '__main__':
from Products.GenericSetup.testing import run
run(test_suite())
-
More information about the Checkins
mailing list