Commit 95edbb88 authored by Hanno Schlichting's avatar Hanno Schlichting

Moved general OFS related ZCML directives from Products.Five into the OFS package itself.

parent fb972e8d
......@@ -11,6 +11,9 @@ Trunk (unreleased)
Restructuring
+++++++++++++
- Moved general OFS related ZCML directives from Products.Five into the OFS
package itself.
- Ported the lazy expression into zope.tales and require a new version of it.
- Updated Five documentation to clarify its role in regard to Zope packages.
......
<configure xmlns="http://namespaces.zope.org/zope">
<include file="deprecated.zcml"/>
<include file="event.zcml"/>
</configure>
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five">
<!-- deprecated in core Zope, should be fixed there -->
<five:deprecatedManageAddDelete
class="AccessControl.User.BasicUserFolder"/>
<five:deprecatedManageAddDelete
class="App.Permission.Permission"/>
<five:deprecatedManageAddDelete
class="HelpSys.HelpTopic.HelpTopicBase"/>
<five:deprecatedManageAddDelete
class="OFS.Cache.CacheManager"/>
<five:deprecatedManageAddDelete
class="Products.PythonScripts.PythonScript.PythonScript"/>
<five:deprecatedManageAddDelete
class="Products.Sessions.BrowserIdManager.BrowserIdManager"/>
<five:deprecatedManageAddDelete
class="Products.Sessions.SessionDataManager.SessionDataManager"/>
<five:deprecatedManageAddDelete
class="Products.SiteAccess.VirtualHostMonster.VirtualHostMonster"/>
<five:deprecatedManageAddDelete
class="Products.SiteAccess.SiteRoot.Traverser"/>
<five:deprecatedManageAddDelete
class="Products.SiteErrorLog.SiteErrorLog.SiteErrorLog"/>
<five:deprecatedManageAddDelete
class="Products.ZCatalog.CatalogAwareness.CatalogAware"/>
<five:deprecatedManageAddDelete
class="Products.ZCatalog.CatalogPathAwareness.CatalogAware"/>
</configure>
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:meta="http://namespaces.zope.org/meta">
<meta:directives namespace="http://namespaces.zope.org/five">
<meta:directive
name="loadProducts"
schema="zope.configuration.xmlconfig.IInclude"
handler=".metaconfigure.loadProducts"
/>
<meta:directive
name="loadProductsOverrides"
schema="zope.configuration.xmlconfig.IInclude"
handler=".metaconfigure.loadProductsOverrides"
/>
<meta:directive
name="deprecatedManageAddDelete"
schema=".metadirectives.IDeprecatedManageAddDeleteDirective"
handler=".metaconfigure.deprecatedManageAddDelete"
/>
<meta:directive
name="registerClass"
schema=".metadirectives.IRegisterClassDirective"
handler=".metaconfigure.registerClass"
/>
<meta:directive
name="registerPackage"
schema=".metadirectives.IRegisterPackageDirective"
handler=".metaconfigure.registerPackage"
/>
</meta:directives>
</configure>
import logging
import os
from zope.component import getUtility
from zope.configuration import xmlconfig
from zope.interface import implementedBy
from zope.security.interfaces import IPermission
import App.config
from OFS.subscribers import deprecatedManageAddDeleteClasses
import Products
debug_mode = App.config.getConfiguration().debug_mode
logger = logging.getLogger('OFS')
_register_monkies = []
_meta_type_regs = []
def findProducts():
from types import ModuleType
products = []
for name in dir(Products):
product = getattr(Products, name)
if isinstance(product, ModuleType) and hasattr(product, '__file__'):
products.append(product)
return products
def handleBrokenProduct(product):
if debug_mode:
# Just reraise the error and let Zope handle it.
raise
# Not debug mode. Zope should continue to load. Print a log message:
logger.exception('Could not import Product %s' % product.__name__)
def loadProducts(_context, file=None, files=None, package=None):
if file is None:
# set the default
file = 'configure.zcml'
if files is not None or package is not None:
raise ValueError("Neither the files or package argument is supported.")
# now load the files if they exist
for product in findProducts():
zcml = os.path.join(os.path.dirname(product.__file__), file)
if os.path.isfile(zcml):
try:
xmlconfig.include(_context, zcml, package=product)
except: # Yes, really, *any* kind of error.
handleBrokenProduct(product)
def loadProductsOverrides(_context, file=None, files=None, package=None):
if file is None:
# set the default
file = 'overrides.zcml'
if files is not None or package is not None:
raise ValueError("Neither the files or package argument is supported.")
# now load the files if they exist
for product in findProducts():
zcml = os.path.join(os.path.dirname(product.__file__), file)
if os.path.isfile(zcml):
try:
xmlconfig.includeOverrides(_context, zcml, package=product)
except: # Yes, really, *any* kind of error.
handleBrokenProduct(product)
def _registerPackage(module_, init_func=None):
"""Registers the given python package as a Zope 2 style product
"""
if not hasattr(module_, '__path__'):
raise ValueError("Must be a package and the " \
"package must be filesystem based")
registered_packages = getattr(Products, '_registered_packages', None)
if registered_packages is None:
registered_packages = Products._registered_packages = []
registered_packages.append(module_)
# Delay the actual setup until the usual product loading time in
# OFS.Application. Otherwise, we may get database write errors in
# ZEO, when there's no connection with which to write an entry to
# Control_Panel. We would also get multiple calls to initialize().
to_initialize = getattr(Products, '_packages_to_initialize', None)
if to_initialize is None:
to_initialize = Products._packages_to_initialize = []
to_initialize.append((module_, init_func,))
def registerPackage(_context, package, initialize=None):
"""ZCML directive function for registering a python package product
"""
_context.action(
discriminator = ('registerPackage', package),
callable = _registerPackage,
args = (package,initialize)
)
def _registerClass(class_, meta_type, permission, addview, icon, global_):
setattr(class_, 'meta_type', meta_type)
permission_obj = getUtility(IPermission, permission)
if icon:
setattr(class_, 'icon', '++resource++%s' % icon)
interfaces = tuple(implementedBy(class_))
info = {'name': meta_type,
'action': addview and ('+/%s' % addview) or '',
'product': 'Five',
'permission': str(permission_obj.title),
'visibility': global_ and 'Global' or None,
'interfaces': interfaces,
'instance': class_,
'container_filter': None}
Products.meta_types += (info,)
_register_monkies.append(class_)
_meta_type_regs.append(meta_type)
def registerClass(_context, class_, meta_type, permission, addview=None,
icon=None, global_=True):
_context.action(
discriminator = ('registerClass', meta_type),
callable = _registerClass,
args = (class_, meta_type, permission, addview, icon, global_)
)
def unregisterClass(class_):
delattr(class_, 'meta_type')
try:
delattr(class_, 'icon')
except AttributeError:
pass
def setDeprecatedManageAddDelete(class_):
"""Instances of the class will still see their old methods called."""
deprecatedManageAddDeleteClasses.append(class_)
def deprecatedManageAddDelete(_context, class_):
_context.action(
discriminator=('five:deprecatedManageAddDelete', class_),
callable=setDeprecatedManageAddDelete,
args=(class_,),
)
def cleanUp():
deprecatedManageAddDeleteClasses[:] = []
global _register_monkies
for class_ in _register_monkies:
unregisterClass(class_)
_register_monkies = []
global _meta_type_regs
Products.meta_types = tuple([ info for info in Products.meta_types
if info['name'] not in _meta_type_regs ])
_meta_type_regs = []
from zope.testing.cleanup import addCleanUp
addCleanUp(cleanUp)
del addCleanUp
from zope.interface import Interface
from zope.security.zcml import Permission
from zope.configuration.fields import GlobalObject
from zope.configuration.fields import Bool
from zope.schema import ASCII
class IDeprecatedManageAddDeleteDirective(Interface):
"""Call manage_afterAdd & co for these contained content classes.
"""
class_ = GlobalObject(
title=u"Class",
required=True,
)
class IRegisterClassDirective(Interface):
"""registerClass directive schema.
Register content with Zope 2.
"""
class_ = GlobalObject(
title=u'Instance Class',
description=u'Dotted name of the class that is registered.',
required=True
)
meta_type = ASCII(
title=u'Meta Type',
description=u'A human readable unique identifier for the class.',
required=True
)
permission = Permission(
title=u'Add Permission',
description=u'The permission for adding objects of this class.',
required=True
)
addview = ASCII(
title=u'Add View ID',
description=u'The ID of the add view used in the ZMI. Consider this '
u'required unless you know exactly what you do.',
default=None,
required=False
)
icon = ASCII(
title=u'Icon ID',
description=u'The ID of the icon used in the ZMI.',
default=None,
required=False
)
global_ = Bool(
title=u'Global scope?',
description=u'If "global" is False the class is only available in '
u'containers that explicitly allow one of its interfaces.',
default=True,
required=False
)
class IRegisterPackageDirective(Interface):
"""Registers the given Python package which at a minimum fools zope2 into
thinking of it as a zope2 product.
"""
package = GlobalObject(
title=u'Target package',
required=True
)
initialize = GlobalObject(
title=u'Initialization function to invoke',
description=u'The dotted name of a function that will get invoked '
u'with a ProductContext instance',
required=False
)
......@@ -33,9 +33,9 @@ work inside a database::
We'll use a few simple classes (defined in python code for picklability)
for our tests.
>>> from Products.Five.tests.test_event import MyApp, MyContent
>>> from Products.Five.tests.test_event import MyFolder, MyBTreeFolder
>>> from Products.Five.tests.test_event import MyOrderedFolder
>>> from OFS.tests.test_event import MyApp, MyContent
>>> from OFS.tests.test_event import MyFolder, MyBTreeFolder
>>> from OFS.tests.test_event import MyOrderedFolder
>>> app = MyApp('')
>>> root['app'] = app
......@@ -92,7 +92,7 @@ Finally we need to load the subscribers configuration::
We need at least one fake deprecated method to tell the compatibility
framework that component architecture is initialized::
>>> from Products.Five.eventconfigure import setDeprecatedManageAddDelete
>>> from OFS.metaconfigure import setDeprecatedManageAddDelete
>>> class C(object): pass
>>> setDeprecatedManageAddDelete(C)
......@@ -308,7 +308,7 @@ New class
If we use classes that don't have any manage_afterAdd & co method,
everything happens correctly::
>>> from Products.Five.tests.test_event import MyNewFolder, MyNewContent
>>> from OFS.tests.test_event import MyNewFolder, MyNewContent
>>> app = MyApp('')
>>> root['app'] = app
>>> folder = MyNewFolder('folder')
......
......@@ -57,7 +57,7 @@ class TestFolder(Folder):
Folder.manage_beforeDelete(self, item, container)
from Products.Five.eventconfigure import setDeprecatedManageAddDelete
from OFS.metaconfigure import setDeprecatedManageAddDelete
class HookLayer:
......
......@@ -11,11 +11,11 @@ from Acquisition import aq_base
from Acquisition import Implicit
from App.config import getConfiguration
from logging import getLogger
from OFS.metaconfigure import setDeprecatedManageAddDelete
from OFS.ObjectManager import ObjectManager
from OFS.SimpleItem import SimpleItem
import Products.Five
from Products.Five import zcml
from Products.Five.eventconfigure import setDeprecatedManageAddDelete
from zExceptions import BadRequest
logger = getLogger('OFS.subscribers')
......@@ -75,8 +75,7 @@ class ObjectManagerTests(PlacelessSetup, unittest.TestCase):
self.saved_cfg_debug_mode = getConfiguration().debug_mode
zcml.load_config('meta.zcml', Products.Five)
import OFS
zcml.load_config('event.zcml', OFS)
zcml.load_config('deprecated.zcml', Products.Five)
zcml.load_config('configure.zcml', OFS)
setDeprecatedManageAddDelete(ItemForDeletion)
def tearDown( self ):
......
......@@ -84,5 +84,5 @@ class MyNewFolder(DontComplain, Folder):
def test_suite():
from zope.testing.doctest import DocFileSuite
return DocFileSuite('event.txt', package="Products.Five.tests",
return DocFileSuite('event.txt', package="OFS.tests",
setUp=setUp, tearDown=testing.tearDown)
......@@ -3,7 +3,6 @@
<include file="meta.zcml" />
<include file="permissions.zcml" />
<include file="deprecated.zcml"/>
<include package="zope.traversing" />
<include package="OFS "/>
......
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five">
<configure xmlns="http://namespaces.zope.org/zope">
<!-- deprecated in core Zope, should be fixed there -->
<five:deprecatedManageAddDelete
class="AccessControl.User.BasicUserFolder"/>
<five:deprecatedManageAddDelete
class="App.Permission.Permission"/>
<five:deprecatedManageAddDelete
class="HelpSys.HelpTopic.HelpTopicBase"/>
<five:deprecatedManageAddDelete
class="OFS.Cache.CacheManager"/>
<five:deprecatedManageAddDelete
class="Products.PythonScripts.PythonScript.PythonScript"/>
<five:deprecatedManageAddDelete
class="Products.Sessions.BrowserIdManager.BrowserIdManager"/>
<five:deprecatedManageAddDelete
class="Products.Sessions.SessionDataManager.SessionDataManager"/>
<five:deprecatedManageAddDelete
class="Products.SiteAccess.VirtualHostMonster.VirtualHostMonster"/>
<five:deprecatedManageAddDelete
class="Products.SiteAccess.SiteRoot.Traverser"/>
<five:deprecatedManageAddDelete
class="Products.SiteErrorLog.SiteErrorLog.SiteErrorLog"/>
<five:deprecatedManageAddDelete
class="Products.ZCatalog.CatalogAwareness.CatalogAware"/>
<five:deprecatedManageAddDelete
class="Products.ZCatalog.CatalogPathAwareness.CatalogAware"/>
<include package="OFS" file="deprecated.zcml"/>
</configure>
......@@ -12,28 +12,13 @@
#
##############################################################################
"""
Use 'structured monkey patching' to enable zope.container event sending for
Zope 2 objects.
$Id$
"""
from OFS.subscribers import deprecatedManageAddDeleteClasses
def setDeprecatedManageAddDelete(class_):
"""Instances of the class will still see their old methods called."""
deprecatedManageAddDeleteClasses.append(class_)
def cleanUp():
deprecatedManageAddDeleteClasses[:] = []
def deprecatedManageAddDelete(_context, class_):
_context.action(
discriminator=('five:deprecatedManageAddDelete', class_),
callable=setDeprecatedManageAddDelete,
args=(class_,),
)
from zope.deferredimport import deprecated
from zope.testing.cleanup import addCleanUp
addCleanUp(cleanUp)
del addCleanUp
deprecated("Please import from OFS.metaconfigure",
deprecatedManageAddDelete = 'OFS.metaconfigure:deprecatedManageAddDelete',
setDeprecatedManageAddDelete = \
'OFS.metaconfigure:setDeprecatedManageAddDelete',
)
......@@ -19,80 +19,15 @@ $Id$
"""
import os
import glob
import logging
import warnings
import App.config
import Products
import Zope2
from zope.interface import classImplements, implementedBy
from zope.component import getUtility
from zope.interface import classImplements
from zope.component.interface import provideInterface
from zope.configuration import xmlconfig
from zope.configuration.exceptions import ConfigurationError
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.security.interfaces import IPermission
from Products.Five import isFiveMethod
from Products.Five.browser.metaconfigure import page
debug_mode = App.config.getConfiguration().debug_mode
LOG = logging.getLogger('Five')
def findProducts():
import Products
from types import ModuleType
products = []
for name in dir(Products):
product = getattr(Products, name)
if isinstance(product, ModuleType) and hasattr(product, '__file__'):
products.append(product)
return products
def handleBrokenProduct(product):
if debug_mode:
# Just reraise the error and let Zope handle it.
raise
# Not debug mode. Zope should continue to load. Print a log message:
# XXX It would be really cool if we could make this product appear broken
# in the control panel. However, all attempts to do so has failed from my
# side. //regebro
LOG.error('Could not import Product %s' % product.__name__, exc_info=True)
def loadProducts(_context, file=None, files=None, package=None):
if file is None:
# set the default
file = 'configure.zcml'
if files is not None or package is not None:
raise ValueError("Neither the files or package argument is supported.")
# now load the files if they exist
for product in findProducts():
zcml = os.path.join(os.path.dirname(product.__file__), file)
if os.path.isfile(zcml):
try:
xmlconfig.include(_context, zcml, package=product)
except: # Yes, really, *any* kind of error.
handleBrokenProduct(product)
def loadProductsOverrides(_context, file=None, files=None, package=None):
if file is None:
# set the default
file = 'overrides.zcml'
if files is not None or package is not None:
raise ValueError("Neither the files or package argument is supported.")
# now load the files if they exist
for product in findProducts():
zcml = os.path.join(os.path.dirname(product.__file__), file)
if os.path.isfile(zcml):
try:
xmlconfig.includeOverrides(_context, zcml, package=product)
except: # Yes, really, *any* kind of error.
handleBrokenProduct(product)
def implements(_context, class_, interface):
warnings.warn('Using <five:implements /> is deprecated. Please use the '
......@@ -133,114 +68,18 @@ def pagesFromDirectory(_context, directory, module, for_=None,
layer=layer, for_=for_, template=fname)
_register_monkies = []
_meta_type_regs = []
def _registerClass(class_, meta_type, permission, addview, icon, global_):
setattr(class_, 'meta_type', meta_type)
permission_obj = getUtility(IPermission, permission)
if icon:
setattr(class_, 'icon', '++resource++%s' % icon)
interfaces = tuple(implementedBy(class_))
info = {'name': meta_type,
'action': addview and ('+/%s' % addview) or '',
'product': 'Five',
'permission': str(permission_obj.title),
'visibility': global_ and 'Global' or None,
'interfaces': interfaces,
'instance': class_,
'container_filter': None}
Products.meta_types += (info,)
_register_monkies.append(class_)
_meta_type_regs.append(meta_type)
def registerClass(_context, class_, meta_type, permission, addview=None,
icon=None, global_=True):
_context.action(
discriminator = ('registerClass', meta_type),
callable = _registerClass,
args = (class_, meta_type, permission, addview, icon, global_)
)
def _registerPackage(module_, init_func=None):
"""Registers the given python package as a Zope 2 style product
"""
if not hasattr(module_, '__path__'):
raise ValueError("Must be a package and the " \
"package must be filesystem based")
registered_packages = getattr(Products, '_registered_packages', None)
if registered_packages is None:
registered_packages = Products._registered_packages = []
registered_packages.append(module_)
# Delay the actual setup until the usual product loading time in
# OFS.Application. Otherwise, we may get database write errors in
# ZEO, when there's no connection with which to write an entry to
# Control_Panel. We would also get multiple calls to initialize().
to_initialize = getattr(Products, '_packages_to_initialize', None)
if to_initialize is None:
to_initialize = Products._packages_to_initialize = []
to_initialize.append((module_, init_func,))
def registerPackage(_context, package, initialize=None):
"""ZCML directive function for registering a python package product
"""
_context.action(
discriminator = ('registerPackage', package),
callable = _registerPackage,
args = (package,initialize)
)
# clean up code
def killMonkey(class_, name, fallback, attr=None):
"""Die monkey, die!"""
method = getattr(class_, name, None)
if isFiveMethod(method):
original = getattr(class_, fallback, None)
if original is not None:
delattr(class_, fallback)
if original is None or isFiveMethod(original):
try:
delattr(class_, name)
except AttributeError:
pass
else:
setattr(class_, name, original)
if attr is not None:
try:
delattr(class_, attr)
except (AttributeError, KeyError):
pass
def unregisterClass(class_):
delattr(class_, 'meta_type')
try:
delattr(class_, 'icon')
except AttributeError:
pass
def cleanUp():
global _register_monkies
for class_ in _register_monkies:
unregisterClass(class_)
_register_monkies = []
global _meta_type_regs
Products.meta_types = tuple([ info for info in Products.meta_types
if info['name'] not in _meta_type_regs ])
_meta_type_regs = []
from zope.testing.cleanup import addCleanUp
addCleanUp(cleanUp)
del addCleanUp
from zope.deferredimport import deprecated
deprecated("Please import from OFS.metaconfigure",
findProducts = 'OFS.metaconfigure:findProducts',
handleBrokenProduct = 'OFS.metaconfigure:handleBrokenProduct',
loadProducts = 'OFS.metaconfigure:loadProducts',
loadProductsOverrides = 'OFS.metaconfigure:loadProductsOverrides',
_register_monkies = 'OFS.metaconfigure:_register_monkies',
_meta_type_regs = 'OFS.metaconfigure:_meta_type_regs',
_registerClass = 'OFS.metaconfigure:_registerClass',
registerClass = 'OFS.metaconfigure:registerClass',
_registerPackage = 'OFS.metaconfigure:_registerPackage',
registerPackage = 'OFS.metaconfigure:registerPackage',
unregisterClass = 'OFS.metaconfigure:unregisterClass',
)
......@@ -17,10 +17,8 @@ $Id$
"""
from zope.interface import Interface
from zope.browserresource.metadirectives import IBasicResourceInformation
from zope.security.zcml import Permission
from zope.configuration.fields import GlobalObject, Tokens
from zope.configuration.fields import Bool
from zope.schema import ASCII, TextLine
from zope.schema import TextLine
# Deprecated, the class directive from zope.security allows the same
......@@ -38,8 +36,9 @@ class IImplementsDirective(Interface):
value_type=GlobalObject()
)
class ISizableDirective(Interface):
"""Make instances of class send events.
"""Attach sizable adapters to classes.
"""
class_ = GlobalObject(
......@@ -48,15 +47,6 @@ class ISizableDirective(Interface):
)
class IDeprecatedManageAddDeleteDirective(Interface):
"""Call manage_afterAdd & co for these contained content classes.
"""
class_ = GlobalObject(
title=u"Class",
required=True,
)
class IPagesFromDirectoryDirective(IBasicResourceInformation):
"""Register each file in a skin directory as a page resource
"""
......@@ -77,75 +67,16 @@ class IPagesFromDirectoryDirective(IBasicResourceInformation):
required=True
)
class IRegisterClassDirective(Interface):
"""registerClass directive schema.
Register Five content with Zope 2.
"""
class_ = GlobalObject(
title=u'Instance Class',
description=u'Dotted name of the class that is registered.',
required=True
)
meta_type = ASCII(
title=u'Meta Type',
description=u'A human readable unique identifier for the class.',
required=True
)
permission = Permission(
title=u'Add Permission',
description=u'The permission for adding objects of this class.',
required=True
)
addview = ASCII(
title=u'Add View ID',
description=u'The ID of the add view used in the ZMI. Consider this '
u'required unless you know exactly what you do.',
default=None,
required=False
)
icon = ASCII(
title=u'Icon ID',
description=u'The ID of the icon used in the ZMI.',
default=None,
required=False
)
global_ = Bool(
title=u'Global scope?',
description=u'If "global" is False the class is only available in '
u'containers that explicitly allow one of its interfaces.',
default=True,
required=False
)
class IRegisterPackageDirective(Interface):
"""Registers the given python package which at a minimum fools zope2 into
thinking of it as a zope2 product.
"""
package = GlobalObject(
title=u'Target package',
required=True
)
initialize = GlobalObject(
title=u'Initialization function to invoke',
description=u'The dotted name of a function that will get invoked '
u'with a ProductContext instance',
required=False
)
from zope.deferredimport import deprecated
deprecated("Please import from OFS.metadirectives",
IRegisterPackageDirective = 'OFS.metadirectives:IRegisterPackageDirective',
IRegisterClassDirective = 'OFS.metadirectives:IRegisterClassDirective',
IDeprecatedManageAddDeleteDirective = \
'OFS.metadirectives:IDeprecatedManageAddDeleteDirective',
)
deprecated("Please import from zope.configuration.xmlconfig",
IInclude = 'zope.configuration.xmlconfig:IInclude',
)
......@@ -3,6 +3,7 @@
xmlns:meta="http://namespaces.zope.org/meta">
<include package="AccessControl" file="meta.zcml" />
<include package="OFS" file="meta.zcml" />
<include package="zope.component" file="meta.zcml" />
<include package="zope.i18n" file="meta.zcml" />
......@@ -23,24 +24,6 @@
<!-- specific to Five -->
<meta:directive
name="loadProducts"
schema="zope.configuration.xmlconfig.IInclude"
handler=".fiveconfigure.loadProducts"
/>
<meta:directive
name="loadProductsOverrides"
schema="zope.configuration.xmlconfig.IInclude"
handler=".fiveconfigure.loadProductsOverrides"
/>
<meta:directive
name="deprecatedManageAddDelete"
schema=".fivedirectives.IDeprecatedManageAddDeleteDirective"
handler=".eventconfigure.deprecatedManageAddDelete"
/>
<meta:directive
name="sizable"
schema=".fivedirectives.ISizableDirective"
......@@ -53,18 +36,6 @@
handler=".fiveconfigure.pagesFromDirectory"
/>
<meta:directive
name="registerClass"
schema=".fivedirectives.IRegisterClassDirective"
handler=".fiveconfigure.registerClass"
/>
<meta:directive
name="registerPackage"
schema=".fivedirectives.IRegisterPackageDirective"
handler=".fiveconfigure.registerPackage"
/>
<!-- Deprecated, use the class directive instead. -->
<meta:directive
name="implements"
......
......@@ -50,8 +50,26 @@ def sizable(_context, class_):
)
# clean up code
from Products.Five.fiveconfigure import killMonkey
from zope.testing.cleanup import addCleanUp
def killMonkey(class_, name, fallback, attr=None):
"""Die monkey, die!"""
method = getattr(class_, name, None)
if isFiveMethod(method):
original = getattr(class_, fallback, None)
if original is not None:
delattr(class_, fallback)
if original is None or isFiveMethod(original):
try:
delattr(class_, name)
except AttributeError:
pass
else:
setattr(class_, name, original)
if attr is not None:
try:
delattr(class_, attr)
except (AttributeError, KeyError):
pass
def unsizable(class_):
"""Restore class's initial state with respect to being sizable"""
......@@ -61,5 +79,6 @@ def cleanUp():
for class_ in _monkied:
unsizable(class_)
from zope.testing.cleanup import addCleanUp
addCleanUp(cleanUp)
del addCleanUp
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment