Skip to main content

Now you see it, it now you don’t!

This package defines a dynamic module type that lets you create objects in the dynamic module on demand.

Usage

To use this package, you should:

  • Identify an appropriate parent module where the dynamic module will live.

  • Ensure that plone.alterego.dynamic.create() is called with this module and a dynamic module name. Typically, you’d do this in the parent module itself, so that the dynamic module is instantiated as soon as the parent module is imported.

  • Register a named utility providing IDynamicObjectFactory. The name should be the same as the full dotted path to the dynamic module. This utility will be responsible for creating the objects that inhabit the dynamicmodule.

Example

For a more fully-featured example, see the alterego.txt doctest.

Let’s say we have a generic content class that should get a unique interface for each instance.

>>> from zope import interface
>>> class IContent(interface.Interface):
...     pass
>>> class Content(object):
...     interface.implements(IContent)

>>> c1 = Content()

To create the unique interface, we will use a dynamic module. There is a helper method to make this easier. It takes a parent module and a name as arguments:

>>> from plone.alterego.dynamic import create
>>> dynamic = create('plone.alterego.tests.dynamic')

We can now import this module:

>>> from plone.alterego.tests import dynamic

To make objects on demand, we’ll need to register a utility that can act as a factory.

>>> from plone.alterego.interfaces import IDynamicObjectFactory
>>> from zope.interface.interface import InterfaceClass
>>> class InterfaceOnDemand(object):
...     interface.implements(IDynamicObjectFactory)
...
...     def __call__(self, name, module):
...         schema = InterfaceClass(name, (interface.Interface,), __module__=module.__name__)
...         setattr(module, name, schema)
...         return schema

This utility should have a name that corresponds to the full, dotted name to the dynamic module. This way, we can have different factories for different dynamic modules. We’d register this in ZCML like so:

<utility
    name="plone.alterego.tests.dynamic"
    provides="plone.alterego.interfaces.IDynamicObjectFactory"
    factory=".factory.InterfaceOnDemand"
    />

From this point forward, when we access an attribute of the dynamic module, the factory will be used:

>>> dynamic.IOne
<InterfaceClass plone.alterego.tests.dynamic.IOne>

Note that so long as the setattr() call above is executed, the factory is called only once. That is, you’ll always get the same object each time you access a given attribute of the dynamic module.

Changelog

3.0.0 (2026-05-07)

Internal:

  • Update configuration files. [plone devs]

3.0.0a1 (2025-11-19)

Breaking changes:

  • Replace pkg_resources namespace with PEP 420 native namespace. Support only Plone 6.2 and Python 3.10+. (#3928)

2.0.2 (2025-09-10)

Internal:

  • Update configuration files. [plone devs] (6e36bcc4)

  • Move distribution to src layout [gforcada] (#4217)

2.0.1 (2024-01-19)

Internal:

  • Update configuration files. [plone devs] (237ff4c8)

2.0.0 (2023-04-15)

Breaking changes:

  • Drop python 2 support. [gforcada] (#1)

1.1.6 (2023-04-15)

Internal:

  • Update configuration files. [plone devs] (5623f8b3)

1.1.5 (2020-04-20)

Bug fixes:

  • Minor packaging updates. (#1)

1.1.4 (2020-03-21)

Bug fixes:

  • Minor packaging updates. [various] (#1)

1.1.3 (2018-11-21)

Bug fixes:

  • Cleanup project level files (setup.py, .travis-ci.yml…) [maurits] [gforcada] (#2524)

  • Initialized towncrier. [gforcada] (#2548)

1.1.3 (unreleased)

1.1.2 (2018-11-21)

Bug fixes:

  • Update code to follow Plone styleguide. [gforcada]

1.1 (2016-11-01)

New features:

  • Add compatibility with Python 3. [datakurre]

1.0.1 (2016-08-11)

Fixes:

  • Use zope.interface decorator. [gforcada]

1.0 (2011-04-30)

  • Use doctest from the stdlib instead of from zope.testing [davisagli]

1.0a1 (2009-04-17)

  • Initial release.

Release files for plone.alterego 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plone.alterego 3.0.0
File Size Uploaded
plone_alterego-3.0.0.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for plone.alterego 3.0.0
File Interpreter ABI Platform
plone_alterego-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / plone_alterego-3.0.0.tar.gz

Download URL plone_alterego-3.0.0.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c136e9bbc7f2cf57bcfb13d8947e9c33cc1d8d4f8cb286cc24cc2c4470e9118a
BLAKE2b-256 checksum
How to use checksums
19c0238fdd69481fa6030f9f7944476095575f89734bc8a069ba070e84b1f542
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / plone_alterego-3.0.0-py3-none-any.whl

Download URL plone_alterego-3.0.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61e4be8dbdbd4bf340d6ffced4e9fd301325e338b1db5fa5a23f168012b79853
BLAKE2b-256 checksum
How to use checksums
248dfdac28e56ddec42a459fb43a96d4ad07452338294a65088b9f9bc16dc59a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

1 release file

1.1

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page