==============
plone.behavior
==============
.. contents:: Table of Contents
:depth: 2
Overview
========
This package provides support for **behaviors**.
A behavior is a reusable aspect of an object that can be enabled or disabled without changing the component registry.
A behavior is described by an interface, and has metadata such as a title and a description.
The behavior can be looked up by a given short name or by the dotted name of the interface.
With this unique name behaviors metadata can be looked up.
When the behavior is enabled for an object, you will be able to adapt the object to the interface.
In some cases, the interface can be used as a marker interface as well.
As an example, let's say that your application needs to support object-level locking.
This can be modeled via an adapter, but you want to leave it until runtime to determine whether locking is enabled for a particular object.
You could then register locking as a behavior.
**Requirements and Limitations:**
* This package comes with support for registering behaviors and factories.
* It does not implement the policy for determining what behaviors are enabled on a particular object at a particular time.
That decision is deferred to an ``IBehaviorAssignable`` adapter, which must be implemented (``plone.dexterity`` implements this).
* Like the ``IBehaviorAssignable`` plumbing, marker interface support needs to be enabled on a per-application basis.
This package also does not directly support the adding of marker interfaces to instances.
To do that, you can either use an event handler to mark an object when it is created, or a dynamic __providedBy__ descriptor that does the lookup on the fly (but you probably want some caching).
A sample event handler is provided with this package, but is not registered by default
* The intention is that behavior assignment is generic across an application, used for multiple, optional behaviors.
It probably doesn't make much sense to use ``plone.behavior`` for a single type of object.
The means to keep track of which behaviors are enabled for what types of objects will be application specific.
Usage
=====
Explained
---------
A behavior is written much like an adapter, except that you don't specify the type of context being adapted directly.
For example::
from zope.interface import Interface
from zope.interface import implementer
class ILockingSupport(Interface):
"""Support locking
"""
def lock():
"""Lock an object
"""
def unlock():
"""Unlock an object
"""
@implementer(ILockingSupport)
class LockingSupport(object):
def __init__(self, context):
self.context = context
def lock(self):
# do something
def unlock(self):
# do something
This interface (which describes the type of behavior) and class (which describes the implementation of the behavior) then needs to be registered.
The simplest way to do that is to load the ``meta.zcml`` file from this package and use ZCML::
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="my.package">
<include package="plone.behavior" file="meta.zcml" />
<plone:behavior
name="locking_support"
title="Locking support"
description="Optional object-level locking"
provides=".interfaces.ILockingSupport"
factory=".locking.LockingSupport"
/>
</configure>
After this is done you can adapt a context to ``ILockingSupport`` as normal::
locking = ILockingSupport(context, None)
if locking is not None:
locking.lock()
The ``name`` can be used for lookup instead of the full dotted name of the interface::
from plone.behavior.interfaces import IBehavior
from zope.component import getUtility
registration = getUtility(IBehavior, name='locking_support')
We also have a helper function to achieve this::
from plone.behavior.registration import lookup_behavior_registration
registration = lookup_behavior_registration(name='locking_support')
You'll get an instance of ``LockingSupport`` if context can be adapted to ``IBehaviorAssignable`` (which, recall, is application specific),
and if the implementation of ``IBehaviorAssignable`` says that this context supports this particular behavior.
It is also possible to let the provided interface act as a marker interface that is to be provided directly by the instance.
To achieve this, omit the ``factory`` argument.
This is useful if you need to register other adapters for instances providing a particular behavior.
ZCML Reference
--------------
The ``plone:behavior`` directive uses the namespace ``xmlns:plone="http://namespaces.plone.org/plone"``.
In order to enable it loading of its ``meta.zcml`` is needed, use::
<include package="plone.behavior" file="meta.zcml" />
The directive supports the attributes:
``title``
A user friendly title for this behavior (required).
``description``
A longer description for this behavior (optional).
``provides``
An interface to which the behavior can be adapted.
This is what the conditional adapter factory will be registered as providing (required).
``name``
Convenience lookup name for this behavior (optional).
The behavior will be always registered under the dotted name of ``provides`` attribute.
This are usually long names. ``name`` is a short name for this.
If ``name`` is given the behavior is registered additional under it.
Anyway using short namespaces in ``name`` is recommended.
``name_only``
If set to ``yes`` or ``true`` the behavior is registered only under the given name,
but not under the dotted path of the ``provides`` interface.
This makes ``name`` mandatory.
``marker``
A marker interface to be applied by the behavior.
If ``factory`` is not given, then this is optional and defaults to the value of ``provides``.
If factory is given ``marker`` is required and should be different from ``provides`` - even if its not enforced.
``factory``
The factory for this behavior (optional).
If no factory is given, the behavior context is assumed to provide the interface given by ``provides`` itself.
If factory provides ``plone.behavior.interfaces.ISchemaAwareFactory`` the factory is assumed to be a callable.
``ISchemaAwareFactory`` is an interface for factories that should be initialised with a schema.
It is called with the value given in ``provides`` as the only argument.
The value returned is then used as the factory, another callable that can create appropriate behavior factories on demand.
``for``
The type of object to register the conditional adapter factory for (optional).
Must be omitted is no ``factory`` is given.
The default is either to auto-detect what the factory adapts (i.e. using the ``@adapter`` decorator) or to fall back to ``zope.interface.Interface`` (also written as ``*`` in ZCML).
Must be one element (no multiadapters, applies also for auto-detection).
``former_dotted_names``
In case a behavior is modified so that its dotted name changes, this field can be used to register the old name(s). Therefore, it is possible to retrieve the name(s) under which a behavior was formerly registered under.
If a call to ``lookup_behavior_registration`` does not find a behavior under the given name, it will look at the former dotted names to try and find the behavior.
ZCML Examples
-------------
Example usage, given
- some ``context`` (some arbitrary object) which is ``IBehaviorAssignable``,
- an ``IMyBehavior`` interface intended to be used as ``provides``,
- an ``IMyMarker`` interface intended to be used as ``marker``,
- a ``MyFactory`` class implementing ``IMyBehavior`` ,
- a ``MySchemaAwareFactory`` class implementing ``IMyBehavior`` and ``plone.behavior.interfaces.ISchemaAwareFactory``,
- an ``IMyType`` intended to be used as ``for``.
- some ``typed_context`` (some arbitrary object) which is ``IBehaviorAssignable`` and provides ``IMyType``,
- an ``MyTypedFactory`` class implementing ``IMyBehavior`` and adapting ``IMyType``,
``title`` and ``description`` is trivial, so we don't cover it here in the explanation.
We don't cover ``name`` too, because it's not having any effect in this usage.
To simplify it, we assume ``context`` ``IBehaviorAssignable`` always supports the behavior.
Also for simplifications sake we assume some magic applies the marker interface to ``context``
I.e. both is done by ``plone.dexterity``.
**Example 1** - only ``provides`` given::
<plone:behavior
title="Example 1"
provides="IMyBehavior"
/>
- ``marker`` defaults to ``provides``,
- with ``behavior = IMyBehavior(context)`` the ``context`` itself is returned,
- ``context`` provides ``IBehavior``,
**Example 2** - also ``factory`` is given, so ``marker`` is required:
.. warning::
Using the same Interface as marker and behavior works, but is not recommended and will be deprecated in future.
It is semantically wrong!
Go for Example 3 instead!
::
<plone:behavior
title="Example 1"
provides="IMyBehavior"
marker="IMyBehavior"
factory="MyFactory"
/>
- ``marker`` is the same as ``provides``,
- with ``behavior = IMyBehavior(context)`` a ``MyFactory`` instance is returned,
- ``context`` provides ``IMyBehavior``,
- ``MyFactory`` instance provides ``IMyBehavior``,
- having ``context`` and ``MyFactory`` providing both the same interface is ugly and not recommended!
**Example 3** - in example 2 both, factory and context are providing the ``IMyBehavior``.
This may lead to confusion, so now better with a ``marker``::
<plone:behavior
title="Example 1"
provides="IMyBehavior"
marker="IMyMarker"
factory="MyFactory"
/>
- with ``behavior = IMyBehavior(context)`` a ``MyFactory`` instance is returned,
- ``context`` provides ``IMyMarker``,
- ``MyFactory`` instance provides ``IMyBehavior``,
**Example 4** - like example 3 but with an ``MySchemaAwareFactory``::
<plone:behavior
title="Example 1"
provides="IMyBehavior"
marker="IMyMarker"
factory="MySchemaAwareFactory"
/>
- with ``behavior = IMyBehavior(context)`` some factory instance is returned as a result from calling a ``MySchemaAwareFactory`` instance with ``IMyBehavior`` as argument,
- ``context`` provides ``IMyMarker``,
- ``MyFactory`` instance provides ``IMyBehavior``,
**Example 5** - the behavior should be restricted to the ``typed_context``::
<plone:behavior
title="Example 1"
provides="IMyBehavior"
marker="IMyMarker"
factory="MyFactory"
for="IMyType"
/>
- with ``behavior = IMyBehavior(context, None)`` it could not adapt and ``behavior`` is ``None``,
- with ``behavior = IMyBehavior(typed_context)`` a ``MyFactory`` instance is returned,
- ``context`` provides ``IMyMarker``,
- ``MyFactory`` provides ``IMyBehavior``,
**Example 6** - the behavior should be restricted to the ``typed_context`` by auto-detection.
The ``MyTypedFactory`` class adapts ``IMyType`` using a class decorator ``@adapter(IMyType)``::
<plone:behavior
title="Example 1"
provides="IMyBehavior"
marker="IMyMarker"
factory="MyTypedFactory"
/>
- with ``behavior = IMyBehavior(context, None)`` it could not adapt and ``behavior`` is ``None``,
- with ``behavior = IMyBehavior(typed_context)`` a ``MyFactory`` instance is returned,
- ``context`` provides ``IMyMarker``,
- ``MyFactory`` instance provides ``IMyBehavior``,
Further Reading
---------------
For more details please read the doctests in the source code: ``behavior.rst``, ``directives.rst`` and ``annotation.rst``.
Source Code
===========
Contributors please read the document `Process for Plone core's development <https://docs.plone.org/develop/coredev/docs/index.html>`_
Sources are at the `Plone code repository hosted at Github <https://github.com/plone/plone.behavior>`_.
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.7 support.
[gforcada] (#1)
Internal:
- Update configuration files.
[plone devs] (a9dd65cc)
1.4.0 (2020-09-07)
------------------
New features:
- Drop Plone 4.3 support.
[maurits] (#3130)
Bug fixes:
- Fixed deprecation warning for ComponentLookupError.
[maurits] (#3130)
1.3.2 (2020-04-20)
------------------
Bug fixes:
- Minor packaging updates. (#1)
1.3.1 (2020-03-08)
------------------
Bug fixes:
- Improved documentation. [jensens] (#0)
1.3.0 (2019-02-13)
------------------
New features:
- New option ``former_dotted_names`` that allows to register the former name
under which a behavior used to be registered. This can be useful to ensure a
smooth transition in case a behavior's dotted name is changed. [pysailor]
(#18)
1.2.1 (2018-01-17)
------------------
Bug fixes:
- Fixed import of dotted path in example. [fulv]
1.2.0 (2017-03-23)
------------------
New features:
- For zcml registration:
If both, no ``for`` and no ``@adapter`` is given,
fall first back to ``marker`` if given (new),
else to ``Interface`` (as it was already before).
[jensens]
Bug fixes:
- Cleanup: Make Jenkins CI code analysis silent by fixing the issues.
[jensens]
1.1.4 (2016-12-06)
------------------
Bug fixes:
- Add already introduced attribute ``name`` to interface IBehavior.
This was missing.
Also modernized other IBehavior interface descriptions a bit.
[jensens]
1.1.3 (2016-11-09)
------------------
New features:
- Support Python 3. [davisagli]
1.1.2 (2016-08-11)
------------------
New:
- New option to register a behavior only by it's short name and not by it's dotted name.
This enables more advanced behavior subclassing capabilities.
[jensens]
1.1.1 (2016-02-25)
------------------
Fixes:
- Make doctest comparison more robust against zope.component __repr__ changes.
[thet]
1.1 (2015-07-18)
----------------
- Corrected typo in warning.
[jensens]
- Add name to behavior directive. This name can be used to lookup behavior
registrations by new plone.behaviors.registration.
lookup_behavior_registration function.
[rnixx]
- Added more documentation, simplified code in directive, added a warning if
``for`` is given w/o ``factory``.
[jensens]
1.0.3 (2015-04-29)
------------------
- Code modernization: utf-header, pep8, rst-files, adapter/implementer
decorators, ...
[jensens]
1.0.2 (2013-01-17)
------------------
- Remove dependence of tests on zope.app.testing.
[davisagli]
1.0.1 - 2011-05-20
------------------
- Relicense under BSD license.
See http://plone.org/foundation/materials/foundation-resolutions/plone-framework-components-relicensing-policy
[davisagli]
1.0 - 2011-04-30
----------------
- Use stdlib doctest instead of the deprecated one in zope.testing.
[davisagli]
- 'plone:behavior' zcml directive use now MessageID for title and description.
[sylvainb]
1.0b6 - 2009-11-17
------------------
- Fix tests for Zope 2.12
[optilude]
1.0b5 - 2009-07-12
------------------
- Changed API methods and arguments to mixedCase to be more consistent with
the rest of Zope. This is a non-backwards-compatible change. Our profuse
apologies, but it's now or never. :-/
If you find that you get import errors or unknown keyword arguments in your
code, please change names from foo_bar too fooBar, e.g.
enumerate_behaviors() becomes enumerateBehaviors().
[optilude]
1.0b4 - 2009-06-07
------------------
- Allow a marker-interface-only behavior to be set by using the 'provides'
attribute (previously 'interface') in the <plone:behavior /> directive
without a 'factory' attribute. The 'marker' attribute (previously known as
'subtype') is now only required if there is a marker used in addition to
a behavior adapter with a separate interface ('provides') and factory.
[optilude]
- Rename the 'interface' attribute of <plone:behavior /> to 'provides' to
be more consistent with the <adapter /> directive. This is a backwards
incompatible change!
[optilude]
- Rename the 'subtype' attribute of <plone:behavior /> to 'marker' to
be more explicit about its purpose. This is a backwards
incompatible change!
[optilude]
1.0b3 - 2009-04-17
------------------
- Allow behaviors with no factory.
[alecm]
- Provide a vocabulary of available behaviors.
[davisagli]
1.0b1 - 2008-04-27
------------------
- Initial release
Raw data
{
"_id": null,
"home_page": "https://github.com/plone/plone.behavior",
"name": "plone.behavior",
"maintainer": "Plone Foundation - Release Team",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "releaseteam@plone.org",
"keywords": "Plone behavior registry",
"author": "Martin Aspeli",
"author_email": "optilude@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/8c/12/6405b8e23561a23eaec78a62fedc13ae276b3eae90fe1ca1bd62f9615230/plone.behavior-2.0.1.tar.gz",
"platform": null,
"description": "==============\nplone.behavior\n==============\n\n.. contents:: Table of Contents\n :depth: 2\n\n\nOverview\n========\n\nThis package provides support for **behaviors**.\n\n A behavior is a reusable aspect of an object that can be enabled or disabled without changing the component registry.\n\nA behavior is described by an interface, and has metadata such as a title and a description.\nThe behavior can be looked up by a given short name or by the dotted name of the interface.\nWith this unique name behaviors metadata can be looked up.\nWhen the behavior is enabled for an object, you will be able to adapt the object to the interface.\nIn some cases, the interface can be used as a marker interface as well.\n\nAs an example, let's say that your application needs to support object-level locking.\nThis can be modeled via an adapter, but you want to leave it until runtime to determine whether locking is enabled for a particular object.\nYou could then register locking as a behavior.\n\n**Requirements and Limitations:**\n\n* This package comes with support for registering behaviors and factories.\n\n* It does not implement the policy for determining what behaviors are enabled on a particular object at a particular time.\n That decision is deferred to an ``IBehaviorAssignable`` adapter, which must be implemented (``plone.dexterity`` implements this).\n\n* Like the ``IBehaviorAssignable`` plumbing, marker interface support needs to be enabled on a per-application basis.\n This package also does not directly support the adding of marker interfaces to instances.\n To do that, you can either use an event handler to mark an object when it is created, or a dynamic __providedBy__ descriptor that does the lookup on the fly (but you probably want some caching).\n A sample event handler is provided with this package, but is not registered by default\n\n* The intention is that behavior assignment is generic across an application, used for multiple, optional behaviors.\n It probably doesn't make much sense to use ``plone.behavior`` for a single type of object.\n The means to keep track of which behaviors are enabled for what types of objects will be application specific.\n\nUsage\n=====\n\nExplained\n---------\n\nA behavior is written much like an adapter, except that you don't specify the type of context being adapted directly.\nFor example::\n\n from zope.interface import Interface\n from zope.interface import implementer\n\n class ILockingSupport(Interface):\n \"\"\"Support locking\n \"\"\"\n\n def lock():\n \"\"\"Lock an object\n \"\"\"\n\n def unlock():\n \"\"\"Unlock an object\n \"\"\"\n\n @implementer(ILockingSupport)\n class LockingSupport(object):\n\n def __init__(self, context):\n self.context = context\n\n def lock(self):\n # do something\n\n def unlock(self):\n # do something\n\nThis interface (which describes the type of behavior) and class (which describes the implementation of the behavior) then needs to be registered.\n\nThe simplest way to do that is to load the ``meta.zcml`` file from this package and use ZCML::\n\n <configure\n xmlns=\"http://namespaces.zope.org/zope\"\n xmlns:plone=\"http://namespaces.plone.org/plone\"\n i18n_domain=\"my.package\">\n\n <include package=\"plone.behavior\" file=\"meta.zcml\" />\n\n <plone:behavior\n name=\"locking_support\"\n title=\"Locking support\"\n description=\"Optional object-level locking\"\n provides=\".interfaces.ILockingSupport\"\n factory=\".locking.LockingSupport\"\n />\n\n </configure>\n\nAfter this is done you can adapt a context to ``ILockingSupport`` as normal::\n\n locking = ILockingSupport(context, None)\n\n if locking is not None:\n locking.lock()\n\nThe ``name`` can be used for lookup instead of the full dotted name of the interface::\n\n from plone.behavior.interfaces import IBehavior\n from zope.component import getUtility\n\n registration = getUtility(IBehavior, name='locking_support')\n\nWe also have a helper function to achieve this::\n\n from plone.behavior.registration import lookup_behavior_registration\n\n registration = lookup_behavior_registration(name='locking_support')\n\n\nYou'll get an instance of ``LockingSupport`` if context can be adapted to ``IBehaviorAssignable`` (which, recall, is application specific),\nand if the implementation of ``IBehaviorAssignable`` says that this context supports this particular behavior.\n\nIt is also possible to let the provided interface act as a marker interface that is to be provided directly by the instance.\nTo achieve this, omit the ``factory`` argument.\nThis is useful if you need to register other adapters for instances providing a particular behavior.\n\nZCML Reference\n--------------\n\nThe ``plone:behavior`` directive uses the namespace ``xmlns:plone=\"http://namespaces.plone.org/plone\"``.\nIn order to enable it loading of its ``meta.zcml`` is needed, use::\n\n <include package=\"plone.behavior\" file=\"meta.zcml\" />\n\nThe directive supports the attributes:\n\n``title``\n A user friendly title for this behavior (required).\n\n``description``\n A longer description for this behavior (optional).\n\n``provides``\n An interface to which the behavior can be adapted.\n This is what the conditional adapter factory will be registered as providing (required).\n\n``name``\n Convenience lookup name for this behavior (optional).\n The behavior will be always registered under the dotted name of ``provides`` attribute.\n This are usually long names. ``name`` is a short name for this.\n If ``name`` is given the behavior is registered additional under it.\n Anyway using short namespaces in ``name`` is recommended.\n\n``name_only``\n If set to ``yes`` or ``true`` the behavior is registered only under the given name,\n but not under the dotted path of the ``provides`` interface.\n This makes ``name`` mandatory.\n\n``marker``\n A marker interface to be applied by the behavior.\n If ``factory`` is not given, then this is optional and defaults to the value of ``provides``.\n If factory is given ``marker`` is required and should be different from ``provides`` - even if its not enforced.\n\n``factory``\n The factory for this behavior (optional).\n If no factory is given, the behavior context is assumed to provide the interface given by ``provides`` itself.\n\n If factory provides ``plone.behavior.interfaces.ISchemaAwareFactory`` the factory is assumed to be a callable.\n ``ISchemaAwareFactory`` is an interface for factories that should be initialised with a schema.\n It is called with the value given in ``provides`` as the only argument.\n The value returned is then used as the factory, another callable that can create appropriate behavior factories on demand.\n\n``for``\n The type of object to register the conditional adapter factory for (optional).\n Must be omitted is no ``factory`` is given.\n\n The default is either to auto-detect what the factory adapts (i.e. using the ``@adapter`` decorator) or to fall back to ``zope.interface.Interface`` (also written as ``*`` in ZCML).\n\n Must be one element (no multiadapters, applies also for auto-detection).\n\n``former_dotted_names``\n In case a behavior is modified so that its dotted name changes, this field can be used to register the old name(s). Therefore, it is possible to retrieve the name(s) under which a behavior was formerly registered under.\n\n If a call to ``lookup_behavior_registration`` does not find a behavior under the given name, it will look at the former dotted names to try and find the behavior.\n\n\nZCML Examples\n-------------\n\nExample usage, given\n\n- some ``context`` (some arbitrary object) which is ``IBehaviorAssignable``,\n- an ``IMyBehavior`` interface intended to be used as ``provides``,\n- an ``IMyMarker`` interface intended to be used as ``marker``,\n- a ``MyFactory`` class implementing ``IMyBehavior`` ,\n- a ``MySchemaAwareFactory`` class implementing ``IMyBehavior`` and ``plone.behavior.interfaces.ISchemaAwareFactory``,\n- an ``IMyType`` intended to be used as ``for``.\n- some ``typed_context`` (some arbitrary object) which is ``IBehaviorAssignable`` and provides ``IMyType``,\n- an ``MyTypedFactory`` class implementing ``IMyBehavior`` and adapting ``IMyType``,\n\n``title`` and ``description`` is trivial, so we don't cover it here in the explanation.\nWe don't cover ``name`` too, because it's not having any effect in this usage.\nTo simplify it, we assume ``context`` ``IBehaviorAssignable`` always supports the behavior.\nAlso for simplifications sake we assume some magic applies the marker interface to ``context``\nI.e. both is done by ``plone.dexterity``.\n\n**Example 1** - only ``provides`` given::\n\n <plone:behavior\n title=\"Example 1\"\n provides=\"IMyBehavior\"\n />\n\n- ``marker`` defaults to ``provides``,\n- with ``behavior = IMyBehavior(context)`` the ``context`` itself is returned,\n- ``context`` provides ``IBehavior``,\n\n**Example 2** - also ``factory`` is given, so ``marker`` is required:\n\n.. warning::\n Using the same Interface as marker and behavior works, but is not recommended and will be deprecated in future.\n It is semantically wrong!\n\n Go for Example 3 instead!\n\n::\n\n <plone:behavior\n title=\"Example 1\"\n provides=\"IMyBehavior\"\n marker=\"IMyBehavior\"\n factory=\"MyFactory\"\n />\n\n- ``marker`` is the same as ``provides``,\n- with ``behavior = IMyBehavior(context)`` a ``MyFactory`` instance is returned,\n- ``context`` provides ``IMyBehavior``,\n- ``MyFactory`` instance provides ``IMyBehavior``,\n- having ``context`` and ``MyFactory`` providing both the same interface is ugly and not recommended!\n\n**Example 3** - in example 2 both, factory and context are providing the ``IMyBehavior``.\nThis may lead to confusion, so now better with a ``marker``::\n\n <plone:behavior\n title=\"Example 1\"\n provides=\"IMyBehavior\"\n marker=\"IMyMarker\"\n factory=\"MyFactory\"\n />\n\n- with ``behavior = IMyBehavior(context)`` a ``MyFactory`` instance is returned,\n- ``context`` provides ``IMyMarker``,\n- ``MyFactory`` instance provides ``IMyBehavior``,\n\n**Example 4** - like example 3 but with an ``MySchemaAwareFactory``::\n\n <plone:behavior\n title=\"Example 1\"\n provides=\"IMyBehavior\"\n marker=\"IMyMarker\"\n factory=\"MySchemaAwareFactory\"\n />\n\n- with ``behavior = IMyBehavior(context)`` some factory instance is returned as a result from calling a ``MySchemaAwareFactory`` instance with ``IMyBehavior`` as argument,\n- ``context`` provides ``IMyMarker``,\n- ``MyFactory`` instance provides ``IMyBehavior``,\n\n**Example 5** - the behavior should be restricted to the ``typed_context``::\n\n <plone:behavior\n title=\"Example 1\"\n provides=\"IMyBehavior\"\n marker=\"IMyMarker\"\n factory=\"MyFactory\"\n for=\"IMyType\"\n />\n\n- with ``behavior = IMyBehavior(context, None)`` it could not adapt and ``behavior`` is ``None``,\n- with ``behavior = IMyBehavior(typed_context)`` a ``MyFactory`` instance is returned,\n- ``context`` provides ``IMyMarker``,\n- ``MyFactory`` provides ``IMyBehavior``,\n\n**Example 6** - the behavior should be restricted to the ``typed_context`` by auto-detection.\nThe ``MyTypedFactory`` class adapts ``IMyType`` using a class decorator ``@adapter(IMyType)``::\n\n <plone:behavior\n title=\"Example 1\"\n provides=\"IMyBehavior\"\n marker=\"IMyMarker\"\n factory=\"MyTypedFactory\"\n />\n\n- with ``behavior = IMyBehavior(context, None)`` it could not adapt and ``behavior`` is ``None``,\n- with ``behavior = IMyBehavior(typed_context)`` a ``MyFactory`` instance is returned,\n- ``context`` provides ``IMyMarker``,\n- ``MyFactory`` instance provides ``IMyBehavior``,\n\n\nFurther Reading\n---------------\n\nFor more details please read the doctests in the source code: ``behavior.rst``, ``directives.rst`` and ``annotation.rst``.\n\n\nSource Code\n===========\n\nContributors please read the document `Process for Plone core's development <https://docs.plone.org/develop/coredev/docs/index.html>`_\n\nSources are at the `Plone code repository hosted at Github <https://github.com/plone/plone.behavior>`_.\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.7 support.\n [gforcada] (#1)\n\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (a9dd65cc)\n\n\n1.4.0 (2020-09-07)\n------------------\n\nNew features:\n\n\n- Drop Plone 4.3 support.\n [maurits] (#3130)\n\n\nBug fixes:\n\n\n- Fixed deprecation warning for ComponentLookupError.\n [maurits] (#3130)\n\n\n1.3.2 (2020-04-20)\n------------------\n\nBug fixes:\n\n\n- Minor packaging updates. (#1)\n\n\n1.3.1 (2020-03-08)\n------------------\n\nBug fixes:\n\n\n- Improved documentation. [jensens] (#0)\n\n\n1.3.0 (2019-02-13)\n------------------\n\nNew features:\n\n\n- New option ``former_dotted_names`` that allows to register the former name\n under which a behavior used to be registered. This can be useful to ensure a\n smooth transition in case a behavior's dotted name is changed. [pysailor]\n (#18)\n\n\n1.2.1 (2018-01-17)\n------------------\n\nBug fixes:\n\n- Fixed import of dotted path in example. [fulv]\n\n\n1.2.0 (2017-03-23)\n------------------\n\nNew features:\n\n- For zcml registration:\n If both, no ``for`` and no ``@adapter`` is given,\n fall first back to ``marker`` if given (new),\n else to ``Interface`` (as it was already before).\n [jensens]\n\nBug fixes:\n\n- Cleanup: Make Jenkins CI code analysis silent by fixing the issues.\n [jensens]\n\n\n1.1.4 (2016-12-06)\n------------------\n\nBug fixes:\n\n- Add already introduced attribute ``name`` to interface IBehavior.\n This was missing.\n Also modernized other IBehavior interface descriptions a bit.\n [jensens]\n\n\n1.1.3 (2016-11-09)\n------------------\n\nNew features:\n\n- Support Python 3. [davisagli]\n\n\n1.1.2 (2016-08-11)\n------------------\n\nNew:\n\n- New option to register a behavior only by it's short name and not by it's dotted name.\n This enables more advanced behavior subclassing capabilities.\n [jensens]\n\n\n1.1.1 (2016-02-25)\n------------------\n\nFixes:\n\n- Make doctest comparison more robust against zope.component __repr__ changes.\n [thet]\n\n\n1.1 (2015-07-18)\n----------------\n\n- Corrected typo in warning.\n [jensens]\n\n- Add name to behavior directive. This name can be used to lookup behavior\n registrations by new plone.behaviors.registration.\n lookup_behavior_registration function.\n [rnixx]\n\n- Added more documentation, simplified code in directive, added a warning if\n ``for`` is given w/o ``factory``.\n [jensens]\n\n\n1.0.3 (2015-04-29)\n------------------\n\n- Code modernization: utf-header, pep8, rst-files, adapter/implementer\n decorators, ...\n [jensens]\n\n\n1.0.2 (2013-01-17)\n------------------\n\n- Remove dependence of tests on zope.app.testing.\n [davisagli]\n\n\n1.0.1 - 2011-05-20\n------------------\n\n- Relicense under BSD license.\n See http://plone.org/foundation/materials/foundation-resolutions/plone-framework-components-relicensing-policy\n [davisagli]\n\n\n1.0 - 2011-04-30\n----------------\n\n- Use stdlib doctest instead of the deprecated one in zope.testing.\n [davisagli]\n\n- 'plone:behavior' zcml directive use now MessageID for title and description.\n [sylvainb]\n\n\n1.0b6 - 2009-11-17\n------------------\n\n- Fix tests for Zope 2.12\n [optilude]\n\n\n1.0b5 - 2009-07-12\n------------------\n\n- Changed API methods and arguments to mixedCase to be more consistent with\n the rest of Zope. This is a non-backwards-compatible change. Our profuse\n apologies, but it's now or never. :-/\n\n If you find that you get import errors or unknown keyword arguments in your\n code, please change names from foo_bar too fooBar, e.g.\n enumerate_behaviors() becomes enumerateBehaviors().\n [optilude]\n\n\n1.0b4 - 2009-06-07\n------------------\n\n- Allow a marker-interface-only behavior to be set by using the 'provides'\n attribute (previously 'interface') in the <plone:behavior /> directive\n without a 'factory' attribute. The 'marker' attribute (previously known as\n 'subtype') is now only required if there is a marker used in addition to\n a behavior adapter with a separate interface ('provides') and factory.\n [optilude]\n\n- Rename the 'interface' attribute of <plone:behavior /> to 'provides' to\n be more consistent with the <adapter /> directive. This is a backwards\n incompatible change!\n [optilude]\n\n- Rename the 'subtype' attribute of <plone:behavior /> to 'marker' to\n be more explicit about its purpose. This is a backwards\n incompatible change!\n [optilude]\n\n\n1.0b3 - 2009-04-17\n------------------\n\n- Allow behaviors with no factory.\n [alecm]\n\n- Provide a vocabulary of available behaviors.\n [davisagli]\n\n\n1.0b1 - 2008-04-27\n------------------\n\n- Initial release\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Infrastructure for maintaining a registry of available behaviors",
"version": "2.0.1",
"project_urls": {
"Homepage": "https://github.com/plone/plone.behavior"
},
"split_keywords": [
"plone",
"behavior",
"registry"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "70a2c1bc62639a25f0e96f8787cb5f05040d606a9c4a43f9f09e9c3877dbb502",
"md5": "413608b4930a20e9264c326c14bab66c",
"sha256": "2befc5c45a0a645bbc07dd56ac248a2b384fb0dee0390e010b3158fcfebb20f7"
},
"downloads": -1,
"filename": "plone.behavior-2.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "413608b4930a20e9264c326c14bab66c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 24049,
"upload_time": "2024-01-19T09:43:32",
"upload_time_iso_8601": "2024-01-19T09:43:32.787029Z",
"url": "https://files.pythonhosted.org/packages/70/a2/c1bc62639a25f0e96f8787cb5f05040d606a9c4a43f9f09e9c3877dbb502/plone.behavior-2.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8c126405b8e23561a23eaec78a62fedc13ae276b3eae90fe1ca1bd62f9615230",
"md5": "ad1f45b1e7664fff54368fca47fed880",
"sha256": "abad04798d1f6f1a5e67e5b51f4169640db50210fa81223e87a45c7d47544aba"
},
"downloads": -1,
"filename": "plone.behavior-2.0.1.tar.gz",
"has_sig": false,
"md5_digest": "ad1f45b1e7664fff54368fca47fed880",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 27814,
"upload_time": "2024-01-19T09:43:35",
"upload_time_iso_8601": "2024-01-19T09:43:35.208831Z",
"url": "https://files.pythonhosted.org/packages/8c/12/6405b8e23561a23eaec78a62fedc13ae276b3eae90fe1ca1bd62f9615230/plone.behavior-2.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-19 09:43:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "plone",
"github_project": "plone.behavior",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "plone.behavior"
}