Skip to main content

Zope Event Publication

Project description

The zope.event package provides a simple event system. It provides:

  • An event publishing system

  • A very simple event-dispatching system on which more sophisticated event dispatching systems can be built. (For example, a type-based event dispatching system that builds on zope.event can be found in zope.component.

Detailed Documentation

Events

This package provides a simple event system on which application-specific event systems can be built.

Application code can generate events without being concerned about the event-processing frameworks that might handle the events.

Events are objects that represent something happening in a system. They are used to extend processing by providing processing plug points.

The package has a list of subscribers. Application code can manage subscriptions by manipulating this list. For the examples here, we’ll save the current contents away and empty the list. We’ll restore the contents when we’re done with our examples.

>>> import zope.event
>>> old_subscribers = zope.event.subscribers[:]
>>> del zope.event.subscribers[:]

The package provides a notify function, which is used to notify subscribers that something has happened:

>>> class MyEvent:
...     pass
>>> event = MyEvent()
>>> zope.event.notify(event)

The notify function is called with a single object, which we call an event. Any object will do:

>>> zope.event.notify(None)
>>> zope.event.notify(42)

An extremely trivial subscription mechanism is provided. Subscribers are simply callback functions:

>>> def f(event):
...     print 'got:', event

that are put into the subscriptions list:

>>> zope.event.subscribers.append(f)
>>> zope.event.notify(42)
got: 42
>>> def g(event):
...     print 'also got:', event
>>> zope.event.subscribers.append(g)
>>> zope.event.notify(42)
got: 42
also got: 42

To unsubscribe, simply remove a subscriber from the list:

>>> zope.event.subscribers.remove(f)
>>> zope.event.notify(42)
also got: 42

Generally, application frameworks will provide more sophisticated subscription mechanisms that build on this simple mechanism. The frameworks will install subscribers that then dispatch to other subscribers based on event types or data.

We’re done, so we’ll restore the subscribers:

>>> zope.event.subscribers[:] = old_subscribers

Download

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zope.event-3.4.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zope.event-3.4.0-py2.4.egg (7.0 kB view details)

Uploaded Egg

File details

Details for the file zope.event-3.4.0.tar.gz.

File metadata

  • Download URL: zope.event-3.4.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for zope.event-3.4.0.tar.gz
Algorithm Hash digest
SHA256 19b1626b75959c6cc16cd3ac0a0d47120dd0c7ced4a3ca780dec25be50f52078
MD5 9fbfdfb1298db09a5029f605ad4940be
BLAKE2b-256 119da0e3365ae23f1fb84a04b91febab2bc74efc868315c8c379c36b58a4965a

See more details on using hashes here.

File details

Details for the file zope.event-3.4.0-py2.4.egg.

File metadata

File hashes

Hashes for zope.event-3.4.0-py2.4.egg
Algorithm Hash digest
SHA256 c6afda09e8a773a3a25d5d435a23e451b2e693a15846832a6da7089c8d2af032
MD5 79af17fa33ec85de3894802e9bb72277
BLAKE2b-256 29dce55a402c446369bf5c1b6928778873df2a3b0fb538525706867bc805db30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page