Ejemplo n.º 1
0
def resource(
    _context, factory, type, name, permission=None, allowed_interface=None, allowed_attributes=None, provides=Interface
):

    if (allowed_attributes or allowed_interface) and (not permission):
        raise ComponentConfigurationError("Must use name attribute with allowed_interface or " "allowed_attributes")

    if permission is not None:

        checker = _checker(_context, permission, allowed_interface, allowed_attributes)

        def proxyResource(request, factory=factory, checker=checker):
            return proxify(factory(request), checker)

        proxyResource.factory = factory

        factory = proxyResource

    _context.action(
        discriminator=("resource", name, type, provides),
        callable=handler,
        args=("registerAdapter", factory, (type,), provides, name, _context.info),
    )
    _context.action(discriminator=None, callable=provideInterface, args=("", type))
    _context.action(discriminator=None, callable=provideInterface, args=("", provides))
Ejemplo n.º 2
0
def resource(_context, factory, type, name, layer=None,
             permission=None,
             allowed_interface=None, allowed_attributes=None,
             provides=zope.interface.Interface):

    if ((allowed_attributes or allowed_interface)
        and (not permission)):
        raise ConfigurationError(
            "Must use name attribute with allowed_interface or "
            "allowed_attributes"
            )

    if permission is not None:
        check_security_support()

        checker = _checker(_context, permission,
                           allowed_interface, allowed_attributes)

        def proxyResource(request, factory=factory, checker=checker):
            return proxify(factory(request), checker)

        factory = proxyResource

    if layer is not None:
        warnings.warn_explicit(
            "The 'layer' argument of the 'resource' directive has been "
            "deprecated.  Use the 'type' argument instead.",
            DeprecationWarning, _context.info.file, _context.info.line)
        type = layer

    _context.action(
        discriminator = ('resource', name, type, provides),
        callable = handler,
        args = ('registerAdapter',
                factory, (type,), provides, name, _context.info),
        )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = (type.__module__ + '.' + type.__name__, type)
               )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = (provides.__module__ + '.' + provides.__name__, type)
               )
Ejemplo n.º 3
0
def resource(_context, factory, type, name, layer=None,
             permission=None,
             allowed_interface=None, allowed_attributes=None,
             provides=zope.interface.Interface):

    if ((allowed_attributes or allowed_interface)
        and (not permission)):
        raise ConfigurationError(
            "Must use name attribute with allowed_interface or "
            "allowed_attributes"
            )

    if permission is not None:
        check_security_support()

        checker = _checker(_context, permission,
                           allowed_interface, allowed_attributes)

        def proxyResource(request, factory=factory, checker=checker):
            return proxify(factory(request), checker)

        factory = proxyResource

    if layer is not None:
        warnings.warn_explicit(
            "The 'layer' argument of the 'resource' directive has been "
            "deprecated.  Use the 'type' argument instead.",
            DeprecationWarning, _context.info.file, _context.info.line)
        type = layer

    _context.action(
        discriminator = ('resource', name, type, provides),
        callable = handler,
        args = ('registerAdapter',
                factory, (type,), provides, name, _context.info),
        )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = (type.__module__ + '.' + type.__name__, type)
               )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = (provides.__module__ + '.' + provides.__name__, type)
               )
Ejemplo n.º 4
0
def resource(_context,
             factory,
             type,
             name,
             permission=None,
             allowed_interface=None,
             allowed_attributes=None,
             provides=Interface):

    if ((allowed_attributes or allowed_interface) and (not permission)):
        raise ComponentConfigurationError(
            "Must use name attribute with allowed_interface or "
            "allowed_attributes")

    if permission is not None:

        checker = _checker(_context, permission, allowed_interface,
                           allowed_attributes)

        def proxyResource(request, factory=factory, checker=checker):
            return proxify(factory(request), checker)

        proxyResource.factory = factory

        factory = proxyResource

    _context.action(discriminator=('resource', name, type, provides),
                    callable=handler,
                    args=('registerAdapter', factory, (type, ), provides, name,
                          _context.info))
    _context.action(discriminator=None,
                    callable=provideInterface,
                    args=('', type))
    _context.action(discriminator=None,
                    callable=provideInterface,
                    args=('', provides))
Ejemplo n.º 5
0
def view(
    _context,
    factory,
    type,
    name,
    for_,
    permission=None,
    allowed_interface=None,
    allowed_attributes=None,
    provides=Interface,
):

    if ((allowed_attributes or allowed_interface) and (not permission)):
        raise ComponentConfigurationError(
            "'permission' required with 'allowed_interface' or "
            "'allowed_attributes'")

    if permission is not None:

        checker = _checker(_context, permission, allowed_interface,
                           allowed_attributes)

        class ProxyView(object):
            """Class to create simple proxy views."""
            def __init__(self, factory, checker):
                self.factory = factory
                self.checker = checker

            def __call__(self, *objects):
                return proxify(self.factory(*objects), self.checker)

        factory[-1] = ProxyView(factory[-1], checker)

    if not for_:
        raise ComponentConfigurationError("No for interfaces specified")
    for_ = tuple(for_)

    # Generate a single factory from multiple factories:
    factories = factory
    if len(factories) == 1:
        factory = factories[0]
    elif len(factories) < 1:
        raise ComponentConfigurationError("No view factory specified")
    elif len(factories) > 1 and len(for_) > 1:
        raise ComponentConfigurationError(
            "Can't use multiple factories and multiple for")
    else:

        def factory(ob, request):
            for f in factories[:-1]:
                ob = f(ob)
            return factories[-1](ob, request)

        factory.factory = factories[0]

    for_ = for_ + (type, )

    _context.action(
        discriminator=('view', for_, name, provides),
        callable=handler,
        args=('registerAdapter', factory, for_, provides, name, _context.info),
    )

    _context.action(discriminator=None,
                    callable=provideInterface,
                    args=('', provides))

    if for_ is not None:
        for iface in for_:
            if iface is not None:
                _context.action(discriminator=None,
                                callable=provideInterface,
                                args=('', iface))
Ejemplo n.º 6
0
 def _callFUT(self, *args, **kw):
     from zope.component.security import _checker
     return _checker(*args, **kw)
Ejemplo n.º 7
0
 def _callFUT(self, *args, **kw):
     from zope.component.security import _checker
     return _checker(*args, **kw)
Ejemplo n.º 8
0
def view(
    _context,
    factory,
    type,
    name,
    for_,
    permission=None,
    allowed_interface=None,
    allowed_attributes=None,
    provides=Interface,
):

    if (allowed_attributes or allowed_interface) and (not permission):
        raise ComponentConfigurationError("'permission' required with 'allowed_interface' or " "'allowed_attributes'")

    if permission is not None:

        checker = _checker(_context, permission, allowed_interface, allowed_attributes)

        class ProxyView(object):
            """Class to create simple proxy views."""

            def __init__(self, factory, checker):
                self.factory = factory
                self.checker = checker

            def __call__(self, *objects):
                return proxify(self.factory(*objects), self.checker)

        factory[-1] = ProxyView(factory[-1], checker)

    if not for_:
        raise ComponentConfigurationError("No for interfaces specified")
    for_ = tuple(for_)

    # Generate a single factory from multiple factories:
    factories = factory
    if len(factories) == 1:
        factory = factories[0]
    elif len(factories) < 1:
        raise ComponentConfigurationError("No view factory specified")
    elif len(factories) > 1 and len(for_) > 1:
        raise ComponentConfigurationError("Can't use multiple factories and multiple for")
    else:

        def factory(ob, request):
            for f in factories[:-1]:
                ob = f(ob)
            return factories[-1](ob, request)

        factory.factory = factories[0]

    for_ = for_ + (type,)

    _context.action(
        discriminator=("view", for_, name, provides),
        callable=handler,
        args=("registerAdapter", factory, for_, provides, name, _context.info),
    )

    _context.action(discriminator=None, callable=provideInterface, args=("", provides))

    if for_ is not None:
        for iface in for_:
            if iface is not None:
                _context.action(discriminator=None, callable=provideInterface, args=("", iface))
Ejemplo n.º 9
0
def view(_context, factory, type, name, for_, layer=None,
         permission=None, allowed_interface=None, allowed_attributes=None,
         provides=zope.interface.Interface):

    if ((allowed_attributes or allowed_interface)
        and (not permission)):
        raise ConfigurationError(
            "Must use name attribute with allowed_interface or "
            "allowed_attributes"
            )

    if not factory:
        raise ConfigurationError("No view factory specified.")

    if permission is not None:
        check_security_support()

        checker = _checker(_context, permission,
                           allowed_interface, allowed_attributes)

        class ProxyView(object):
            """Class to create simple proxy views."""

            def __init__(self, factory, checker):
                self.factory = factory
                self.checker = checker

            def __call__(self, *objects):
                return proxify(self.factory(*objects), self.checker)

        factory[-1] = ProxyView(factory[-1], checker)


    if not for_:
        raise ValueError("No for interfaces specified");
    for_ = tuple(for_)

    # Generate a single factory from multiple factories:
    factories = factory
    if len(factories) == 1:
        factory = factories[0]
    elif len(factories) < 1:
        raise ValueError("No factory specified")
    elif len(factories) > 1 and len(for_) > 1:
        raise ValueError("Can't use multiple factories and multiple for")
    else:
        def factory(ob, request):
            for f in factories[:-1]:
                ob = f(ob)
            return factories[-1](ob, request)

    # BBB 2006/02/18, to be removed after 12 months
    if layer is not None:
        for_ = for_ + (layer,)
        warnings.warn_explicit(
            "The 'layer' argument of the 'view' directive has been "
            "deprecated.  Use the 'type' argument instead. If you have "
            "an existing 'type' argument IBrowserRequest, replace it with the "
            "'layer' argument (the layer subclasses IBrowserRequest). "
            "which subclasses BrowserRequest.",
            DeprecationWarning, _context.info.file, _context.info.line)
    else:
        for_ = for_ + (type,)

    _context.action(
        discriminator = ('view', for_, name, provides),
        callable = handler,
        args = ('registerAdapter',
                factory, for_, provides, name, _context.info),
        )
    if type is not None:
        _context.action(
            discriminator = None,
            callable = provideInterface,
            args = ('', type)
            )

    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = ('', provides)
        )

    if for_ is not None:
        for iface in for_:
            if iface is not None:
                _context.action(
                    discriminator = None,
                    callable = provideInterface,
                    args = ('', iface)
                    )
Ejemplo n.º 10
0
def view(_context, factory, type, name, for_, layer=None,
         permission=None, allowed_interface=None, allowed_attributes=None,
         provides=zope.interface.Interface):

    if ((allowed_attributes or allowed_interface)
        and (not permission)):
        raise ConfigurationError(
            "Must use name attribute with allowed_interface or "
            "allowed_attributes"
            )

    if not factory:
        raise ConfigurationError("No view factory specified.")

    if permission is not None:
        check_security_support()

        checker = _checker(_context, permission,
                           allowed_interface, allowed_attributes)

        class ProxyView(object):
            """Class to create simple proxy views."""

            def __init__(self, factory, checker):
                self.factory = factory
                self.checker = checker

            def __call__(self, *objects):
                return proxify(self.factory(*objects), self.checker)

        factory[-1] = ProxyView(factory[-1], checker)


    if not for_:
        raise ValueError("No for interfaces specified");
    for_ = tuple(for_)

    # Generate a single factory from multiple factories:
    factories = factory
    if len(factories) == 1:
        factory = factories[0]
    elif len(factories) < 1:
        raise ValueError("No factory specified")
    elif len(factories) > 1 and len(for_) > 1:
        raise ValueError("Can't use multiple factories and multiple for")
    else:
        def factory(ob, request):
            for f in factories[:-1]:
                ob = f(ob)
            return factories[-1](ob, request)

    # BBB 2006/02/18, to be removed after 12 months
    if layer is not None:
        for_ = for_ + (layer,)
        warnings.warn_explicit(
            "The 'layer' argument of the 'view' directive has been "
            "deprecated.  Use the 'type' argument instead. If you have "
            "an existing 'type' argument IBrowserRequest, replace it with the "
            "'layer' argument (the layer subclasses IBrowserRequest). "
            "which subclasses BrowserRequest.",
            DeprecationWarning, _context.info.file, _context.info.line)
    else:
        for_ = for_ + (type,)

    _context.action(
        discriminator = ('view', for_, name, provides),
        callable = handler,
        args = ('registerAdapter',
                factory, for_, provides, name, _context.info),
        )
    if type is not None:
        _context.action(
            discriminator = None,
            callable = provideInterface,
            args = ('', type)
            )

    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = ('', provides)
        )

    if for_ is not None:
        for iface in for_:
            if iface is not None:
                _context.action(
                    discriminator = None,
                    callable = provideInterface,
                    args = ('', iface)
                    )