[z3-checkins] r18584 - in z3/Five/branch/regebro-sitemanager: . site
regebro at codespeak.net
regebro at codespeak.net
Fri Oct 14 19:13:31 CEST 2005
Author: regebro
Date: Fri Oct 14 19:13:27 2005
New Revision: 18584
Added:
z3/Five/branch/regebro-sitemanager/site/
z3/Five/branch/regebro-sitemanager/site/localsite.py
- copied, changed from r18581, z3/Five/branch/regebro-sitemanager/localsite.py
z3/Five/branch/regebro-sitemanager/site/localsite.zcml
- copied unchanged from r18581, z3/Five/branch/regebro-sitemanager/localsite.zcml
Removed:
z3/Five/branch/regebro-sitemanager/localsite.py
z3/Five/branch/regebro-sitemanager/localsite.zcml
Modified:
z3/Five/branch/regebro-sitemanager/configure.zcml
z3/Five/branch/regebro-sitemanager/fiveconfigure.py
z3/Five/branch/regebro-sitemanager/fivedirectives.py
z3/Five/branch/regebro-sitemanager/interfaces.py
z3/Five/branch/regebro-sitemanager/meta.zcml
Log:
Moving things around.
Modified: z3/Five/branch/regebro-sitemanager/configure.zcml
==============================================================================
--- z3/Five/branch/regebro-sitemanager/configure.zcml (original)
+++ z3/Five/branch/regebro-sitemanager/configure.zcml Fri Oct 14 19:13:27 2005
@@ -6,11 +6,10 @@
<include file="interfaces.zcml" />
<include file="permissions.zcml" />
<include file="i18n.zcml" />
+ <include package=".site" />
<include package=".browser" />
<include package=".form" />
<include package=".skin" />
- # Localsite registers a page, and must come after browser.
- <include file="localsite.zcml" />
<include package="zope.app.event" />
<include package="zope.app.traversing" />
Modified: z3/Five/branch/regebro-sitemanager/fiveconfigure.py
==============================================================================
--- z3/Five/branch/regebro-sitemanager/fiveconfigure.py (original)
+++ z3/Five/branch/regebro-sitemanager/fiveconfigure.py Fri Oct 14 19:13:27 2005
@@ -31,14 +31,11 @@
from zope.configuration.exceptions import ConfigurationError
from zope.app.component.interface import provideInterface
from zope.app.component.metaconfigure import adapter
-from zope.app.utility.interfaces import ILocalUtilityService
-from zope.app.site.interfaces import IPossibleSite, ISite
from viewable import Viewable
from traversable import Traversable
from bridge import fromZ2Interface
from browser.metaconfigure import page
-from localsite import FiveSite, SimpleLocalUtilityService
debug_mode = App.config.getConfiguration().debug_mode
@@ -239,59 +236,6 @@
page(_context, name=name, permission=permission,
layer=layer, for_=for_, template=fname)
-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_)
# clean up code
@@ -325,19 +269,11 @@
killMonkey(class_, '__browser_default__', '__fallback_default__',
'__five_viewable__')
-def uinstallSiteHook(class_):
- delattr(class_, 'getSiteManager')
- delattr(class_, 'setSiteManager')
- classImplementsOnly(class_, implementedBy(class_)-IPossibleSite)
- _localsite_monkies.remove(class_)
-
def cleanUp():
for class_ in _traversable_monkies:
untraversable(class_)
for class_ in _defaultviewable_monkies:
undefaultViewable(class_)
- for class_ in _localsite_monkies:
- uinstallSiteHook(class_)
from zope.testing.cleanup import addCleanUp
addCleanUp(cleanUp)
Modified: z3/Five/branch/regebro-sitemanager/fivedirectives.py
==============================================================================
--- z3/Five/branch/regebro-sitemanager/fivedirectives.py (original)
+++ z3/Five/branch/regebro-sitemanager/fivedirectives.py Fri Oct 14 19:13:27 2005
@@ -105,22 +105,3 @@
required=True
)
-class ISiteDirective(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
Modified: z3/Five/branch/regebro-sitemanager/interfaces.py
==============================================================================
--- z3/Five/branch/regebro-sitemanager/interfaces.py (original)
+++ z3/Five/branch/regebro-sitemanager/interfaces.py Fri Oct 14 19:13:27 2005
@@ -35,10 +35,6 @@
menu items.
"""
-class IFiveSite(ISite):
- """Five specialization of ISite
- """
-
#
# BBB: Zope core interfaces
#
Deleted: /z3/Five/branch/regebro-sitemanager/localsite.py
==============================================================================
--- /z3/Five/branch/regebro-sitemanager/localsite.py Fri Oct 14 19:13:27 2005
+++ (empty file)
@@ -1,206 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 Five Contributors. All rights reserved.
-#
-# This software is distributed under the terms of the Zope Public
-# License (ZPL) v2.1. See COPYING.txt for more information.
-#
-##############################################################################
-"""
-$Id: traversable.py 9776 2005-03-15 09:18:43Z dreamcatcher $
-"""
-
-from zope.event import notify
-from zope.interface import directlyProvides, directlyProvidedBy
-from zope.interface import implements
-from zope.component import getGlobalServices
-from zope.component.interfaces import IServiceService, IUtilityService
-from zope.app.utility.interfaces import ILocalUtilityService
-from zope.component.exceptions import ComponentLookupError
-from zope.component.servicenames import Utilities
-from zope.app.site.interfaces import ISite
-from zope.app.site.interfaces import IPossibleSite
-from zope.app.publication.zopepublication import BeforeTraverseEvent
-from zope.component.servicenames import Adapters
-
-from interfaces import IFiveSite
-from ExtensionClass import Base
-from Acquisition import aq_base, aq_inner, aq_parent
-from Products.SiteAccess.AccessRule import AccessRule
-from ZPublisher.BeforeTraverse import registerBeforeTraverse
-from ZPublisher.BeforeTraverse import unregisterBeforeTraverse
-
-def serviceServiceAdapter(ob):
- """An adapter * -> IServiceService.
-
- This is registered in place of the one in Zope 3 so that we lookup
- using acquisition instead of ILocation.
- """
- current = ob
- while True:
- if ISite.providedBy(current):
- return current.getSiteManager()
- current = aq_parent(aq_inner(current))
- if current is None:
- raise ComponentLookupError("Could not adapt %r to"
- " IServiceService" % (ob, ))
-
-HOOK_NAME = '__local_site_hook__'
-
-class LocalSiteHook(Base):
- def __call__(self, container, request):
- notify(BeforeTraverseEvent(container, request))
-
-
-def enableLocalSiteHook(obj):
- """Install __before_traverse__ hook for Local Site
- """
- # We want the original object, not stuff in between, and no acquisition
- obj = aq_base(obj)
- if not IPossibleSite.providedBy(obj):
- raise TypeError, 'Must provide IPossibleSite'
- hook = AccessRule(HOOK_NAME)
- registerBeforeTraverse(obj, hook, HOOK_NAME, 1)
-
- if not hasattr(obj, HOOK_NAME):
- setattr(obj, HOOK_NAME, LocalSiteHook())
-
- directlyProvides(obj, ISite, directlyProvidedBy(obj))
-
-def disableLocalSiteHook(obj):
- """Remove __before_traverse__ hook for Local Site
- """
- # We want the original object, not stuff in between, and no acquisition
- obj = aq_base(obj)
- if not ISite.providedBy(obj):
- raise TypeError, 'Must provide ISite'
- rules = unregisterBeforeTraverse(obj, HOOK_NAME)
- if hasattr(obj, HOOK_NAME):
- delattr(obj, HOOK_NAME)
-
- directlyProvides(obj, directlyProvidedBy(obj) - ISite)
-
-class LocalService:
- implements(IServiceService)
-
- def __init__(self, context):
- self.context = context
-
- def getServiceDefinitions(self):
- """Retrieve all Service Definitions
-
- Should return a list of tuples (name, interface)
- """
- return getGlobalServices().getServiceDefinitions()
-
- def getInterfaceFor(self, name):
- """Retrieve the service interface for the given name
- """
- return getGlobalServices().getInterfaceFor(name)
-
- def getService(self, name):
- """Retrieve a service implementation
-
- Raises ComponentLookupError if the service can't be found.
- """
- if name in (Utilities,):
- return SimpleLocalUtilityService(self.context)
- return getGlobalServices().getService(name)
-
-class SimpleLocalUtilityService:
- implements(ILocalUtilityService)
-
- def __init__(self, context):
- self.context = context
-
- def getUtility(self, interface, name=''):
- """See IUtilityService interface
- """
- c = self.queryUtility(interface, name)
- if c is not None:
- return c
- raise ComponentLookupError(interface, name)
-
- def queryUtility(self, interface, name='', default=None):
- """See IUtilityService interface
- """
- if name == '':
- # Singletons. Only one per interface allowed, so, let's call it
- # by the interface.
- name = interface.getName()
- utilities = getattr(self.context, 'utilities')
- utility = utilities._getOb(name, None)
- if utility is None:
- return default
- if not interface.providedBy(utility):
- return default
- return utility
-
- def getUtilitiesFor(self, interface):
- utilities = getattr(self.context, 'utilities')
- for utility in utilities.objectValues():
- if interface.providedBy(utility):
- yield (utility.getId(), utility)
-
- def getAllUtilitiesRegisteredFor(self, interface):
- # This also supposedly returns "overridden" utilities, but we don't
- # keep them around. It also does not return the name-value pair that
- # getUtilitiesFor returns.
- utilities = getattr(self.context, 'utilities')
- for utility in utilities.objectValues():
- if interface.providedBy(utility):
- yield utility
-
- def registerUtility(self, interface, utility, name=''):
- # I think you are *really* supposed to:
- # 1. Check if there is a "registrations" object for utilities.
- # 2. If not create one.
- # 3. Get it.
- # 4. Create a registration object for the utility.
- # 5. Rgister the registration object in the registrations.
- # But that is quite complex, and Jim sais he wants to change that
- # anyway, and in any case the way you would normally do this in Zope3
- # and Five would probably differ anyway, so, here is this new
- # Five-only, easy to use method!
-
- utilities = getattr(self.context, 'utilities', None)
- if utilities is None:
- from OFS.Folder import Folder
- self.context._setObject('utilities', Folder('utilities'))
- utilities = self.context.utilities
-
- if name == '':
- # Singletons. Only one per interface allowed, so, let's call it
- # by the interface.
- name = interface.getName()
-
- utilities._setObject(name, utility)
-
-
-class FiveSite:
- implements(IPossibleSite)
-
- def __init__(self, context):
- self.context = context
-
- def getSiteManager(self):
- return LocalService(self)
-
- def setSiteManager(self, sm):
- raise NotImplementedError('This class has a fixed site manager')
-
-
-from Products.Five.browser import BrowserView
-
-class MakeSite(BrowserView):
- """View for convering a possible site to a site
- """
-
- def makeSite(self):
- """Convert a possible site to a site"""
- if ISite.providedBy(self.context):
- raise ValueError('This is already a site')
-
- enableLocalSiteHook(self.context)
- return "This object is now a site"
-
\ No newline at end of file
Deleted: /z3/Five/branch/regebro-sitemanager/localsite.zcml
==============================================================================
--- /z3/Five/branch/regebro-sitemanager/localsite.zcml Fri Oct 14 19:13:27 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>
Modified: z3/Five/branch/regebro-sitemanager/meta.zcml
==============================================================================
--- z3/Five/branch/regebro-sitemanager/meta.zcml (original)
+++ z3/Five/branch/regebro-sitemanager/meta.zcml Fri Oct 14 19:13:27 2005
@@ -2,6 +2,7 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:meta="http://namespaces.zope.org/meta">
+ <include package=".site" file="meta.zcml" />
<include package=".browser" file="meta.zcml" />
<include package=".form" file="meta.zcml" />
@@ -161,12 +162,6 @@
schema=".fivedirectives.IBridgeDirective"
handler=".fiveconfigure.bridge"
/>
-
- <meta:directive
- name="localsite"
- schema=".fivedirectives.ISiteDirective"
- handler=".fiveconfigure.installSiteHook"
- />
</meta:directives>
Copied: z3/Five/branch/regebro-sitemanager/site/localsite.py (from r18581, z3/Five/branch/regebro-sitemanager/localsite.py)
==============================================================================
--- z3/Five/branch/regebro-sitemanager/localsite.py (original)
+++ z3/Five/branch/regebro-sitemanager/site/localsite.py Fri Oct 14 19:13:27 2005
@@ -23,7 +23,6 @@
from zope.app.publication.zopepublication import BeforeTraverseEvent
from zope.component.servicenames import Adapters
-from interfaces import IFiveSite
from ExtensionClass import Base
from Acquisition import aq_base, aq_inner, aq_parent
from Products.SiteAccess.AccessRule import AccessRule
@@ -74,7 +73,7 @@
obj = aq_base(obj)
if not ISite.providedBy(obj):
raise TypeError, 'Must provide ISite'
- rules = unregisterBeforeTraverse(obj, HOOK_NAME)
+ unregisterBeforeTraverse(obj, HOOK_NAME)
if hasattr(obj, HOOK_NAME):
delattr(obj, HOOK_NAME)
More information about the z3-checkins
mailing list