• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python component.subscribers函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zope.component.subscribers函数的典型用法代码示例。如果您正苦于以下问题:Python subscribers函数的具体用法?Python subscribers怎么用?Python subscribers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了subscribers函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: validate

    def validate(self, REQUEST=None, errors=None, data=None, metadata=None):
        """Validates the form data from the request.
        """
        if errors is None:
            errors = {}

        self.pre_validate(REQUEST, errors)

        for pre_validator in subscribers((self,), IObjectPreValidation):
            pre_errors = pre_validator(REQUEST)
            if pre_errors is not None:
                for field_name, error_message in pre_errors.items():
                    if field_name in errors:
                        errors[field_name] += " %s" % error_message
                    else:
                        errors[field_name] = error_message

        if errors:
            return errors
        self.Schema().validate(instance=self, REQUEST=REQUEST,
                               errors=errors, data=data, metadata=metadata)

        self.post_validate(REQUEST, errors)

        for post_validator in subscribers((self,), IObjectPostValidation):
            post_errors = post_validator(REQUEST)
            if post_errors is not None:
                for field_name, error_message in post_errors.items():
                    if field_name in errors:
                        errors[field_name] += " %s" % error_message
                    else:
                        errors[field_name] = error_message

        return errors
开发者ID:MrTango,项目名称:Products.Archetypes,代码行数:34,代码来源:BaseObject.py


示例2: impacts_for

def impacts_for(thing):
    '''
    Return a two element tuple.

    First element is a list of object ids impacted by thing. Second element is
    a list of object ids impacting thing.
    '''
    from ZenPacks.zenoss.Impact.impactd.interfaces \
        import IRelationshipDataProvider

    impacted_by = []
    impacting = []

    guid_manager = IGUIDManager(thing.getDmd())
    for subscriber in subscribers([thing], IRelationshipDataProvider):
        for edge in subscriber.getEdges():
            source = guid_manager.getObject(edge.source)
            impacted = guid_manager.getObject(edge.impacted)

            if source.id == thing.id:
                impacted_by.append(impacted.id)
            elif impacted.id == thing.id:
                impacting.append(source.id)

    return (impacted_by, impacting)
开发者ID:zenoss,项目名称:ZenPacks.zenoss.OpenStackInfrastructure,代码行数:25,代码来源:test_impact.py


示例3: dispatchToComponent

def dispatchToComponent(registration, event):
    """When a utility is registered, dispatch to an event handler registered for
    the particular component registered, the registration and the event.
    """
    handlers = subscribers((registration.component, registration, event), None)
    for handler in handlers:
        pass  # getting them does the work
开发者ID:zestsoftware,项目名称:collective.multisearch,代码行数:7,代码来源:events.py


示例4: publishTraverse

    def publishTraverse(self, request, name):
        view = queryMultiAdapter((self, request), name=name)
        if view is not None:
            if ISaveable.providedBy(view):
                self.saveable = True
            else:
                self.saveable = False

            self.wizard.updateActions()
            return view

        for publisher in subscribers((self, request), IPublisherPlugin):
            try:
                view = publisher.publishTraverse(request, name)
                if ISaveable.providedBy(view):
                    self.saveable = True
                else:
                    self.saveable = False

                self.wizard.updateActions()
                return view
            except NotFound:
                pass

        raise NotFound(self, name, request)
开发者ID:Zojax,项目名称:zojax.wizard,代码行数:25,代码来源:step.py


示例5: transform_obj

def transform_obj(target):
    while True:
        oid, obj = (yield)

        # First, get any subscription adapters registered as transforms
        adapters = subscribers((obj,), IInvalidationOid)
        # Next check for an old-style (regular adapter) transform
        try:
            adapters = chain(adapters, (IInvalidationOid(obj),))
        except TypeError:
            # No old-style adapter is registered
            pass
        transformed = set()
        for adapter in adapters:
            o = adapter.transformOid(oid)
            if isinstance(o, str):
                transformed.add(o)
            elif hasattr(o, '__iter__'):
                # If the transform didn't give back a string, it should have
                # given back an iterable
                transformed.update(o)
        # Get rid of any useless Nones
        transformed.discard(None)
        # Get rid of the original oid, if returned. We don't want to use it IF
        # any transformed oid came back.
        transformed.discard(oid)
        target.send(transformed or (oid,))
开发者ID:zenoss,项目名称:zenoss-prodbin,代码行数:27,代码来源:invalidationmanager.py


示例6: getSubItems

    def getSubItems(self, context):
        """Collect all items that should be displayed in the submenu of context.

        Submenu items are registered as subscribers with interface
        ISubMenuItem.
        """
        return list(subscribers((context, ), ISubMenuItem))
开发者ID:achouhans,项目名称:schooltool-2.8.5,代码行数:7,代码来源:skin.py


示例7: validate

    def validate(self):

        """
        Will walk through all subscribers from IValidator type
        the first one will be returned as valid type. In this way we can supporting a lot of types
        on the same port/service

        :return: matched IValidator subscriber
        """

        for sub in subscribers([self.__msg], IValidator):

            msg = sub.validate()

            self.is_valid = msg.is_valid
            self.message_type = msg.message_type
            self.message = msg.message

            # we want only one correct type of our message so
            # only one validator will response with True

            if self.is_valid is True:

                self.__logger.debug('Matched type is: {}'.format(self.message_type))

                return self

        self.__logger.warning('Main Validator - There are no subscribers from type IValidator')

        return False
开发者ID:dimddev,项目名称:NetCatKS,代码行数:30,代码来源:__init__.py


示例8: check

    def check(self):

        """
        Will trying to get a RootAPI and if match one will fired a process_factory
        of an implementation API

        :return: False if not success otherwise the response from process_factory
        """
        for api in subscribers([self.comp], IJSONResourceRootAPI):

            if api.__class__.__name__.lower() in self.comp.to_dict().keys():

                self.__logger.debug('Candidate API {} for {}'.format(
                    api.__class__.__name__,
                    self.comp.__class__.__name__
                ))

                self.__logger.info('Successful apply API {} for {}'.format(
                    api.__class__.__name__,
                    self.comp.__class__.__name__
                ))

                return api.process_factory()

        return False
开发者ID:dimddev,项目名称:NetCatKS,代码行数:25,代码来源:__init__.py


示例9: applyChanges

def applyChanges(context, form_fields, data, adapters=None):
    if adapters is None:
        adapters = {}

    changed = False

    for form_field in form_fields:
        field = form_field.field
        # Adapt context, if necessary
        interface = field.interface
        adapter = adapters.get(interface)
        if adapter is None:
            if interface is None:
                adapter = context
            else:
                adapter = interface(context)
            adapters[interface] = adapter

        name = form_field.__name__
        newvalue = data.get(name, form_field) # using form_field as marker
        if (newvalue is not form_field) and (field.get(adapter) != newvalue):
            changed = True
            field.set(adapter, newvalue)
            for handler in component.subscribers(
                (adapter, field), IFieldUpdate
                ):
                handler.update()

    return changed
开发者ID:trollfot,项目名称:spear.content,代码行数:29,代码来源:utils.py


示例10: _process_devices

 def _process_devices(self):
     stats = {'Device Count': 0,
              'Decommissioned Devices': 0,
              'CPU Cores':0}
     LINKED_DEVICES = "Linked Devices"
     if LINKED_DEVICES not in stats:
         stats[LINKED_DEVICES] = 0
     for device in self._dmd.Devices.getSubDevicesGen_recursive():
         stats['Device Count'] += 1
         if device.productionState < 0:
             stats["Decommissioned Devices"] += 1
         cpuCount = IDeviceCpuCount(device).cpuCount()
         log.debug("Devices %s has %s cpu cores", device, cpuCount)
         stats['CPU Cores'] += cpuCount
         for adapter in subscribers([device], IDeviceResource):
             adapter.processDevice(stats)
         found_linked = False
         for name, adapter in getAdapters((device,), IDeviceLink):
             if adapter.linkedDevice():
                 key = "%s - %s" % (LINKED_DEVICES, name)
                 if key not in stats:
                     stats[key] = 0
                 stats[key] += 1
                 if not found_linked:
                     stats[LINKED_DEVICES] += 1
                     found_linked = True
                 
             
     return stats
开发者ID:SteelHouseLabs,项目名称:zenoss-prodbin,代码行数:29,代码来源:ZenossAppData.py


示例11: _eventRedispatcher

 def _eventRedispatcher(self, event):
     """This works similar to zope.component.event.objectEventNotify:
     It dispatches object events to subscribers that listen to
     (object, view, event)."""
     adapters = component.subscribers((event.object, self, event), None)
     for adapter in adapters:
         pass # getting them does the work
开发者ID:resa89,项目名称:imusite,代码行数:7,代码来源:kssview.py


示例12: queryMultiSubscriptions

def queryMultiSubscriptions(components, interface):
    """Query for subscriptions on the `components` providing `interface`.

    :parameter components: tuple of components to lookup the subscription for.
    :parameter interface: interface that the subscriptions should provide.
    :return: a list of subscriptions.
    """
    return component.subscribers(components, interface)
开发者ID:resa89,项目名称:imusite,代码行数:8,代码来源:subscription.py


示例13: getExportersForSupportedFileFormat

    def getExportersForSupportedFileFormat(self, file_format):
        """See `ITranslationExporter`."""
        exporters_available = []
        for exporter in subscribers([self], ITranslationFormatExporter):
            if file_format in exporter.supported_source_formats:
                exporters_available.append(exporter)

        return exporters_available
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:8,代码来源:translation_export.py


示例14: is_private

def is_private(ob):
    """
    Do any registered private object adapters define this object as private?
    """
    for adapted in subscribers([ob], IPrivateObjectAdapter):
        if adapted.is_private():
            return True
    return False
开发者ID:damilare,项目名称:zenoss-prodbin,代码行数:8,代码来源:privateobject.py


示例15: dispatchToOpaqueItems

def dispatchToOpaqueItems(ob, event):
    """Dispatch an event to opaque sub-items of a given object.
    """
    for opaque in ob.opaqueValues():
        s = getattr(opaque, '_p_changed', 0)
        for ignored in subscribers((opaque, event), None):
            pass # They do work in the adapter fetch
        if s is None:
            opaque._p_deactivate()
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:9,代码来源:CMFCatalogAware.py


示例16: __call__

 def __call__(self):
     metrics = collections.defaultdict(lambda: {})
     for subscriber in component.subscribers((self.context.dmd,), interfaces.ISystemMetric):
         try:
             metrics[subscriber.category].update(subscriber.metrics())
         except Exception as ex:
             _LOG.warn("An error occurred gathering performance stats: %s" % ex)
         
     self.request.response.write(json.dumps(metrics))
开发者ID:SteelHouseLabs,项目名称:zenoss-prodbin,代码行数:9,代码来源:stats.py


示例17: getExporterProducingTargetFileFormat

    def getExporterProducingTargetFileFormat(self, file_format):
        """See `ITranslationExporter`."""
        for exporter in subscribers([self], ITranslationFormatExporter):
            if (exporter.format == file_format or
                (file_format == TranslationFileFormat.XPI and
                 exporter.format == TranslationFileFormat.XPIPO)):
                # XPIPO is a special case for XPI exports.
                return exporter

        return None
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:10,代码来源:translation_export.py


示例18: publishTraverse

    def publishTraverse(self, request, name):
        # Look at all the traverser plugins, whether they have an answer.
        for traverser in subscribers((self.context, request),
                                     interfaces.ITraverserPlugin):
            try:
                return traverser.publishTraverse(request, name)
            except NotFound:
                pass

        raise NotFound(self.context, name, request)
开发者ID:pombredanne,项目名称:z3c.traverser,代码行数:10,代码来源:traverser.py


示例19: providers

    def providers(self):
        providers = []
        for provider in subscribers([self.context], IExportProvider):
            if provider.layer:
                if not provider.layer.providedBy(self.request):
                    continue

            providers.append(provider)

        return providers
开发者ID:seantis,项目名称:seantis.dir.base,代码行数:10,代码来源:xlsexport.py


示例20: isVM

 def isVM(self):
     if self._isVM is None:
         self._isVM = False
         for deviceType in subscribers((self._device,), IVirtualDeviceType):
             vmType = deviceType.vmType()
             if vmType is not None:
                 self._vmType = vmType
                 self._isVm = True
                 break
     return self._isVM
开发者ID:SteelHouseLabs,项目名称:zenoss-prodbin,代码行数:10,代码来源:ZenossAppData.py



注:本文中的zope.component.subscribers函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python event.objectEventNotify函数代码示例发布时间:2022-05-26
下一篇:
Python component.queryUtility函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap