plone.uuid
==========
This is a minimal package that can be used to obtain a universally unique
identifier (UUID) for an object.
The default implementation uses the Python standard library ``uuid`` module
to generate an RFC 4122-compliant UUID, using the ``uuid4()`` function. It
will assign a UUID upon object creation (by subscribing to
``IObjectCreatedEvent`` from ``zope.lifecycleevent``) and store it in an
attribute on the object.
Why use an attribute and not annotations? The most common form of annotation
is the one provided by ``IAttributeAnnotations``. This stores annotations in
a BTree in an attribute called ``__annotations__``, which means that
annotation values do not end up in the same ZODB persistent object as the
parent. This is good for "large" values, but not very good for small ones
that are frequently required, as it requires a separate ZODB object load.
Simple usage
============
To automatically assign a UUID to your objects using the default
implementation outlined above, you should:
* Make sure they implement ``plone.uuid.interfaces.IAttributeUUID``. You
can do this in code, via the ``implements()`` directive, or in ZCML, with
a statement like::
<class class="my.package.MyClass">
<implements interface="plone.uuid.interfaces.IAttributeUUID" />
</class>
* Make sure that an ``IObjectCreatedEvent`` is fired for this object when it
is first created.
Once the event handler has triggered, you can obtain a UUID by adapting the
object to the ``IUUID`` interface::
from plone.uuid.interfaces import IUUID
uuid = IUUID(context)
The ``uuid`` variable will now be a (byte) string containing a UUID. If the
UUID has not yet been assigned, adaptation will fail with a ``TypeError``.
If you would rather get ``None`` instead of a ``TypeError``, you can do::
uuid = IUUID(context, None)
UUID view
=========
If you require a UUID in a page template or remotely, you can use the
``@@uuid`` view, which is registered for all objects that provide the
``IUUIDAware`` marker interface (which is a super-interface of the
``IAttributeUUID`` marker seen above).
For example::
<div tal:attributes="id string:uuid-${context/@@uuid}">
...
</div>
The view simply returns the UUID string as looked up by the ``IUUID`` adapter.
Customising behaviour
=====================
There are two primary customisation points for this package:
* You can change the default UUID generating algorithm by overriding the
unnamed utility providing the ``IUUIDGenerator`` interface. The default
implementation simply calls ``uuid.uuid4()`` and casts the result to a
``str``.
* You can change the UUID storage by providing a custom ``IUUID`` adapter
implementation. If you do this, you must also provide a mechanism for
assigning UUIDs upon object creation, usually via an event handler. To
obtain a UUID, use the ``IUUIDGenerator`` interface::
from zope.component import getUtility
from plone.uuid.interfaces import IUUIDGenerator
generator = getUtility(IUUIDGenerator)
uuid = generator()
You should also make sure that instances with a UUID provide a sub-interface
of ``plone.uuid.interfaces.IUUIDAware``.
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.0 (2023-04-26)
------------------
Breaking changes:
- Drop python 2.7 support.
[gforcada] (#1)
Internal:
- Update configuration files.
[plone devs] (2ed8f544)
1.0.6 (2020-04-22)
------------------
Bug fixes:
- Minor packaging updates. (#1)
1.0.5 (2018-01-18)
------------------
Bug fixes:
- Fix package dependencies.
[gforcada]
- Fix documentation and uuid generator class name to reflect the fact that we use the ``uuid4`` implementation instead of ``uuid1``.
[thet]
1.0.4 (2016-06-02)
------------------
Bug fixes:
- Update setup.py url to point to github.
[esteele]
- Fixed issues preventing tests passing on Python 3
[datakurre]
1.0.3 (2012-05-31)
------------------
- Use zope.browserpage.
[hannosch]
- Defensive UUID assignment in addAttributeUUID() handler: keep existing
UUID value if handler called more than once, except in case of object
copy event, where original and destination should have distinct UUID.
[seanupton]
1.0.2 - 2011-10-18
------------------
- Generate UUID without dashes.
[elro]
1.0.1 - 2011-05-20
------------------
- Relicense under modified BSD license.
See http://plone.org/foundation/materials/foundation-resolutions/plone-framework-components-relicensing-policy
[davisagli]
1.0 - 2011-05-13
----------------
- Release 1.0 Final
[esteele]
- Add MANIFEST.in.
[WouterVH]
1.0b2 - 2011-01-03
------------------
- Add MutableUUID component
[toutpt]
1.0b1 - 2010-11-27
------------------
- Initial release
Raw data
{
"_id": null,
"home_page": "https://github.com/plone/plone.uuid",
"name": "plone.uuid",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "plone uuid",
"author": "Martin Aspeli",
"author_email": "optilude@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/aa/79/c18d6c417d283dc9e1e47ff72b9635175d4745f32f546fcce13af5156f4f/plone.uuid-2.0.0.tar.gz",
"platform": null,
"description": "plone.uuid\n==========\n\nThis is a minimal package that can be used to obtain a universally unique\nidentifier (UUID) for an object.\n\nThe default implementation uses the Python standard library ``uuid`` module\nto generate an RFC 4122-compliant UUID, using the ``uuid4()`` function. It\nwill assign a UUID upon object creation (by subscribing to\n``IObjectCreatedEvent`` from ``zope.lifecycleevent``) and store it in an\nattribute on the object.\n\n Why use an attribute and not annotations? The most common form of annotation\n is the one provided by ``IAttributeAnnotations``. This stores annotations in\n a BTree in an attribute called ``__annotations__``, which means that\n annotation values do not end up in the same ZODB persistent object as the\n parent. This is good for \"large\" values, but not very good for small ones\n that are frequently required, as it requires a separate ZODB object load.\n\nSimple usage\n============\n\nTo automatically assign a UUID to your objects using the default\nimplementation outlined above, you should:\n\n* Make sure they implement ``plone.uuid.interfaces.IAttributeUUID``. You\n can do this in code, via the ``implements()`` directive, or in ZCML, with\n a statement like::\n\n <class class=\"my.package.MyClass\">\n <implements interface=\"plone.uuid.interfaces.IAttributeUUID\" />\n </class>\n\n* Make sure that an ``IObjectCreatedEvent`` is fired for this object when it\n is first created.\n\nOnce the event handler has triggered, you can obtain a UUID by adapting the\nobject to the ``IUUID`` interface::\n\n from plone.uuid.interfaces import IUUID\n uuid = IUUID(context)\n\nThe ``uuid`` variable will now be a (byte) string containing a UUID. If the\nUUID has not yet been assigned, adaptation will fail with a ``TypeError``.\n\nIf you would rather get ``None`` instead of a ``TypeError``, you can do::\n\n uuid = IUUID(context, None)\n\nUUID view\n=========\n\nIf you require a UUID in a page template or remotely, you can use the\n``@@uuid`` view, which is registered for all objects that provide the\n``IUUIDAware`` marker interface (which is a super-interface of the\n``IAttributeUUID`` marker seen above).\n\nFor example::\n\n <div tal:attributes=\"id string:uuid-${context/@@uuid}\">\n ...\n </div>\n\nThe view simply returns the UUID string as looked up by the ``IUUID`` adapter.\n\nCustomising behaviour\n=====================\n\nThere are two primary customisation points for this package:\n\n* You can change the default UUID generating algorithm by overriding the\n unnamed utility providing the ``IUUIDGenerator`` interface. The default\n implementation simply calls ``uuid.uuid4()`` and casts the result to a\n ``str``.\n\n* You can change the UUID storage by providing a custom ``IUUID`` adapter\n implementation. If you do this, you must also provide a mechanism for\n assigning UUIDs upon object creation, usually via an event handler. To\n obtain a UUID, use the ``IUUIDGenerator`` interface::\n\n from zope.component import getUtility\n from plone.uuid.interfaces import IUUIDGenerator\n\n generator = getUtility(IUUIDGenerator)\n uuid = generator()\n\n You should also make sure that instances with a UUID provide a sub-interface\n of ``plone.uuid.interfaces.IUUIDAware``.\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.0 (2023-04-26)\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] (2ed8f544)\n\n\n1.0.6 (2020-04-22)\n------------------\n\nBug fixes:\n\n\n- Minor packaging updates. (#1)\n\n\n1.0.5 (2018-01-18)\n------------------\n\nBug fixes:\n\n- Fix package dependencies.\n [gforcada]\n\n- Fix documentation and uuid generator class name to reflect the fact that we use the ``uuid4`` implementation instead of ``uuid1``.\n [thet]\n\n\n1.0.4 (2016-06-02)\n------------------\n\nBug fixes:\n\n- Update setup.py url to point to github.\n [esteele]\n\n- Fixed issues preventing tests passing on Python 3\n [datakurre]\n\n\n1.0.3 (2012-05-31)\n------------------\n\n- Use zope.browserpage.\n [hannosch]\n\n- Defensive UUID assignment in addAttributeUUID() handler: keep existing\n UUID value if handler called more than once, except in case of object\n copy event, where original and destination should have distinct UUID.\n [seanupton]\n\n\n1.0.2 - 2011-10-18\n------------------\n\n- Generate UUID without dashes.\n [elro]\n\n\n1.0.1 - 2011-05-20\n------------------\n\n- Relicense under modified BSD license.\n See http://plone.org/foundation/materials/foundation-resolutions/plone-framework-components-relicensing-policy\n [davisagli]\n\n\n1.0 - 2011-05-13\n----------------\n\n- Release 1.0 Final\n [esteele]\n\n- Add MANIFEST.in.\n [WouterVH]\n\n\n1.0b2 - 2011-01-03\n------------------\n\n- Add MutableUUID component\n [toutpt]\n\n\n1.0b1 - 2010-11-27\n------------------\n\n- Initial release\n\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "UUIDs for content items",
"version": "2.0.0",
"split_keywords": [
"plone",
"uuid"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee5ee0c21b37b17d85c579b8a47a1dab5a0e8dce70cb9322d43e3d9fd40994c9",
"md5": "e3ec8617cb4517a08552337cc6e8d198",
"sha256": "da9b4d8eb7ad3b53e3e17151173ada885d1cdc9418f6ae7c447c1823be39956b"
},
"downloads": -1,
"filename": "plone.uuid-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e3ec8617cb4517a08552337cc6e8d198",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8147,
"upload_time": "2023-04-26T21:48:58",
"upload_time_iso_8601": "2023-04-26T21:48:58.236680Z",
"url": "https://files.pythonhosted.org/packages/ee/5e/e0c21b37b17d85c579b8a47a1dab5a0e8dce70cb9322d43e3d9fd40994c9/plone.uuid-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "aa79c18d6c417d283dc9e1e47ff72b9635175d4745f32f546fcce13af5156f4f",
"md5": "feeefd68d8d1502379aaf93793931e57",
"sha256": "03391c1aca3256fce701dca9853a812c6271c41d5e3cc512ec410e6076a22208"
},
"downloads": -1,
"filename": "plone.uuid-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "feeefd68d8d1502379aaf93793931e57",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11290,
"upload_time": "2023-04-26T21:49:00",
"upload_time_iso_8601": "2023-04-26T21:49:00.513584Z",
"url": "https://files.pythonhosted.org/packages/aa/79/c18d6c417d283dc9e1e47ff72b9635175d4745f32f546fcce13af5156f4f/plone.uuid-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-26 21:49:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "plone",
"github_project": "plone.uuid",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "plone.uuid"
}