Class
zope.copypastemove.ContainerItemRenamer

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 zope.app.container.interfaces 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 zope.app.container.contained import Contained
>>> foo = Contained()
>>> container['foo'] = foo
>>> container['foo'] is foo
True

to 'bar':

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

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

Attributes/Properties

There are no attributes in this class.

Methods

Known Subclasses