Class
zope.app.component.vocabulary.UtilityNames

Vocabulary with utility names for a single interface as values.

>>> class IMyUtility(Interface):
...     pass
>>> class MyUtility(object):
...     implements(IMyUtility)
>>> vocab = UtilityNames(IMyUtility)
>>> from zope.schema.interfaces import IVocabulary
>>> IVocabulary.providedBy(vocab)
True
>>> IVocabularyTokenized.providedBy(vocab)
True
>>> from zope.app.testing import placelesssetup
>>> from zope.app.testing import ztapi
>>> placelesssetup.setUp()
>>> ztapi.provideUtility(IMyUtility, MyUtility(), 'one')
>>> ztapi.provideUtility(IMyUtility, MyUtility(), 'two')
>>> unames = UtilityNames(IMyUtility)
>>> len(list(unames))
2
>>> L = [t.value for t in unames]
>>> L.sort()
>>> L
[u'one', u'two']
>>> u'one' in vocab
True
>>> u'three' in vocab
False
>>> ztapi.provideUtility(IMyUtility, MyUtility(), 'three')
>>> u'three' in vocab
True
>>> ztapi.provideUtility(IMyUtility, MyUtility())
>>> u'' in vocab
True
>>> term1 = vocab.getTerm(u'')
>>> term2 = vocab.getTermByToken(term1.token)
>>> term2.value
u''
>>> term3 = vocab.getTerm(u'one')
>>> term3.token
'tb25l'
>>> term3a = vocab.getTermByToken('tb25l')
>>> term3.value
u'one'
>>> placelesssetup.tearDown()

Base classes

There are no base classes.

Implemented Interfaces

Attributes/Properties

There are no attributes in this class.

Methods

Known Subclasses

There are no known subclasses.