本文整理汇总了Python中zope.component.subscribers函数的典型用法代码示例。如果您正苦于以下问题:Python subscribers函数的具体用法?Python subscribers怎么用?Python subscribers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了subscribers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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)
示例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,))
示例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))
示例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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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()