Пример #1
0
    def registerUtility(self,
                        component=None,
                        provided=None,
                        name=u'',
                        info=u'',
                        event=True,
                        factory=None):
        if factory:
            if component:
                raise TypeError("Can't specify factory and component.")
            component = factory()

        if provided is None:
            provided = _getUtilityProvided(component)

        if name == u'':
            name = _getName(component)

        reg = self._utility_registrations.get((provided, name))
        if reg is not None:
            if reg[:2] == (component, info):
                # already registered
                return
            self.unregisterUtility(reg[0], provided, name)

        self._utility_registrations_cache.registerUtility(
            provided, name, component, info, factory)

        if event:
            notify(
                Registered(
                    UtilityRegistration(self, provided, name, component, info,
                                        factory)))
Пример #2
0
    def registerUtility(self, component=None, provided=None, name=_u(''), 
                        info=_u(''), event=True, factory=None):
        if factory:
            if component:
                raise TypeError("Can't specify factory and component.")
            component = factory()

        if provided is None:
            provided = _getUtilityProvided(component)

        reg = self._utility_registrations.get((provided, name))
        if reg is not None:
            if reg[:2] == (component, info):
                # already registered
                return
            self.unregisterUtility(reg[0], provided, name)

        subscribed = False
        for ((p, _), data) in iter(self._utility_registrations.items()):
            if p == provided and data[0] == component:
                subscribed = True
                break

        self._utility_registrations[(provided, name)] = component, info, factory
        self.utilities.register((), provided, name, component)

        if not subscribed:
            self.utilities.subscribe((), provided, component)

        if event:
            notify(Registered(
                UtilityRegistration(self, provided, name, component, info,
                                    factory)
                ))
Пример #3
0
    def registerAdapter(self, factory, required=None, provided=None, 
                        name=_u(''), info=_u(''), event=True):
        if provided is None:
            provided = _getAdapterProvided(factory)
        required = _getAdapterRequired(factory, required)
        self._adapter_registrations[(required, provided, name)
                                    ] = factory, info
        self.adapters.register(required, provided, name, factory)

        if event:
            notify(Registered(
                AdapterRegistration(self, required, provided, name,
                                    factory, info)
                ))
Пример #4
0
    def registerHandler(self,
                        factory,
                        required=None,
                        name=_u(''),
                        info=_u(''),
                        event=True):
        if name:
            raise TypeError("Named handlers are not yet supported")
        required = _getAdapterRequired(factory, required)
        self._handler_registrations.append((required, name, factory, info))
        self.adapters.subscribe(required, None, factory)

        if event:
            notify(
                Registered(
                    HandlerRegistration(self, required, name, factory, info)))
Пример #5
0
    def registerSubscriptionAdapter(self,
                                    factory, required=None, provided=None,
                                    name=_u(''), info=_u(''),
                                    event=True):
        if name:
            raise TypeError("Named subscribers are not yet supported")
        if provided is None:
            provided = _getAdapterProvided(factory)
        required = _getAdapterRequired(factory, required)
        self._subscription_registrations.append(
            (required, provided, name, factory, info)
            )
        self.adapters.subscribe(required, provided, factory)

        if event:
            notify(Registered(
                SubscriptionRegistration(self, required, provided, name,
                                         factory, info)
                ))