==============
plone.alterego
==============
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.
.. code-block:: python
>>> 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:
.. code-block:: python
>>> from plone.alterego.dynamic import create
>>> dynamic = create('plone.alterego.tests.dynamic')
We can now import this module:
.. code-block:: python
>>> from plone.alterego.tests import dynamic
To make objects on demand, we'll need to register a utility that can act
as a factory.
.. code-block:: python
>>> 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:
.. code-block:: XML
<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:
.. code-block:: python
>>> 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
=========
.. You should *NOT* be adding new change log entries to this file.
You should create a file in the news directory instead.
For helpful instructions, please see:
https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst
.. towncrier release notes start
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/plone/plone.alterego",
"name": "plone.alterego",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Plone schema interface",
"author": "Laurence Rowe",
"author_email": "plone-developers@lists.sourceforge.net",
"download_url": "https://files.pythonhosted.org/packages/78/8b/8491a330d13510c81da97485771f261a0bc230526a8c318662db3da3ae74/plone.alterego-2.0.1.tar.gz",
"platform": null,
"description": "==============\nplone.alterego\n==============\n\nNow you see it, it now you don't!\n\nThis package defines a dynamic module type that lets you create objects in the\ndynamic module on demand.\n\nUsage\n-----\n\nTo use this package, you should:\n\n- Identify an appropriate parent module where the dynamic module will live.\n\n- Ensure that plone.alterego.dynamic.create() is called with this module and a dynamic module name. \n 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.\n\n- Register a named utility providing IDynamicObjectFactory. \n The name should be the same as the full dotted path to the dynamic module. \n This utility will be responsible for creating the objects that inhabit the dynamicmodule.\n\nExample\n-------\n\nFor a more fully-featured example, see the alterego.txt doctest.\n\nLet's say we have a generic content class that should get a unique interface\nfor each instance.\n\n.. code-block:: python\n\n >>> from zope import interface\n >>> class IContent(interface.Interface):\n ... pass\n >>> class Content(object):\n ... interface.implements(IContent)\n\n >>> c1 = Content()\n\nTo create the unique interface, we will use a dynamic module. There is a\nhelper method to make this easier. It takes a parent module and a name as\narguments:\n\n.. code-block:: python\n\n >>> from plone.alterego.dynamic import create\n >>> dynamic = create('plone.alterego.tests.dynamic')\n\nWe can now import this module:\n\n.. code-block:: python\n\n >>> from plone.alterego.tests import dynamic\n\nTo make objects on demand, we'll need to register a utility that can act\nas a factory.\n\n.. code-block:: python\n\n >>> from plone.alterego.interfaces import IDynamicObjectFactory\n >>> from zope.interface.interface import InterfaceClass\n >>> class InterfaceOnDemand(object):\n ... interface.implements(IDynamicObjectFactory)\n ...\n ... def __call__(self, name, module):\n ... schema = InterfaceClass(name, (interface.Interface,), __module__=module.__name__)\n ... setattr(module, name, schema)\n ... return schema\n\nThis utility should have a name that corresponds to the full,\ndotted name to the dynamic module. This way, we can have different factories\nfor different dynamic modules. We'd register this in ZCML like so:\n\n.. code-block:: XML\n\n <utility\n name=\"plone.alterego.tests.dynamic\"\n provides=\"plone.alterego.interfaces.IDynamicObjectFactory\"\n factory=\".factory.InterfaceOnDemand\"\n />\n\nFrom this point forward, when we access an attribute of the dynamic module,\nthe factory will be used:\n\n.. code-block:: python\n\n >>> dynamic.IOne\n <InterfaceClass plone.alterego.tests.dynamic.IOne>\n\nNote that so long as the setattr() call above is executed, the factory is\ncalled only once. That is, you'll always get the same object each time you\naccess a given attribute of the dynamic module.\n\n\nChangelog\n=========\n\n.. You should *NOT* be adding new change log entries to this file.\n You should create a file in the news directory instead.\n For helpful instructions, please see:\n https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst\n\n.. towncrier release notes start\n\n2.0.1 (2024-01-19)\n------------------\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (237ff4c8)\n\n\n2.0.0 (2023-04-15)\n------------------\n\nBreaking changes:\n\n\n- Drop python 2 support.\n [gforcada] (#1)\n\n\n1.1.6 (2023-04-15)\n------------------\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (5623f8b3)\n\n\n1.1.5 (2020-04-20)\n------------------\n\nBug fixes:\n\n\n- Minor packaging updates. (#1)\n\n\n1.1.4 (2020-03-21)\n------------------\n\nBug fixes:\n\n\n- Minor packaging updates. [various] (#1)\n\n\n1.1.3 (2018-11-21)\n------------------\n\nBug fixes:\n\n\n- Cleanup project level files (setup.py, .travis-ci.yml...) [maurits]\n [gforcada] (#2524)\n- Initialized towncrier. [gforcada] (#2548)\n\n\n1.1.3 (unreleased)\n------------------\n\n\n1.1.2 (2018-11-21)\n------------------\n\nBug fixes:\n\n- Update code to follow Plone styleguide.\n [gforcada]\n\n1.1 (2016-11-01)\n----------------\n\nNew features:\n\n- Add compatibility with Python 3. [datakurre]\n\n\n1.0.1 (2016-08-11)\n------------------\n\nFixes:\n\n- Use zope.interface decorator.\n [gforcada]\n\n\n1.0 (2011-04-30)\n----------------\n\n- Use doctest from the stdlib instead of from zope.testing\n [davisagli]\n\n\n1.0a1 (2009-04-17)\n------------------\n\n- Initial release.\n",
"bugtrack_url": null,
"license": "LGPL",
"summary": "Low level support for dynamic modules",
"version": "2.0.1",
"project_urls": {
"Homepage": "https://github.com/plone/plone.alterego"
},
"split_keywords": [
"plone",
"schema",
"interface"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "134e99bb16a38772b09d87663090d4afc954d74d80b43634d38e89857949e6a1",
"md5": "9a269c5f920bc5f2e9264b70a459a4f6",
"sha256": "e161e62d803f3468e86917a0233b29a590b575b21afa6842ef69d783fa08405a"
},
"downloads": -1,
"filename": "plone.alterego-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9a269c5f920bc5f2e9264b70a459a4f6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7182,
"upload_time": "2024-01-19T08:48:21",
"upload_time_iso_8601": "2024-01-19T08:48:21.861743Z",
"url": "https://files.pythonhosted.org/packages/13/4e/99bb16a38772b09d87663090d4afc954d74d80b43634d38e89857949e6a1/plone.alterego-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "788b8491a330d13510c81da97485771f261a0bc230526a8c318662db3da3ae74",
"md5": "26332f28ff1ed173045de184094cbbfd",
"sha256": "b59b103df670e6fbe2950df859a70447b9ccd60b86ba87e838efeb11b13a9ec6"
},
"downloads": -1,
"filename": "plone.alterego-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "26332f28ff1ed173045de184094cbbfd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 14172,
"upload_time": "2024-01-19T08:48:23",
"upload_time_iso_8601": "2024-01-19T08:48:23.644831Z",
"url": "https://files.pythonhosted.org/packages/78/8b/8491a330d13510c81da97485771f261a0bc230526a8c318662db3da3ae74/plone.alterego-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-19 08:48:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "plone",
"github_project": "plone.alterego",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "plone.alterego"
}