[z3-checkins] r18586 - in z3/Five/branch/regebro-sitemanager/site:
. tests
regebro at codespeak.net
regebro at codespeak.net
Fri Oct 14 19:25:21 CEST 2005
Author: regebro
Date: Fri Oct 14 19:25:17 2005
New Revision: 18586
Added:
z3/Five/branch/regebro-sitemanager/site/__init__.py (contents, props changed)
z3/Five/branch/regebro-sitemanager/site/configure.zcml
- copied unchanged from r18584, z3/Five/branch/regebro-sitemanager/site/localsite.zcml
z3/Five/branch/regebro-sitemanager/site/metaconfigure.py (contents, props changed)
z3/Five/branch/regebro-sitemanager/site/metadirectives.py (contents, props changed)
z3/Five/branch/regebro-sitemanager/site/tests/
z3/Five/branch/regebro-sitemanager/site/tests/__init__.py (contents, props changed)
z3/Five/branch/regebro-sitemanager/site/tests/test_localsite.py
- copied, changed from r18579, z3/Five/branch/regebro-sitemanager/tests/test_localservice.py
Removed:
z3/Five/branch/regebro-sitemanager/site/localsite.zcml
Log:
Rearranging complete (at least the tests run)
Added: z3/Five/branch/regebro-sitemanager/site/__init__.py
==============================================================================
Deleted: /z3/Five/branch/regebro-sitemanager/site/localsite.zcml
==============================================================================
--- /z3/Five/branch/regebro-sitemanager/site/localsite.zcml Fri Oct 14 19:25:17 2005
+++ (empty file)
@@ -1,42 +0,0 @@
-<configure xmlns="http://namespaces.zope.org/zope"
- xmlns:browser="http://namespaces.zope.org/browser">
-
- <!-- enough to bootstrap the machinery to lookup local services -->
- <include package="zope.configuration" file="meta.zcml" />
- <hook
- module="zope.component"
- name="getServices"
- implementation="zope.app.component.hooks.getServices_hook"
- />
-
- <hook
- module="zope.component"
- name="adapter_hook"
- implementation="zope.app.component.hooks.adapter_hook"
- />
-
- <adapter
- factory=".localsite.serviceServiceAdapter"
- provides="zope.component.IServiceService"
- for="zope.interface.Interface"
- />
-
- <subscriber
- factory="zope.app.component.localservice.threadSiteSubscriber"
- for="zope.app.publication.interfaces.IBeforeTraverseEvent"
- />
-
- <subscriber
- factory="zope.app.component.localservice.clearThreadSiteSubscriber"
- for="zope.app.publication.interfaces.IEndRequestEvent"
- />
-
- <browser:page
- for="zope.app.site.interfaces.IPossibleSite"
- name="addServiceManager.html"
- permission="zope2.Public"
- class=".localsite.MakeSite"
- attribute="makeSite"
- />
-
-</configure>
Added: z3/Five/branch/regebro-sitemanager/site/metaconfigure.py
==============================================================================
--- (empty file)
+++ z3/Five/branch/regebro-sitemanager/site/metaconfigure.py Fri Oct 14 19:25:17 2005
@@ -0,0 +1,94 @@
+##############################################################################
+#
+# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Five-specific directive handlers
+
+These directives are specific to Five and have no equivalents in Zope 3.
+
+$Id: fiveconfigure.py 18581 2005-10-14 16:54:25Z regebro $
+"""
+
+from zope.interface import classImplements, classImplementsOnly, implementedBy
+from zope.interface.interface import InterfaceClass
+from zope.configuration.exceptions import ConfigurationError
+from zope.app.component.metaconfigure import adapter
+from zope.app.utility.interfaces import ILocalUtilityService
+from zope.app.site.interfaces import IPossibleSite, ISite
+
+from localsite import FiveSite, SimpleLocalUtilityService
+
+def classSiteHook(class_, site_class):
+ setattr(class_, 'getSiteManager',
+ site_class.getSiteManager.im_func)
+ setattr(class_, 'setSiteManager',
+ site_class.setSiteManager.im_func)
+
+count = 0
+def next():
+ global count
+ count += 1
+ return count
+
+_localsite_monkies = []
+def installSiteHook(_context, class_, site_class=None, utility_service=None):
+ if site_class is None:
+ if not IPossibleSite.implementedBy(class_):
+ # This is not a possible site, we need to monkey-patch it so that
+ # it is.
+ site_class = FiveSite
+ else:
+ if not IPossibleSite.implementedBy(site_class):
+ raise ConfigurationError('Site class does not implement '
+ 'IPossibleClass: %s' % site_class)
+ if site_class is not None:
+ _context.action(
+ discriminator = (class_,),
+ callable = classSiteHook,
+ args=(class_, site_class)
+ )
+ _context.action(
+ discriminator = (class_, IPossibleSite),
+ callable = classImplements,
+ args=(class_, IPossibleSite)
+ )
+ if utility_service is None:
+ utility_service = SimpleLocalUtilityService
+ else:
+ if not ILocalUtilityService.implementedBy(utility_service):
+ raise ConfigurationError('utility_service does not implement '
+ 'ILocalUtilityService: %s' % utility_service)
+
+ # Generate a marker interface that should be unique, so that
+ # we can register the utility service only for this class.
+ iface = InterfaceClass('IFiveSite%s' % next())
+ adapter(_context, factory=(utility_service,),
+ provides=ILocalUtilityService,
+ for_=(iface,))
+ _context.action(
+ discriminator = (class_, 'UtilityMarker'),
+ callable = classImplements,
+ args=(class_, iface)
+ )
+ _localsite_monkies.append(class_)
+
+def uinstallSiteHooks():
+ for class_ in _localsite_monkies:
+ delattr(class_, 'getSiteManager')
+ delattr(class_, 'setSiteManager')
+ classImplementsOnly(class_, implementedBy(class_)-IPossibleSite)
+ _localsite_monkies.remove(class_)
+
+from zope.testing.cleanup import addCleanUp
+addCleanUp(uinstallSiteHooks)
+del addCleanUp
+
Added: z3/Five/branch/regebro-sitemanager/site/metadirectives.py
==============================================================================
--- (empty file)
+++ z3/Five/branch/regebro-sitemanager/site/metadirectives.py Fri Oct 14 19:25:17 2005
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Site support ZCML directive schemas
+
+$Id: fivedirectives.py 18581 2005-10-14 16:54:25Z regebro $
+"""
+from zope.interface import Interface
+from zope.configuration.fields import GlobalObject
+
+class ILocalSiteDirective(Interface):
+ """Make instances of class hookable for Site.
+
+ site_class is an implementation of ISite, which will have it's methods
+ monkey_patched into the the class. If not given a default implementation
+ will be used.
+ """
+ class_ = GlobalObject(
+ title=u"Class",
+ required=True
+ )
+ site_class = GlobalObject(
+ title=u"Site Class",
+ required=False
+ )
+ utility_service = GlobalObject(
+ title=u"Utility Service Class",
+ required=False
+ )
\ No newline at end of file
Added: z3/Five/branch/regebro-sitemanager/site/tests/__init__.py
==============================================================================
Copied: z3/Five/branch/regebro-sitemanager/site/tests/test_localsite.py (from r18579, z3/Five/branch/regebro-sitemanager/tests/test_localservice.py)
==============================================================================
--- z3/Five/branch/regebro-sitemanager/tests/test_localservice.py (original)
+++ z3/Five/branch/regebro-sitemanager/site/tests/test_localsite.py Fri Oct 14 19:25:17 2005
@@ -5,7 +5,7 @@
import unittest
from Testing import ZopeTestCase
-ZopeTestCase.installProduct('Five')
+#ZopeTestCase.installProduct('Five')
from zope.interface import implements
from zope.interface import directlyProvides, directlyProvidedBy
@@ -103,7 +103,8 @@
self.unparented_folder = Folder()
self.unrooted_subfolder = Wrapper(Folder(), self.unparented_folder)
zcml.load_config("meta.zcml", Products.Five)
- zcml.load_config("localsite.zcml", Products.Five)
+ zcml.load_config("permissions.zcml", Products.Five)
+ zcml.load_config("configure.zcml", Products.Five.site)
zcml_text = """<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five">
@@ -223,7 +224,7 @@
getLocalServices, unrooted_subfolder)
def test_serviceServiceAdapter(self):
- from Products.Five.localsite import serviceServiceAdapter
+ from Products.Five.site.localsite import serviceServiceAdapter
# If it is a site, return the service service.
ss = ServiceServiceStub()
@@ -279,7 +280,8 @@
def afterSetUp(self):
setUp()
zcml.load_config("meta.zcml", Products.Five)
- zcml.load_config("localsite.zcml", Products.Five)
+ zcml.load_config("permissions.zcml", Products.Five)
+ zcml.load_config("configure.zcml", Products.Five.site)
zcml_text = """<configure xmlns:five="http://namespaces.zope.org/five">
<five:localsite class="Products.Five.testing.localsite.DummySite" />
</configure>"""
@@ -292,7 +294,7 @@
def test_before_traversal_event_and_hook(self):
return
- from Products.Five.localsite import enableLocalSiteHook
+ from Products.Five.site.localsite import enableLocalSiteHook
f1 = Folder()
f1.id = 'f1'
self.folder._setObject('f1', f1)
@@ -313,10 +315,11 @@
def afterSetUp(self):
setUp()
- from Products.Five.localsite import enableLocalSiteHook
+ from Products.Five.site.localsite import enableLocalSiteHook
from Products.Five.testing.localsite import manage_addDummySite
zcml.load_config("meta.zcml", Products.Five)
- zcml.load_config("localsite.zcml", Products.Five)
+ zcml.load_config("permissions.zcml", Products.Five)
+ zcml.load_config("configure.zcml", Products.Five.site)
zcml_text = """<configure xmlns:five="http://namespaces.zope.org/five">
<five:localsite class="Products.Five.testing.localsite.DummySite" />
</configure>"""
@@ -337,7 +340,7 @@
tearDown()
def test_getServicesHook(self):
- from Products.Five.localsite import LocalService
+ from Products.Five.site.localsite import LocalService
local_sm = getServices(None)
self.failIf(local_sm is serviceManager)
self.failUnless(isinstance(local_sm, LocalService))
@@ -347,7 +350,7 @@
self.failUnless(isinstance(local_sm, LocalService))
def test_getUtilityService(self):
- from Products.Five.localsite import SimpleLocalUtilityService
+ from Products.Five.site.localsite import SimpleLocalUtilityService
utils = getService(Utilities)
self.failUnless(isinstance(utils, SimpleLocalUtilityService))
More information about the z3-checkins
mailing list