Example #1
0
def utility(_context, provides=None, component=None, factory=None,
            permission=None, name=''):
    if factory and component:
        raise TypeError("Can't specify factory and component.")

    if provides is None:
        if factory:
            provides = list(zope.interface.implementedBy(factory))
        else:
            provides = list(zope.interface.providedBy(component))
        if len(provides) == 1:
            provides = provides[0]
        else:
            raise TypeError("Missing 'provides' attribute")

    if permission is not None:
        check_security_support()
        component = proxify(component, provides=provides, permission=permission)

    _context.action(
        discriminator = ('utility', provides, name),
        callable = handler,
        args = ('registerUtility', component, provides, name),
        kw = dict(factory=factory),
        )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = (provides.__module__ + '.' + provides.getName(), provides)
        )
Example #2
0
def utility(_context, provides=None, component=None, factory=None,
            permission=None, name=''):
    if factory and component:
        raise TypeError("Can't specify factory and component.")

    if provides is None:
        if factory:
            provides = list(zope.interface.implementedBy(factory))
        else:
            provides = list(zope.interface.providedBy(component))
        if len(provides) == 1:
            provides = provides[0]
        else:
            raise TypeError("Missing 'provides' attribute")

    if permission is not None:
        check_security_support()
        component = proxify(component, provides=provides, permission=permission)

    _context.action(
        discriminator = ('utility', provides, name),
        callable = handler,
        args = ('registerUtility', component, provides, name),
        kw = dict(factory=factory),
        )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = (provides.__module__ + '.' + provides.getName(), provides)
        )
Example #3
0
def utility(_context, provides=None, component=None, factory=None,
            permission=None, name=''):
    if factory and component:
        raise TypeError("Can't specify factory and component.")

    if provides is None:
        if factory:
            provides = list(implementedBy(factory))
        else:
            provides = list(providedBy(component))
        if len(provides) == 1:
            provides = provides[0]
        else:
            raise TypeError("Missing 'provides' attribute")

    if name == '':
        if factory:
            name = getName(factory)
        else:
            name = getName(component)

    if permission is not None:
        component = proxify(component, provides=provides, permission=permission)

    _context.action(
        discriminator = ('utility', provides, name),
        callable = handler,
        args = ('registerUtility', component, provides, name, _context.info),
        kw = dict(factory=factory),
        )
    _context.action(
        discriminator = None,
        callable = provideInterface,
        args = ('', provides),
        )
Example #4
0
 def proxyResource(request, factory=factory, checker=checker):
     return proxify(factory(request), checker)
Example #5
0
 def __call__(self, *objects):
     return proxify(self.factory(*objects), self.checker)
Example #6
0
 def _callFUT(self, *args, **kw):
     from zope.component.security import proxify
     return proxify(*args, **kw)
Example #7
0
 def _callFUT(self, *args, **kw):
     from zope.component.security import proxify
     return proxify(*args, **kw)
Example #8
0
 def proxyResource(request, factory=factory, checker=checker):
     return proxify(factory(request), checker)
Example #9
0
 def __call__(self, *objects):
     return proxify(self.factory(*objects), self.checker)
Example #10
0
def _assertPermission(permission, interfaces, component):
    if not SECURITY_SUPPORT:
        raise ConfigurationError(
            "security proxied components are not "
            "supported because zope.security is not available")
    return proxify(component, provides=interfaces, permission=permission)
Example #11
0
def _assertPermission(permission, interfaces, component):
    if not SECURITY_SUPPORT:
        raise ConfigurationError("security proxied components are not "
            "supported because zope.security is not available")
    return proxify(component, provides=interfaces, permission=permission)
Example #12
0
 def _assertPermission(permission, interfaces, component):
     return proxify(component, provides=interfaces, permission=permission)