This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

;--Doctest--

z3c.persistentfactory

The ZCA and the ZODB are a good combination where components require persistent state. ZCA factories or handlers typically retrieve any persistent state required from the persistent objects being adapted. If the persistent state required is not specific to the objects being adapted, a common solution is to register a persistent utility which is then looked up in the factory or handler. The persistent utility approach requires, however, that the one appropriate utility is looked up which requires support in the ZCA registrations either in the interface provided or the utility name.

In some cases, however, it is more consistent with the object oriented semantics of Python and the ZCA to think of the factory or handler as an instance method of a persistent object. With this approach the non-context specific persistent state can be accessed on self.

Instance Method Event Handler

One example where this may be useful is where some non-context persistent state is tightly coupled to some event handlers in such a way where instance methods are better semantics.

The Baz class uses the decorator in the python code. Note that the factory decorator must come before the declaration decorators so that it will be run last and will reflect the declarations.

>>> from z3c.persistentfactory import testing
>>> baz = testing.Baz()

Register the persistent factory wrapped instance method as a handler.

>>> from zope import component
>>> component.provideHandler(factory=baz.factory)

The method adapts IFoo, so create an object providing IFoo to be used as the event.

>>> component.adaptedBy(baz.factory)
(<InterfaceClass z3c.persistentfactory.testing.IFoo>,)
>>> from zope import interface
>>> foo = testing.Foo()
>>> interface.alsoProvides(foo, testing.IFoo)

When the event is notified, the method is called with the event as an argument.

>>> import zope.event
>>> zope.event.notify(foo)
Called <bound method Baz.factory of
<z3c.persistentfactory.testing.Baz object at ...>>
  args: (<z3c.persistentfactory.testing.Foo object at ...>,)
  kwargs: {}

Instance Method Adapter Factory

Another example is where an adapter factory needs to look up persistent state specific to the objects being adapted but where that state can’t be stored on the adapted objects them selves. The component storing the shared persistent state can register one of it’s instance methods as the adapter factory which will look up the necessary persistent state on self.

Register the persistent factory wrapped instance method as an adapter factory.

>>> component.provideAdapter(factory=baz.factory)

The method implements IBar.

>>> tuple(interface.implementedBy(baz.factory))
(<InterfaceClass z3c.persistentfactory.testing.IBar>,)

When the adapter is looked up, the metod is called with the object to be adapted as an argument.

>>> result = component.getAdapter(foo, testing.IBar)
Called <bound method Baz.factory of
<z3c.persistentfactory.testing.Baz object at ...>>
  args: (<z3c.persistentfactory.testing.Foo object at ...>,)
  kwargs: {}
>>> result
(<bound method Baz.factory of
 <z3c.persistentfactory.testing.Baz object at ...>>,
 (<z3c.persistentfactory.testing.Foo object at ...>,), {})

Changelog

0.3 - 2008-04-10

  • Declarer’s declarations don’t track with changes to the class method’s declarations.
  • Isolate declarations on the declarer’s class from declarations on instances.

0.2 - 2008-04-09

  • Improve README.txt with clearer examples

0.1 - 2008-04-08

  • Initial release
Release History

Release History

0.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
z3c.persistentfactory-0.3.tar.gz (7.5 kB) Copy SHA256 Checksum SHA256 Source Apr 10, 2008

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting