An IContainerItemRenamer adapter for containers.

This adapter uses IObjectMover to move an item within the same container to a different name. We need to first setup an adapter for IObjectMover:

>>> from import IContained
>>> gsm = zope.component.getGlobalSiteManager()
>>> gsm.registerAdapter(ObjectMover, (IContained, ), IObjectMover)

To rename an item in a container, instantiate a ContainerItemRenamer with the container:

>>> container = SampleContainer()
>>> renamer = ContainerItemRenamer(container)

For this example, we'll rename an item 'foo':

>>> from import Contained
>>> foo = Contained()
>>> container['foo'] = foo
>>> container['foo'] is foo

to 'bar':

>>> renamer.renameItem('foo', 'bar')
>>> container['foo'] is foo
Traceback (most recent call last):
KeyError: 'foo'
>>> container['bar'] is foo

If the item being renamed isn't in the container, a NotFoundError is raised:

>>> renamer.renameItem('foo', 'bar') # doctest:+ELLIPSIS
Traceback (most recent call last):
ItemNotFoundError: (<...SampleContainer...>, 'foo')

If the new item name already exists, a DuplicationError is raised:

>>> renamer.renameItem('bar', 'bar')
Traceback (most recent call last):
DuplicationError: bar is already in use

Base classes

Implemented Interfaces


There are no attributes in this class.


Known Subclasses