Back to index

plone3  3.1.7
zcml.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2007 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """PAS ZCML directives.
00014 
00015 $Id: zcml.py 72891 2007-02-27 18:24:41Z tseaver $
00016 """
00017 from zope.configuration.fields import PythonIdentifier
00018 from zope.interface import Interface
00019 
00020 from PluggableAuthService import MultiPlugins
00021 from PluggableAuthService import registerMultiPlugin as rMP
00022 
00023 
00024 class IRegisterMultiPlugin(Interface):
00025 
00026     """Register profiles with the global registry.
00027     """
00028 
00029     class_ = PythonIdentifier(
00030         title=u'Class',
00031         description=u'',
00032         required=False)
00033 
00034     meta_type = PythonIdentifier(
00035         title=u'Meta-Type',
00036         description=u"If not specified, 'class/meta_type' is used.",
00037         required=False)
00038 
00039 
00040 _mt_regs = []
00041 def registerMultiPlugin(_context, class_=None, meta_type=None):
00042     """ Add a new meta_type to the registry.
00043     """
00044     if not class_ and not meta_type:
00045         raise ConfigurationError(
00046             "At least one of 'class' or 'meta_type' is required.")
00047 
00048     if not meta_type:
00049         meta_type = class_.meta_type
00050 
00051     _mt_regs.append(meta_type)
00052 
00053     _context.action(
00054         discriminator = ('registerMultiPlugin', meta_type),
00055         callable = rMP,
00056         args = (meta_type,),
00057         )
00058 
00059 
00060 def cleanUp():
00061     global _mt_regs
00062     for meta_type in _mt_regs:
00063         MultiPlugins.remove(meta_type)
00064     _mt_regs = []
00065 
00066 from zope.testing.cleanup import addCleanUp
00067 addCleanUp(cleanUp)
00068 del addCleanUp