[Checkins] SVN: five.localsitemanager/trunk/ Requiring zope.component >= 3.5.0.
Michael Howitz
mh at gocept.com
Wed Aug 27 03:54:15 EDT 2008
Log message for revision 90406:
Requiring zope.component >= 3.5.0.
Changed:
U five.localsitemanager/trunk/CHANGES.txt
U five.localsitemanager/trunk/buildout.cfg
U five.localsitemanager/trunk/setup.py
U five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
U five.localsitemanager/trunk/src/five/localsitemanager/registry.py
-=-
Modified: five.localsitemanager/trunk/CHANGES.txt
===================================================================
--- five.localsitemanager/trunk/CHANGES.txt 2008-08-27 07:53:20 UTC (rev 90405)
+++ five.localsitemanager/trunk/CHANGES.txt 2008-08-27 07:54:14 UTC (rev 90406)
@@ -1,9 +1,15 @@
Changelog
=========
-0.5 - Unreleased
+2.0 - Unreleased
----------------
+* Requiring zope.component >= 3.5.0.
+
+
+1.0 - Unreleased
+----------------
+
* Added buildout for project, so testing can be done using ``bin/test``.
* Added ability to register utilities with an absolute path. These
Modified: five.localsitemanager/trunk/buildout.cfg
===================================================================
--- five.localsitemanager/trunk/buildout.cfg 2008-08-27 07:53:20 UTC (rev 90405)
+++ five.localsitemanager/trunk/buildout.cfg 2008-08-27 07:54:14 UTC (rev 90406)
@@ -6,6 +6,8 @@
[zope2]
recipe = plone.recipe.zope2install
url = http://www.zope.org/Products/Zope/2.11.1/Zope-2.11.1-final.tgz
+fake-zope-eggs = true
+skip-fake-eggs = zope.component
[test]
recipe = zc.recipe.testrunner
Modified: five.localsitemanager/trunk/setup.py
===================================================================
--- five.localsitemanager/trunk/setup.py 2008-08-27 07:53:20 UTC (rev 90405)
+++ five.localsitemanager/trunk/setup.py 2008-08-27 07:54:14 UTC (rev 90406)
@@ -4,7 +4,7 @@
"""
from setuptools import setup, Extension
-version = '0.5dev'
+version = '2.0dev'
setup(name='five.localsitemanager',
version=version,
@@ -33,6 +33,7 @@
include_package_data = True,
install_requires=[
'setuptools',
+ 'zope.component >= 3.5.0',
],
zip_safe = False,
)
Modified: five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2008-08-27 07:53:20 UTC (rev 90405)
+++ five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2008-08-27 07:54:14 UTC (rev 90406)
@@ -61,6 +61,16 @@
>>> zope.component.queryUtility(ITestUtility, name=u'hello_world')
<Utility TestUtility "test">
+Utilities are also registerable as factory:
+
+ >>> def test_utility_factory():
+ ... return TestUtility('factory_test')
+ >>> sitemanager.registerUtility(factory=test_utility_factory,
+ ... name=u'factory_test',
+ ... provided=ITestUtility)
+ >>> sitemanager.getUtility(ITestUtility, name=u'factory_test')
+ <Utility TestUtility "factory_test">
+
Adapters
---------
@@ -149,15 +159,14 @@
>>> utils = [x for x in sitemanager.getUtilitiesFor(ITestUtility)]
>>> len(utils)
- 2
+ 3
>>> nonaqutils = [(name, comp)
... for name, comp in utils if not IAcquirer.providedBy(comp)]
>>> len(nonaqutils)
- 1
- >>> name, comp = nonaqutils[0]
- >>> Acquisition.aq_parent(comp) is None
- True
+ 2
+ >>> [Acquisition.aq_parent(comp) is None for name, comp in nonaqutils]
+ [True, True]
>>> aqutils = [(name, comp)
... for name, comp in utils if IAcquirer.providedBy(comp)]
@@ -172,14 +181,13 @@
>>> utils = [x for x in
... sitemanager.getAllUtilitiesRegisteredFor(ITestUtility)]
>>> len(utils)
- 2
+ 3
>>> nonaqutils = [comp for comp in utils if not IAcquirer.providedBy(comp)]
>>> len(nonaqutils)
- 1
- >>> comp = nonaqutils[0]
- >>> Acquisition.aq_parent(comp) is None
- True
+ 2
+ >>> [Acquisition.aq_parent(comp) is None for comp in nonaqutils]
+ [True, True]
>>> aqutils = [comp for comp in utils if IAcquirer.providedBy(comp)]
>>> len(aqutils)
@@ -190,16 +198,20 @@
And registeredUtilities():
+ >>> list(sitemanager.registeredUtilities())
+ [UtilityRegistration(<PersistentComponents site>, ITestUtility, u'factory_test', <Utility TestUtility "factory_test">, <function test_utility_factory at 0x...>, u''),
+ UtilityRegistration(<PersistentComponents site>, ITestUtility, u'hello_world', <Utility TestUtility "test">, None, u''),
+ UtilityRegistration(<PersistentComponents site>, ITestUtility, u'aq_wrapped', <Utility AQTestUtility "test">, None, u'')]
+
>>> utils = [ r.component for r in sitemanager.registeredUtilities() ]
>>> len(utils)
- 2
+ 3
>>> nonaqutils = [comp for comp in utils if not IAcquirer.providedBy(comp)]
>>> len(nonaqutils)
- 1
- >>> comp = nonaqutils[0]
- >>> Acquisition.aq_parent(comp) is None
- True
+ 2
+ >>> [Acquisition.aq_parent(comp) is None for comp in nonaqutils]
+ [True, True]
>>> aqutils = [comp for comp in utils if IAcquirer.providedBy(comp)]
>>> len(aqutils)
@@ -339,6 +351,11 @@
And registeredUtilities():
+ >>> list(sitemanager_a.registeredUtilities())
+ [UtilityRegistration(<PersistentComponents /a>, ITestUtility, u'with_aq_chain', si_util_cped, None, u''),
+ UtilityRegistration(<PersistentComponents /a>, ITestUtility, u'aq_wrapped', <Utility AQTestUtility "test">, None, u''),
+ UtilityRegistration(<PersistentComponents /a>, ITestUtility, u'hello_world', <Utility TestUtility "test">, None, u'')]
+
>>> utils = [r.component for r in sitemanager_a.registeredUtilities()]
>>> len(utils)
3
Modified: five.localsitemanager/trunk/src/five/localsitemanager/registry.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2008-08-27 07:53:20 UTC (rev 90405)
+++ five.localsitemanager/trunk/src/five/localsitemanager/registry.py 2008-08-27 07:54:14 UTC (rev 90406)
@@ -195,19 +195,24 @@
reg.component=_wrap(reg.component, self)
yield reg
- def registerUtility(self, component, provided=None, name=u'', info=u'',
- event=True):
+ def registerUtility(self, component=None, provided=None, name=u'', info=u'',
+ event=True, factory=None):
+ if factory:
+ if component:
+ raise TypeError("Can't specify factory and component.")
+ component = factory()
+
if provided is None:
provided = _getUtilityProvided(component)
- registration = self._utility_registrations.get((provided, name))
- if (registration == (component, info)):
+ reg = self._utility_registrations.get((provided, name))
+ if reg is not None and reg[:2] == (component, info):
# already registered
- if isinstance(registration[0], ComponentPathWrapper):
- self.utilities.unsubscribe((), provided, registration[0])
+ if isinstance(reg[0], ComponentPathWrapper):
+ self.utilities.unsubscribe((), provided, reg[0])
# update path
- registration[0].path = component.getPhysicalPath()
- self.utilities.subscribe((), provided, registration[0])
+ reg[0].path = component.getPhysicalPath()
+ self.utilities.subscribe((), provided, reg[0])
return
subscribed = False
@@ -232,7 +237,8 @@
# We have an absolute path, so we can store it.
wrapped_component = ComponentPathWrapper(
Acquisition.aq_base(component), path)
- self._utility_registrations[(provided, name)] = wrapped_component, info
+ self._utility_registrations[(provided, name)] = (
+ wrapped_component, info, factory)
self.utilities.register((), provided, name, wrapped_component)
if not subscribed:
@@ -240,6 +246,7 @@
if event:
zope.event.notify(zope.component.interfaces.Registered(
- UtilityRegistration(self, provided, name, component, info)
- ))
+ UtilityRegistration(
+ self, provided, name, component, info, factory)
+ ))
More information about the Checkins
mailing list