##############################################################################
#
# 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.
#
##############################################################################
"""Generic Components ZCML Handlers

$Id: metaconfigure.py 99145 2009-04-13 10:15:12Z optilude $
"""
import warnings
from zope.security import metaconfigure
from App.class_init import InitializeClass
from Products.Five.security import protectName

class ClassDirective(metaconfigure.ClassDirective):

    def __protectName(self, name, permission_id):
        self.__context.action(
            discriminator = ('five:protectName', self.__class, name),
            callable = protectName,
            args = (self.__class, name, permission_id)
            )

    def __protectSetAttributes(self, names, permission_id):
        warnings.warn("The set_attribute option of the <require /> directive is not supported in Zope 2. " + \
                      "Ignored for %s" % str(self.__class), stacklevel=3)

    def __protectSetSchema(self, schema, permission):
        warnings.warn("The set_schema option of the <require /> directive is not supported in Zope 2. " + \
                      "Ignored for %s" % str(self.__class), stacklevel=3)

    def __mimic(self, _context, class_):
        warnings.warn("The like_class option of the <require /> directive is not supported in Zope 2. " + \
                      "Ignored for %s" % str(self.__class), stacklevel=3)

    def __call__(self):
        return self.__context.action(
            discriminator = None,
            callable = InitializeClass,
            args = (self.__class,)
            )
