vendor/Five/1.2b-r20590

view site/metaconfigure.py @ 0:3673ed425f80

Vendor import of Five 1.2b+ (r20590)
author fguillaume
date Fri, 02 Dec 2005 20:25:42 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2004, 2005 Zope Corporation and Contributors.
4 # All Rights Reserved.
5 #
6 # This software is subject to the provisions of the Zope Public License,
7 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11 # FOR A PARTICULAR PURPOSE.
12 #
13 ##############################################################################
14 """Five-specific directive handlers
16 These directives are specific to Five and have no equivalents in Zope 3.
18 $Id: fiveconfigure.py 18581 2005-10-14 16:54:25Z regebro $
19 """
20 from zope.interface import classImplements, classImplementsOnly, implementedBy
21 from zope.interface.interface import InterfaceClass
22 from zope.configuration.exceptions import ConfigurationError
23 from zope.app.component.metaconfigure import adapter
24 from zope.app.site.interfaces import IPossibleSite
26 from Products.Five.site.localsite import FiveSite
28 def classSiteHook(class_, site_class):
29 setattr(class_, 'getSiteManager',
30 site_class.getSiteManager.im_func)
31 setattr(class_, 'setSiteManager',
32 site_class.setSiteManager.im_func)
34 _localsite_monkies = []
35 def installSiteHook(_context, class_, site_class=None):
36 if site_class is None:
37 if not IPossibleSite.implementedBy(class_):
38 # This is not a possible site, we need to monkey-patch it so that
39 # it is.
40 site_class = FiveSite
41 else:
42 if not IPossibleSite.implementedBy(site_class):
43 raise ConfigurationError('Site class does not implement '
44 'IPossibleClass: %s' % site_class)
45 if site_class is not None:
46 _context.action(
47 discriminator = (class_,),
48 callable = classSiteHook,
49 args=(class_, site_class)
50 )
51 _context.action(
52 discriminator = (class_, IPossibleSite),
53 callable = classImplements,
54 args=(class_, IPossibleSite)
55 )
56 _localsite_monkies.append(class_)
58 # clean up code
60 def uninstallSiteHooks():
61 for class_ in _localsite_monkies:
62 delattr(class_, 'getSiteManager')
63 delattr(class_, 'setSiteManager')
64 classImplementsOnly(class_, implementedBy(class_)-IPossibleSite)
65 _localsite_monkies.remove(class_)
67 from zope.testing.cleanup import addCleanUp
68 addCleanUp(uninstallSiteHooks)
69 del addCleanUp