[Checkins]
SVN: five.localsitemanager/trunk/src/five/localsitemanager/
Did some restructuring and clean up. The components module is
not required
Rocky Burt
rocky at serverzen.com
Thu Feb 22 10:57:11 EST 2007
Log message for revision 72763:
Did some restructuring and clean up. The components module is not required
yet; we'll add it when we need it.
Changed:
U five.localsitemanager/trunk/src/five/localsitemanager/__init__.py
U five.localsitemanager/trunk/src/five/localsitemanager/browser.py
D five.localsitemanager/trunk/src/five/localsitemanager/components.py
U five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
-=-
Modified: five.localsitemanager/trunk/src/five/localsitemanager/__init__.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/__init__.py 2007-02-22 14:58:44 UTC (rev 72762)
+++ five.localsitemanager/trunk/src/five/localsitemanager/__init__.py 2007-02-22 15:57:10 UTC (rev 72763)
@@ -1 +1,22 @@
-# make this directory a package
+from zope.component.globalregistry import base
+from zope.app.component.interfaces import ISite
+from zope.component.persistentregistry import PersistentComponents
+from Products.Five.component.interfaces import IObjectManagerSite
+from Products.Five.component import enableSite
+
+def make_site(obj, iface=ISite):
+ """Give the specified object required qualities to identify it as a proper
+ ISite.
+ """
+
+ # we intentionally test for ISite and not iface
+ if ISite.providedBy(obj):
+ raise ValueError('This is already a site')
+
+ enableSite(obj, iface=iface)
+
+ components = PersistentComponents(name='five', bases=(base,))
+ obj.setSiteManager(components)
+
+def make_objectmanager_site(obj):
+ make_site(obj, IObjectManagerSite)
Modified: five.localsitemanager/trunk/src/five/localsitemanager/browser.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/browser.py 2007-02-22 14:58:44 UTC (rev 72762)
+++ five.localsitemanager/trunk/src/five/localsitemanager/browser.py 2007-02-22 15:57:10 UTC (rev 72763)
@@ -1,22 +1,9 @@
-from five.localsitemanager.components import FivePersistentComponents
-from zope.component.globalregistry import base
-
+from five.localsitemanager import make_objectmanager_site
from Products.Five.component.browser import ObjectManagerSiteView
-from Products.Five.component.interfaces import IObjectManagerSite
-from Products.Five.component import enableSite
class ObjectManagerSiteView(ObjectManagerSiteView):
"""Configure the site setup for an ObjectManager.
"""
def makeSite(self):
- if IObjectManagerSite.providedBy(self.context):
- raise ValueError('This is already a site')
-
- enableSite(self.context, iface=IObjectManagerSite)
-
- #TODO in the future we'll have to walk up to other site
- # managers and put them in the bases
- components = FivePersistentComponents()
- components.__bases__ = (base,)
- self.context.setSiteManager(components)
+ make_objectmanager_site(self.context)
Deleted: five.localsitemanager/trunk/src/five/localsitemanager/components.py
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/components.py 2007-02-22 14:58:44 UTC (rev 72762)
+++ five.localsitemanager/trunk/src/five/localsitemanager/components.py 2007-02-22 15:57:10 UTC (rev 72763)
@@ -1,4 +0,0 @@
-from zope.component.persistentregistry import PersistentComponents
-
-class FivePersistentComponents(PersistentComponents):
- pass
Modified: five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt
===================================================================
--- five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2007-02-22 14:58:44 UTC (rev 72762)
+++ five.localsitemanager/trunk/src/five/localsitemanager/localsitemanager.txt 2007-02-22 15:57:10 UTC (rev 72763)
@@ -12,13 +12,17 @@
>>> import zope.component
>>> from zope.app.component.hooks import setSite as setActiveSite
- >>> from five.localsitemanager.browser import ObjectManagerSiteView
- >>> siteconfig = ObjectManagerSiteView(site, None)
- >>> siteconfig.makeSite()
+ >>> from five.localsitemanager import make_objectmanager_site
+ >>> make_objectmanager_site(site)
>>> sitemanager = site.getSiteManager()
>>> sitemanager
- <FivePersistentComponents ...>
+ <PersistentComponents five>
+Make sure this site has it's ``__bases__`` configure appropriately.
+
+ >>> sitemanager.__bases__
+ (<BaseGlobalComponents ...>,)
+
Utilities
---------
@@ -28,19 +32,19 @@
>>> from OFS.SimpleItem import SimpleItem
>>> from zope import interface
- >>> class ITestUtility(interface.Interface):
- ... def helloworld(): pass
-
- >>> class TestUtility(SimpleItem):
+ >>> class ITestUtility(interface.Interface): pass
+ >>> class TestUtility(object):
... interface.implements(ITestUtility)
- ... def helloworld(self):
- ... print 'Hello World'
+ ... def __init__(self, id):
+ ... self.id = id
+ ... def __repr__(self):
+ ... return '<Utility %s "%s">' % (self.__class__.__name__, self.id)
>>> sitemanager.registerUtility(TestUtility('test'),
... name=u'hello_world',
... provided=ITestUtility)
>>> sitemanager.getUtility(ITestUtility, name=u'hello_world')
- <TestUtility ...>
+ <Utility TestUtility "test">
Make sure the utility lookup only works when the correct active site has
been configured.
@@ -51,7 +55,7 @@
>>> setActiveSite(site)
>>> zope.component.queryUtility(ITestUtility, name=u'hello_world')
- <TestUtility ...>
+ <Utility TestUtility "test">
Adapters
---------
@@ -63,27 +67,35 @@
>>> from zope import interface
>>> class IFoo(interface.Interface): pass
- >>> class Foo(object): interface.implements(IFoo)
+ >>> class Foo(object):
+ ... interface.implements(IFoo)
+ ... def __init__(self, id):
+ ... self.id = id
>>> class ITestAdapter(interface.Interface): pass
- >>> class TestAdapter(SimpleItem): interface.implements(ITestAdapter)
+ >>> class TestAdapter(object):
+ ... interface.implements(ITestAdapter)
+ ... def __init__(self, context):
+ ... self.context = context
+ ... def __repr__(self):
+ ... return '<Adapter %s adapting "%s">' % (self.__class__.__name__,
+ ... self.context.id)
-
>>> sitemanager.registerAdapter(TestAdapter,
... required=(IFoo,),
... provided=ITestAdapter)
- >>> sitemanager.getAdapter(Foo(), ITestAdapter)
- <TestAdapter ...>
+ >>> sitemanager.getAdapter(Foo('foo'), ITestAdapter)
+ <Adapter TestAdapter adapting "foo">
Make sure the adapter lookup only works when the correct active site has
been configured.
>>> setActiveSite(None)
- >>> zope.component.queryAdapter(Foo(), ITestAdapter) is None
+ >>> zope.component.queryAdapter(Foo('foo'), ITestAdapter) is None
True
>>> setActiveSite(site)
- >>> zope.component.queryAdapter(Foo(), ITestAdapter)
- <TestAdapter ...>
- >>> ITestAdapter(Foo())
- <TestAdapter ...>
+ >>> zope.component.queryAdapter(Foo('foo'), ITestAdapter)
+ <Adapter TestAdapter adapting "foo">
+ >>> ITestAdapter(Foo('foo'))
+ <Adapter TestAdapter adapting "foo">
More information about the Checkins
mailing list